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

Make the scan command in ScanPairs a template parameter.

This commit is contained in:
King_DuckZ 2016-06-13 16:20:31 +01:00
parent 9949c273a1
commit 78eee0e16f
4 changed files with 12 additions and 5 deletions

View file

@ -12,6 +12,7 @@ add_library(${PROJECT_NAME} SHARED
target_include_directories(${PROJECT_NAME} SYSTEM
PUBLIC ${Boost_INCLUDE_DIRS}
PRIVATE ${HIREDIS_INCLUDE_DIRS}
PRIVATE ${CMAKE_SOURCE_DIR}/lib/better-enums
)
target_link_libraries(${PROJECT_NAME}

View file

@ -39,7 +39,7 @@ namespace redis {
public:
typedef ScanIterator<ScanSingleValues<std::string>> scan_iterator;
typedef boost::iterator_range<scan_iterator> scan_range;
typedef ScanIterator<ScanPairs<std::pair<std::string, std::string>>> hscan_iterator;
typedef ScanIterator<ScanPairs<std::pair<std::string, std::string>, ScanCommands::HSCAN>> hscan_iterator;
typedef boost::iterator_range<hscan_iterator> hscan_range;
typedef ScanIterator<ScanSingleValuesInKey<std::string>> sscan_iterator;
typedef boost::iterator_range<sscan_iterator> sscan_range;

View file

@ -20,6 +20,7 @@
#include "reply.hpp"
#include "helpers/has_method.hpp"
#include "enum.h"
#include <boost/iterator/iterator_facade.hpp>
#include <type_traits>
#include <vector>
@ -52,6 +53,10 @@ namespace redis {
};
} //namespace implem
BETTER_ENUM(ScanCommands, char,
SCAN, SSCAN, ZSCAN, HSCAN
);
template <typename ValueFetch>
class ScanIterator : private implem::ScanIteratorBaseClass, public implem::ScanIteratorBaseIterator<ValueFetch>, private ValueFetch {
friend class boost::iterator_core_access;
@ -111,13 +116,14 @@ namespace redis {
boost::string_ref m_scan_target;
};
template <typename P, typename A=decltype(P().first), typename B=decltype(P().second)>
template <typename P, char Command, typename A=decltype(P().first), typename B=decltype(P().second)>
struct ScanPairs {
static_assert(Command == ScanCommands::HSCAN or Command == ScanCommands::ZSCAN, "Invalid scan command chosen");
typedef P value_type;
explicit ScanPairs ( boost::string_ref parScanTarget ) : m_scan_target(parScanTarget) {}
static constexpr const char* command ( void ) { return "HSCAN"; }
static constexpr const char* command ( void ) { return ScanCommands::_from_integral(Command)._to_string(); }
static constexpr const std::size_t step = 2;
static value_type make_value ( const RedisReplyType* parItem );

View file

@ -153,8 +153,8 @@ namespace redis {
return get<T>(*parItem);
}
template <typename P, typename A, typename B>
auto ScanPairs<P, A, B>::make_value (const RedisReplyType* parItem) -> value_type {
template <typename P, char Command, typename A, typename B>
auto ScanPairs<P, Command, A, B>::make_value (const RedisReplyType* parItem) -> value_type {
assert(parItem);
return value_type(get<A>(parItem[0]), get<B>(parItem[1]));
}