Electroneum
lmdb::key_iterator< K, V > Class Template Reference

#include <key_stream.h>

Public Types

using value_type = std::pair< K, boost::iterator_range< value_iterator< V > >>
 
using reference = value_type
 
using pointer = void
 
using difference_type = std::size_t
 
using iterator_category = std::input_iterator_tag
 

Public Member Functions

 key_iterator () noexcept
 Construct an "end" iterator. More...
 
 key_iterator (MDB_cursor *cur)
 
bool is_end () const noexcept
 
bool equal (key_iterator const &rhs) const noexcept
 
key_iteratoroperator++ ()
 
key_iterator operator++ (int)
 
value_type operator* () const
 
get_key () const noexcept
 
template<typename T = V, typename F = T, std::size_t offset = 0>
value_iterator< T, F, offset > make_value_iterator () const
 
template<typename T = V, typename F = T, std::size_t offset = 0>
boost::iterator_range< value_iterator< T, F, offset > > make_value_range () const
 

Detailed Description

template<typename K, typename V>
class lmdb::key_iterator< K, V >

An InputIterator for a fixed-sized LMDB key and value. operator++ iterates over keys.

Template Parameters
KKey type in database records.
VValue type in database records.
Note
This meets requirements for an InputIterator only. The iterator can only be incremented and dereferenced. All copies of an iterator share the same LMDB cursor, and therefore incrementing any copy will change the cursor state for all (incrementing an iterator will invalidate all prior copies of the iterator). Usage is identical to std::istream_iterator.

Definition at line 57 of file key_stream.h.

Member Typedef Documentation

◆ difference_type

template<typename K, typename V>
using lmdb::key_iterator< K, V >::difference_type = std::size_t

Definition at line 73 of file key_stream.h.

◆ iterator_category

template<typename K, typename V>
using lmdb::key_iterator< K, V >::iterator_category = std::input_iterator_tag

Definition at line 74 of file key_stream.h.

◆ pointer

template<typename K, typename V>
using lmdb::key_iterator< K, V >::pointer = void

Definition at line 72 of file key_stream.h.

◆ reference

template<typename K, typename V>
using lmdb::key_iterator< K, V >::reference = value_type

Definition at line 71 of file key_stream.h.

◆ value_type

template<typename K, typename V>
using lmdb::key_iterator< K, V >::value_type = std::pair<K, boost::iterator_range<value_iterator<V> >>

Definition at line 70 of file key_stream.h.

Constructor & Destructor Documentation

◆ key_iterator() [1/2]

template<typename K, typename V>
lmdb::key_iterator< K, V >::key_iterator ( )
inlinenoexcept

Construct an "end" iterator.

Definition at line 77 of file key_stream.h.

78  : cur(nullptr), key()
79  {}

◆ key_iterator() [2/2]

template<typename K, typename V>
lmdb::key_iterator< K, V >::key_iterator ( MDB_cursor cur)
inline
Parameters
curIterate over keys starting at this cursor position.
Exceptions
std::system_errorif unexpected LMDB error. This can happen if cur is invalid.

Definition at line 86 of file key_stream.h.

87  : cur(cur), key()
88  {
89  if (cur)
90  key = lmdb::stream::get(*cur, MDB_GET_CURRENT, sizeof(K), sizeof(V)).first;
91  }
std::pair< epee::span< const std::uint8_t >, epee::span< const std::uint8_t > > get(MDB_cursor &cur, MDB_cursor_op op, std::size_t key, std::size_t value)
Here is the call graph for this function:

Member Function Documentation

◆ equal()

template<typename K, typename V>
bool lmdb::key_iterator< K, V >::equal ( key_iterator< K, V > const &  rhs) const
inlinenoexcept
Returns
True iff rhs is referencing this key.

Definition at line 97 of file key_stream.h.

98  {
99  return
100  (key.empty() && rhs.key.empty()) ||
101  key.data() == rhs.key.data();
102  }
constexpr bool empty() const noexcept
Definition: span.h:109
constexpr pointer data() const noexcept
Definition: span.h:110

