1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-17 11:45:50 +00:00

Rename RedisReplyType to just Reply.

This commit is contained in:
King_DuckZ 2016-06-13 17:00:12 +01:00
parent 533b571771
commit 316f8f585b
7 changed files with 47 additions and 47 deletions

View file

@ -28,9 +28,9 @@ namespace redis {
namespace { namespace {
using RedisReply = std::unique_ptr<redisReply, void(*)(void*)>; using RedisReply = std::unique_ptr<redisReply, void(*)(void*)>;
RedisReplyType make_redis_reply_type (redisReply* parReply) { Reply make_redis_reply_type (redisReply* parReply) {
using boost::transform_iterator; using boost::transform_iterator;
using PtrToReplyIterator = transform_iterator<RedisReplyType(*)(redisReply*), redisReply**>; using PtrToReplyIterator = transform_iterator<Reply(*)(redisReply*), redisReply**>;
switch (parReply->type) { switch (parReply->type) {
case REDIS_REPLY_INTEGER: case REDIS_REPLY_INTEGER:
@ -38,12 +38,12 @@ namespace redis {
case REDIS_REPLY_STRING: case REDIS_REPLY_STRING:
return std::string(parReply->str, parReply->len); return std::string(parReply->str, parReply->len);
case REDIS_REPLY_ARRAY: case REDIS_REPLY_ARRAY:
return std::vector<RedisReplyType>( return std::vector<Reply>(
PtrToReplyIterator(parReply->element, &make_redis_reply_type), PtrToReplyIterator(parReply->element, &make_redis_reply_type),
PtrToReplyIterator(parReply->element + parReply->elements, &make_redis_reply_type) PtrToReplyIterator(parReply->element + parReply->elements, &make_redis_reply_type)
); );
default: default:
return RedisReplyType(); return Reply();
}; };
} }
} //unnamed namespace } //unnamed namespace
@ -84,7 +84,7 @@ namespace redis {
m_conn.reset(); m_conn.reset();
} }
RedisReplyType Command::run_pvt (int parArgc, const char** parArgv, std::size_t* parLengths) { Reply Command::run_pvt (int parArgc, const char** parArgv, std::size_t* parLengths) {
assert(parArgc >= 1); assert(parArgc >= 1);
assert(parArgv); assert(parArgv);
assert(parLengths); //This /could/ be null, but I don't see why it should assert(parLengths); //This /could/ be null, but I don't see why it should

View file

@ -55,7 +55,7 @@ namespace redis {
bool is_connected ( void ) const; bool is_connected ( void ) const;
template <typename... Args> template <typename... Args>
RedisReplyType run ( const char* parCommand, Args&&... parArgs ); Reply run ( const char* parCommand, Args&&... parArgs );
//Single Redis command wrappers //Single Redis command wrappers
scan_range scan ( void ); scan_range scan ( void );
@ -66,7 +66,7 @@ namespace redis {
private: private:
using RedisConnection = std::unique_ptr<redisContext, void(*)(redisContext*)>; using RedisConnection = std::unique_ptr<redisContext, void(*)(redisContext*)>;
RedisReplyType run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths ); Reply run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
RedisConnection m_conn; RedisConnection m_conn;
std::string m_address; std::string m_address;
@ -74,7 +74,7 @@ namespace redis {
}; };
template <typename... Args> template <typename... Args>
RedisReplyType Command::run (const char* parCommand, Args&&... parArgs) { Reply Command::run (const char* parCommand, Args&&... parArgs) {
constexpr const std::size_t arg_count = sizeof...(Args) + 1; constexpr const std::size_t arg_count = sizeof...(Args) + 1;
using CharPointerArray = std::array<const char*, arg_count>; using CharPointerArray = std::array<const char*, arg_count>;
using LengthArray = std::array<std::size_t, arg_count>; using LengthArray = std::array<std::size_t, arg_count>;

View file

@ -20,15 +20,15 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
namespace redis { namespace redis {
const long long& get_integer (const RedisReplyType& parReply) { const long long& get_integer (const Reply& parReply) {
return boost::get<long long>(parReply); return boost::get<long long>(parReply);
} }
const std::string& get_string (const RedisReplyType& parReply) { const std::string& get_string (const Reply& parReply) {
return boost::get<std::string>(parReply); return boost::get<std::string>(parReply);
} }
long long get_integer_autoconv_if_str (const RedisReplyType &parReply) { long long get_integer_autoconv_if_str (const Reply &parReply) {
using boost::lexical_cast; using boost::lexical_cast;
const auto type = parReply.which(); const auto type = parReply.which();
@ -43,26 +43,26 @@ namespace redis {
} }
} }
const std::vector<RedisReplyType>& get_array (const RedisReplyType& parReply) { const std::vector<Reply>& get_array (const Reply& parReply) {
return boost::get<std::vector<RedisReplyType>>(parReply); return boost::get<std::vector<Reply>>(parReply);
} }
template <> template <>
const std::string& get<std::string> (const RedisReplyType& parReply) { const std::string& get<std::string> (const Reply& parReply) {
return get_string(parReply); return get_string(parReply);
} }
template <> template <>
const std::vector<RedisReplyType>& get<std::vector<RedisReplyType>> (const RedisReplyType& parReply) { const std::vector<Reply>& get<std::vector<Reply>> (const Reply& parReply) {
return get_array(parReply); return get_array(parReply);
} }
template <> template <>
const long long& get<long long> (const RedisReplyType& parReply) { const long long& get<long long> (const Reply& parReply) {
return get_integer(parReply); return get_integer(parReply);
} }
template const std::string& get<std::string> ( const RedisReplyType& parReply ); template const std::string& get<std::string> ( const Reply& parReply );
template const std::vector<RedisReplyType>& get<std::vector<RedisReplyType>> ( const RedisReplyType& parReply ); template const std::vector<Reply>& get<std::vector<Reply>> ( const Reply& parReply );
template const long long& get<long long> ( const RedisReplyType& parReply ); template const long long& get<long long> ( const Reply& parReply );
} //namespace redis } //namespace redis

View file

@ -23,13 +23,13 @@
#include <string> #include <string>
namespace redis { namespace redis {
class RedisReplyType; class Reply;
namespace implem { namespace implem {
using RedisVariantType = boost::variant< using RedisVariantType = boost::variant<
long long, long long,
std::string, std::string,
boost::recursive_wrapper<std::vector<RedisReplyType>> boost::recursive_wrapper<std::vector<Reply>>
>; >;
enum RedisVariantTypes { enum RedisVariantTypes {
RedisVariantType_Integer = 0, RedisVariantType_Integer = 0,
@ -39,23 +39,23 @@ namespace redis {
}; };
} //namespace implem } //namespace implem
struct RedisReplyType : implem::RedisVariantType { struct Reply : implem::RedisVariantType {
using base_class = implem::RedisVariantType; using base_class = implem::RedisVariantType;
RedisReplyType ( void ) = default; Reply ( void ) = default;
RedisReplyType ( long long parVal ) : base_class(parVal) {} Reply ( long long parVal ) : base_class(parVal) {}
RedisReplyType ( std::string&& parVal ) : base_class(std::move(parVal)) {} Reply ( std::string&& parVal ) : base_class(std::move(parVal)) {}
RedisReplyType ( std::vector<RedisReplyType>&& parVal ) : base_class(std::move(parVal)) {} Reply ( std::vector<Reply>&& parVal ) : base_class(std::move(parVal)) {}
~RedisReplyType ( void ) noexcept = default; ~Reply ( void ) noexcept = default;
}; };
const long long& get_integer ( const RedisReplyType& parReply ); const long long& get_integer ( const Reply& parReply );
long long get_integer_autoconv_if_str ( const RedisReplyType& parReply ); long long get_integer_autoconv_if_str ( const Reply& parReply );
const std::string& get_string ( const RedisReplyType& parReply ); const std::string& get_string ( const Reply& parReply );
const std::vector<RedisReplyType>& get_array ( const RedisReplyType& parReply ); const std::vector<Reply>& get_array ( const Reply& parReply );
template <typename T> template <typename T>
const T& get ( const RedisReplyType& parReply ); const T& get ( const Reply& parReply );
} //namespace redis } //namespace redis
#endif #endif

View file

@ -35,11 +35,11 @@ namespace redis {
return m_command and m_command->is_connected(); return m_command and m_command->is_connected();
} }
RedisReplyType ScanIteratorBaseClass::run (const char* parCommand, long long parScanContext) { Reply ScanIteratorBaseClass::run (const char* parCommand, long long parScanContext) {
return m_command->run(parCommand, boost::lexical_cast<std::string>(parScanContext)); return m_command->run(parCommand, boost::lexical_cast<std::string>(parScanContext));
} }
RedisReplyType ScanIteratorBaseClass::run (const char* parCommand, const boost::string_ref& parParameter, long long parScanContext) { Reply ScanIteratorBaseClass::run (const char* parCommand, const boost::string_ref& parParameter, long long parScanContext) {
return m_command->run(parCommand, parParameter, boost::lexical_cast<std::string>(parScanContext)); return m_command->run(parCommand, parParameter, boost::lexical_cast<std::string>(parScanContext));
} }
} //namespace implem } //namespace implem

View file

@ -43,8 +43,8 @@ namespace redis {
~ScanIteratorBaseClass ( void ) noexcept = default; ~ScanIteratorBaseClass ( void ) noexcept = default;
bool is_connected ( void ) const; bool is_connected ( void ) const;
RedisReplyType run ( const char* parCommand, long long parScanContext ); Reply run ( const char* parCommand, long long parScanContext );
RedisReplyType run ( const char* parCommand, const boost::string_ref& parParameter, long long parScanContext ); Reply run ( const char* parCommand, const boost::string_ref& parParameter, long long parScanContext );
bool is_equal ( const ScanIteratorBaseClass& parOther ) const { return m_command == parOther.m_command; } bool is_equal ( const ScanIteratorBaseClass& parOther ) const { return m_command == parOther.m_command; }
@ -76,9 +76,9 @@ namespace redis {
private: private:
template <typename T> template <typename T>
RedisReplyType forward_scan_command ( typename std::enable_if<HasScanTargetMethod<T>::value, int>::type parDummy ); Reply forward_scan_command ( typename std::enable_if<HasScanTargetMethod<T>::value, int>::type parDummy );
template <typename T> template <typename T>
RedisReplyType forward_scan_command ( typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type parDummy ); Reply forward_scan_command ( typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type parDummy );
bool is_end ( void ) const; bool is_end ( void ) const;
void increment ( void ); void increment ( void );
@ -97,7 +97,7 @@ namespace redis {
static constexpr const char* command ( void ) { return "SCAN"; } static constexpr const char* command ( void ) { return "SCAN"; }
static constexpr const std::size_t step = 1; static constexpr const std::size_t step = 1;
static const T& make_value ( const RedisReplyType* parItem ); static const T& make_value ( const Reply* parItem );
}; };
template <typename T> template <typename T>
@ -109,7 +109,7 @@ namespace redis {
static constexpr const char* command ( void ) { return "SSCAN"; } static constexpr const char* command ( void ) { return "SSCAN"; }
static constexpr const std::size_t step = 1; static constexpr const std::size_t step = 1;
static const T& make_value ( const RedisReplyType* parItem ); static const T& make_value ( const Reply* parItem );
boost::string_ref scan_target ( void ) const { return m_scan_target; } boost::string_ref scan_target ( void ) const { return m_scan_target; }
private: private:
@ -126,7 +126,7 @@ namespace redis {
static constexpr const char* command ( void ) { return ScanCommands::_from_integral(Command)._to_string(); } static constexpr const char* command ( void ) { return ScanCommands::_from_integral(Command)._to_string(); }
static constexpr const std::size_t step = 2; static constexpr const std::size_t step = 2;
static value_type make_value ( const RedisReplyType* parItem ); static value_type make_value ( const Reply* parItem );
boost::string_ref scan_target ( void ) const { return m_scan_target; } boost::string_ref scan_target ( void ) const { return m_scan_target; }
private: private:

View file

@ -81,7 +81,7 @@ namespace redis {
m_curr_index = 0; m_curr_index = 0;
} }
else { else {
std::vector<RedisReplyType> array_reply; std::vector<Reply> array_reply;
long long new_context; long long new_context;
do { do {
@ -131,30 +131,30 @@ namespace redis {
template <typename ValueFetch> template <typename ValueFetch>
template <typename T> template <typename T>
RedisReplyType ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<HasScanTargetMethod<T>::value, int>::type) { Reply ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<HasScanTargetMethod<T>::value, int>::type) {
return implem::ScanIteratorBaseClass::run(T::command(), T::scan_target(), m_scan_context); return implem::ScanIteratorBaseClass::run(T::command(), T::scan_target(), m_scan_context);
} }
template <typename ValueFetch> template <typename ValueFetch>
template <typename T> template <typename T>
RedisReplyType ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type) { Reply ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type) {
return implem::ScanIteratorBaseClass::run(T::command(), m_scan_context); return implem::ScanIteratorBaseClass::run(T::command(), m_scan_context);
} }
template <typename T> template <typename T>
auto ScanSingleValues<T>::make_value (const RedisReplyType* parItem) -> const value_type& { auto ScanSingleValues<T>::make_value (const Reply* parItem) -> const value_type& {
assert(parItem); assert(parItem);
return get<T>(*parItem); return get<T>(*parItem);
} }
template <typename T> template <typename T>
auto ScanSingleValuesInKey<T>::make_value (const RedisReplyType* parItem) -> const value_type& { auto ScanSingleValuesInKey<T>::make_value (const Reply* parItem) -> const value_type& {
assert(parItem); assert(parItem);
return get<T>(*parItem); return get<T>(*parItem);
} }
template <typename P, char Command, typename A, typename B> template <typename P, char Command, typename A, typename B>
auto ScanPairs<P, Command, A, B>::make_value (const RedisReplyType* parItem) -> value_type { auto ScanPairs<P, Command, A, B>::make_value (const Reply* parItem) -> value_type {
assert(parItem); assert(parItem);
return value_type(get<A>(parItem[0]), get<B>(parItem[1])); return value_type(get<A>(parItem[0]), get<B>(parItem[1]));
} }