/* Copyright 2015, 2016, Michele Santullo * This file is part of "dindexer". * * "dindexer" is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * "dindexer" is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with "dindexer". If not, see . */ #ifndef id93FA96E3071745D9A1E45D4D29B9F7D0 #define id93FA96E3071745D9A1E45D4D29B9F7D0 #include #include #include namespace redis { struct Reply; class ErrorString { public: ErrorString ( const char* parCStr, std::size_t parLen ) : m_msg(parCStr, parLen) { } const std::string& message ( void ) const noexcept { return m_msg; } private: std::string m_msg; }; class StatusString { public: StatusString ( const char* parCStr, std::size_t parLen ) : m_msg(parCStr, parLen) { } const std::string& message ( void ) const noexcept { return m_msg; } bool is_ok ( void ) const { return "OK" == m_msg; } private: std::string m_msg; }; namespace implem { using RedisVariantType = boost::variant< long long, std::string, std::vector, ErrorString, StatusString >; } //namespace implem enum RedisVariantTypes { RedisVariantType_Integer = 0, RedisVariantType_String, RedisVariantType_Array, RedisVariantType_Error, RedisVariantType_Status }; struct Reply : implem::RedisVariantType { using base_class = implem::RedisVariantType; Reply ( void ) = default; Reply ( long long parVal ) : base_class(parVal) {} Reply ( std::string&& parVal ) : base_class(std::move(parVal)) {} Reply ( std::vector&& parVal ) : base_class(std::move(parVal)) {} Reply ( ErrorString&& parVal ) : base_class(std::move(parVal)) {} Reply ( StatusString&& parVal ) : base_class(std::move(parVal)) {} ~Reply ( void ) noexcept = default; }; const long long& get_integer ( const Reply& parReply ); long long get_integer_autoconv_if_str ( const Reply& parReply ); const std::string& get_string ( const Reply& parReply ); const std::vector& get_array ( const Reply& parReply ); const ErrorString& get_error_string ( const Reply& parReply ); template const T& get ( const Reply& parReply ); } //namespace redis #endif