◆ get_key()

template<typename K, typename V>
K lmdb::key_iterator< K, V >::get_key ( ) const
inlinenoexcept
Precondition
!is_end()
Returns
Current key

Definition at line 133 of file key_stream.h.

134  {
135  assert(!is_end());
136  K out;
137  std::memcpy(std::addressof(out), key.data(), sizeof(out));
138  return out;
139  }
bool is_end() const noexcept
Definition: key_stream.h:94
void * memcpy(void *a, const void *b, size_t c)
constexpr pointer data() const noexcept
Definition: span.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_end()

template<typename K, typename V>
bool lmdb::key_iterator< K, V >::is_end ( ) const
inlinenoexcept
Returns
True if this is one-past the last key.

Definition at line 94 of file key_stream.h.

94 { return key.empty(); }
constexpr bool empty() const noexcept
Definition: span.h:109
Here is the caller graph for this function:

◆ make_value_iterator()

template<typename K, typename V>
template<typename T = V, typename F = T, std::size_t offset = 0>
value_iterator<T, F, offset> lmdb::key_iterator< K, V >::make_value_iterator ( ) const
inline

Return a C++ iterator over database values from current cursor position that will reach .is_end() after the last duplicate key record. Calling make_iterator() will return an iterator whose operator* will return an entire value (V). make_iterator<ELECTRONEUM_FIELD(account, id)>() will return an iterator whose operator* will return a decltype(account.id) object - the other fields in the struct account are never copied from the database.

Exceptions
std::system_errorif LMDB has unexpected errors.
Returns
C++ iterator starting at current cursor position.

Definition at line 155 of file key_stream.h.

156  {
157  static_assert(std::is_same<T, V>(), "bad ELECTRONEUM_FIELD usage?");
158  return {cur};
159  }

◆ make_value_range()

template<typename K, typename V>
template<typename T = V, typename F = T, std::size_t offset = 0>
boost::iterator_range<value_iterator<T, F, offset> > lmdb::key_iterator< K, V >::make_value_range ( ) const
inline

Return a range from current cursor position until last duplicate key record. Useful in for-each range loops or in templated code expecting a range of elements. Calling make_range() will return a range of T objects. make_range<ELECTRONEUM_FIELD(account, id)>() will return a range of decltype(account.id) objects - the other fields in the struct account are never copied from the database.

Exceptions
std::system_errorif LMDB has unexpected errors.
Returns
An InputIterator range over values at cursor position.

Definition at line 173 of file key_stream.h.

174  {
175  return {make_value_iterator<T, F, offset>(), value_iterator<T, F, offset>{}};
176  }
Here is the caller graph for this function:

◆ operator*()

template<typename K, typename V>
value_type lmdb::key_iterator< K, V >::operator* ( ) const
inline
Precondition
!is_end()
Returns
{current key, current value range}

Definition at line 127 of file key_stream.h.

128  {
129  return {get_key(), make_value_range()};
130  }
K get_key() const noexcept
Definition: key_stream.h:133
boost::iterator_range< value_iterator< T, F, offset > > make_value_range() const
Definition: key_stream.h:173
Here is the call graph for this function:

◆ operator++() [1/2]

template<typename K, typename V>
key_iterator& lmdb::key_iterator< K, V >::operator++ ( )
inline

Moves iterator to next key or end. Invalidates all prior copies of the iterator.

Definition at line 108 of file key_stream.h.

109  {
110  increment();
111  return *this;
112  }

◆ operator++() [2/2]

template<typename K, typename V>
key_iterator lmdb::key_iterator< K, V >::operator++ ( int  )
inline

Moves iterator to next key or end.

Returns
A copy that is already invalidated, ignore

Definition at line 119 of file key_stream.h.

120  {
121  key_iterator out{*this};
122  increment();
123  return out;
124  }
key_iterator() noexcept
Construct an "end" iterator.
Definition: key_stream.h:77

The documentation for this class was generated from the following file: