mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Move V into ValueFetch.
No need to explicitly specify the dereferenced type directly to the scan iterator anymore.
This commit is contained in:
parent
c7eeddabf1
commit
731582d8fe
3 changed files with 34 additions and 32 deletions
|
@ -37,9 +37,9 @@ struct redisContext;
|
|||
namespace redis {
|
||||
class Command {
|
||||
public:
|
||||
typedef ScanIterator<std::string, ScanSingleValues<std::string>> scan_iterator;
|
||||
typedef ScanIterator<ScanSingleValues<std::string>> scan_iterator;
|
||||
typedef boost::iterator_range<scan_iterator> scan_range;
|
||||
typedef ScanIterator<std::pair<std::string, std::string>, ScanPairs<std::pair<std::string, std::string>>> hscan_iterator;
|
||||
typedef ScanIterator<ScanPairs<std::pair<std::string, std::string>>> hscan_iterator;
|
||||
typedef boost::iterator_range<hscan_iterator> hscan_range;
|
||||
|
||||
Command ( std::string&& parAddress, uint16_t parPort );
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace redis {
|
||||
template <typename V, typename ValueFetch>
|
||||
template <typename ValueFetch>
|
||||
class ScanIterator;
|
||||
|
||||
class Command;
|
||||
|
||||
namespace implem {
|
||||
template <typename V, typename ValueFetch>
|
||||
using ScanIteratorBaseIterator = boost::iterator_facade<ScanIterator<V, ValueFetch>, const V, boost::forward_traversal_tag>;
|
||||
template <typename ValueFetch>
|
||||
using ScanIteratorBaseIterator = boost::iterator_facade<ScanIterator<ValueFetch>, const typename ValueFetch::value_type, boost::forward_traversal_tag>;
|
||||
|
||||
class ScanIteratorBaseClass {
|
||||
protected:
|
||||
|
@ -52,10 +52,10 @@ namespace redis {
|
|||
};
|
||||
} //namespace implem
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
class ScanIterator : private implem::ScanIteratorBaseClass, public implem::ScanIteratorBaseIterator<V, ValueFetch>, private ValueFetch {
|
||||
template <typename ValueFetch>
|
||||
class ScanIterator : private implem::ScanIteratorBaseClass, public implem::ScanIteratorBaseIterator<ValueFetch>, private ValueFetch {
|
||||
friend class boost::iterator_core_access;
|
||||
typedef implem::ScanIteratorBaseIterator<V, ValueFetch> base_iterator;
|
||||
typedef implem::ScanIteratorBaseIterator<ValueFetch> base_iterator;
|
||||
define_has_method(scan_target, ScanTarget);
|
||||
public:
|
||||
typedef typename base_iterator::difference_type difference_type;
|
||||
|
@ -78,7 +78,7 @@ namespace redis {
|
|||
|
||||
void increment ( void );
|
||||
bool equal ( const ScanIterator& parOther ) const;
|
||||
const V& dereference ( void ) const;
|
||||
const value_type& dereference ( void ) const;
|
||||
|
||||
std::vector<value_type> m_reply;
|
||||
long long m_scan_context;
|
||||
|
@ -87,6 +87,8 @@ namespace redis {
|
|||
|
||||
template <typename T>
|
||||
struct ScanSingleValues {
|
||||
typedef T value_type;
|
||||
|
||||
static constexpr const char* command ( void ) { return "SCAN"; }
|
||||
static constexpr const std::size_t step = 1;
|
||||
|
||||
|
@ -95,14 +97,14 @@ namespace redis {
|
|||
|
||||
template <typename P, typename A=decltype(P().first), typename B=decltype(P().second)>
|
||||
struct ScanPairs {
|
||||
typedef P PairType;
|
||||
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 std::size_t step = 2;
|
||||
|
||||
static PairType make_value ( const RedisReplyType* parItem );
|
||||
static value_type make_value ( const RedisReplyType* parItem );
|
||||
boost::string_ref scan_target ( void );
|
||||
|
||||
private:
|
||||
|
|
|
@ -23,11 +23,11 @@ namespace redis {
|
|||
namespace implem {
|
||||
} //namespace implem
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
template <typename ValueFetch>
|
||||
template <typename Dummy, typename>
|
||||
ScanIterator<V, ValueFetch>::ScanIterator (Command* parCommand, bool parEnd) :
|
||||
ScanIterator<ValueFetch>::ScanIterator (Command* parCommand, bool parEnd) :
|
||||
implem::ScanIteratorBaseClass(parCommand),
|
||||
implem::ScanIteratorBaseIterator<V, ValueFetch>(),
|
||||
implem::ScanIteratorBaseIterator<ValueFetch>(),
|
||||
ValueFetch(),
|
||||
m_reply(),
|
||||
m_scan_context(0),
|
||||
|
@ -43,11 +43,11 @@ namespace redis {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
template <typename ValueFetch>
|
||||
template <typename Dummy, typename>
|
||||
ScanIterator<V, ValueFetch>::ScanIterator (Command* parCommand, boost::string_ref parKey, bool parEnd) :
|
||||
ScanIterator<ValueFetch>::ScanIterator (Command* parCommand, boost::string_ref parKey, bool parEnd) :
|
||||
implem::ScanIteratorBaseClass(parCommand),
|
||||
implem::ScanIteratorBaseIterator<V, ValueFetch>(),
|
||||
implem::ScanIteratorBaseIterator<ValueFetch>(),
|
||||
ValueFetch(parKey),
|
||||
m_reply(),
|
||||
m_scan_context(0),
|
||||
|
@ -63,13 +63,13 @@ namespace redis {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
bool ScanIterator<V, ValueFetch>::is_end() const {
|
||||
template <typename ValueFetch>
|
||||
bool ScanIterator<ValueFetch>::is_end() const {
|
||||
return not m_curr_index and m_reply.empty() and not m_scan_context;
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
void ScanIterator<V, ValueFetch>::increment() {
|
||||
template <typename ValueFetch>
|
||||
void ScanIterator<ValueFetch>::increment() {
|
||||
assert(not is_end());
|
||||
static_assert(ValueFetch::step > 0, "Can't have an increase step of 0");
|
||||
|
||||
|
@ -107,8 +107,8 @@ namespace redis {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
bool ScanIterator<V, ValueFetch>::equal (const ScanIterator& parOther) const {
|
||||
template <typename ValueFetch>
|
||||
bool ScanIterator<ValueFetch>::equal (const ScanIterator& parOther) const {
|
||||
return
|
||||
(&parOther == this) or
|
||||
(is_end() and parOther.is_end()) or
|
||||
|
@ -121,36 +121,36 @@ namespace redis {
|
|||
);
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
const V& ScanIterator<V, ValueFetch>::dereference() const {
|
||||
template <typename ValueFetch>
|
||||
auto ScanIterator<ValueFetch>::dereference() const -> const value_type& {
|
||||
assert(not m_reply.empty());
|
||||
assert(m_curr_index < m_reply.size());
|
||||
|
||||
return m_reply[m_curr_index];
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
template <typename ValueFetch>
|
||||
template <typename T>
|
||||
RedisReplyType ScanIterator<V, ValueFetch>::forward_scan_command (typename std::enable_if<HasScanTargetMethod<T>::value, int>::type) {
|
||||
RedisReplyType 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);
|
||||
}
|
||||
|
||||
template <typename V, typename ValueFetch>
|
||||
template <typename ValueFetch>
|
||||
template <typename T>
|
||||
RedisReplyType ScanIterator<V, ValueFetch>::forward_scan_command (typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type) {
|
||||
RedisReplyType ScanIterator<ValueFetch>::forward_scan_command (typename std::enable_if<not HasScanTargetMethod<T>::value, int>::type) {
|
||||
return implem::ScanIteratorBaseClass::run(T::command(), m_scan_context);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& ScanSingleValues<T>::make_value (const RedisReplyType* parItem) {
|
||||
auto ScanSingleValues<T>::make_value (const RedisReplyType* parItem) -> const value_type& {
|
||||
assert(parItem);
|
||||
return get<T>(*parItem);
|
||||
}
|
||||
|
||||
template <typename P, typename A, typename B>
|
||||
P ScanPairs<P, A, B>::make_value (const RedisReplyType* parItem) {
|
||||
auto ScanPairs<P, A, B>::make_value (const RedisReplyType* parItem) -> value_type {
|
||||
assert(parItem);
|
||||
return PairType(get<A>(parItem[0]), get<B>(parItem[1]));
|
||||
return value_type(get<A>(parItem[0]), get<B>(parItem[1]));
|
||||
}
|
||||
|
||||
template <typename P, typename A, typename B>
|
||||
|
|
Loading…
Reference in a new issue