Electroneum
Loading...
Searching...
No Matches
lmdb::value_iterator< T, F, offset > Class Template Reference

#include <value_stream.h>

Public Types

using value_type = F
using reference = value_type
using pointer = void
using difference_type = std::size_t
using iterator_category = std::input_iterator_tag

Public Member Functions

 value_iterator () noexcept
 Construct an "end" iterator.
 value_iterator (MDB_cursor *cur)
 value_iterator (value_iterator const &)=default
 ~value_iterator ()=default
value_iteratoroperator= (value_iterator const &)=default
bool is_end () const noexcept
bool equal (value_iterator const &rhs) const noexcept
value_iteratoroperator++ ()
 Invalidates all prior copies of the iterator.
value_iterator operator++ (int)
template<typename U, typename G = U, std::size_t uoffset = 0>
get_value () const noexcept
value_type operator* () const noexcept

Detailed Description

template<typename T, typename F = T, std::size_t offset = 0>
class lmdb::value_iterator< T, F, offset >

An InputIterator for a fixed-sized LMDB value at a specific key.

Template Parameters
TThe value type at the specific key.
FThe value type being returned when dereferenced.
offsetto F within T.
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 82 of file value_stream.h.

Member Typedef Documentation

◆ difference_type

template<typename T, typename F = T, std::size_t offset = 0>
using lmdb::value_iterator< T, F, offset >::difference_type = std::size_t

Definition at line 98 of file value_stream.h.

◆ iterator_category

template<typename T, typename F = T, std::size_t offset = 0>
using lmdb::value_iterator< T, F, offset >::iterator_category = std::input_iterator_tag

Definition at line 99 of file value_stream.h.

◆ pointer

template<typename T, typename F = T, std::size_t offset = 0>
using lmdb::value_iterator< T, F, offset >::pointer = void

Definition at line 97 of file value_stream.h.

◆ reference

template<typename T, typename F = T, std::size_t offset = 0>
using lmdb::value_iterator< T, F, offset >::reference = value_type

Definition at line 96 of file value_stream.h.

◆ value_type

template<typename T, typename F = T, std::size_t offset = 0>
using lmdb::value_iterator< T, F, offset >::value_type = F

Definition at line 95 of file value_stream.h.

Constructor & Destructor Documentation

◆ value_iterator() [1/3]

template<typename T, typename F = T, std::size_t offset = 0>
lmdb::value_iterator< T, F, offset >::value_iterator ( )
inlinenoexcept

Construct an "end" iterator.

Definition at line 102 of file value_stream.h.

103 : cur(nullptr), values()
104 {}
Here is the caller graph for this function:

◆ value_iterator() [2/3]

template<typename T, typename F = T, std::size_t offset = 0>
lmdb::value_iterator< T, F, offset >::value_iterator ( MDB_cursor * cur)
inline
Parameters
curIterate over values starting at this cursor position.
Exceptions
std::system_errorif unexpected LMDB error. This can happen if cur is invalid.

Definition at line 111 of file value_stream.h.

112 : cur(cur), values()
113 {
114 if (cur)
115 values = lmdb::stream::get(*cur, MDB_GET_CURRENT, 0, sizeof(T)).second;
116 }
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:

◆ value_iterator() [3/3]

template<typename T, typename F = T, std::size_t offset = 0>
lmdb::value_iterator< T, F, offset >::value_iterator ( value_iterator< T, F, offset > const & )
default
Here is the call graph for this function:

◆ ~value_iterator()

template<typename T, typename F = T, std::size_t offset = 0>
lmdb::value_iterator< T, F, offset >::~value_iterator ( )
default

Member Function Documentation

◆ equal()

template<typename T, typename F = T, std::size_t offset = 0>
bool lmdb::value_iterator< T, F, offset >::equal ( value_iterator< T, F, offset > const & rhs) const
inlinenoexcept
Returns
True iff rhs is referencing this value.

Definition at line 126 of file value_stream.h.

127 {
128 return
129 (values.empty() && rhs.values.empty()) ||
130 values.data() == rhs.values.data();
131 }
constexpr bool empty() const noexcept
Definition span.h:109
constexpr pointer data() const noexcept
Definition span.h:110
Here is the call graph for this function:

◆ get_value()

template<typename T, typename F = T, std::size_t offset = 0>
template<typename U, typename G = U, std::size_t uoffset = 0>
G lmdb::value_iterator< T, F, offset >::get_value ( ) const
inlinenoexcept

Get a specific field within F. Default behavior is to return the entirety of U, despite the filtering logic of operator*.

Precondition
!is_end()
Template Parameters
Umust match T, used for ELECTRONEUM_FIELD sanity checking.
Gfield type to extract from the value
uoffsetto G type, or 0 when std::is_same<U, G>().
Returns
The field G, at uoffset within U.

Definition at line 161 of file value_stream.h.

162 {
163 static_assert(std::is_same<U, T>(), "bad ELECTRONEUM_FIELD usage?");
164 static_assert(std::is_pod<U>(), "value type must be pod");
165 static_assert(std::is_pod<G>(), "field type must be pod");
166 static_assert(sizeof(G) + uoffset <= sizeof(U), "bad field and/or offset");
167 assert(sizeof(G) + uoffset <= values.size());
168 assert(!is_end());
169
170 G value;
171 std::memcpy(std::addressof(value), values.data() + uoffset, sizeof(value));
172 return value;
173 }
bool is_end() const noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_end()

template<typename T, typename F = T, std::size_t offset = 0>
bool lmdb::value_iterator< T, F, offset >::is_end ( ) const
inlinenoexcept
Returns
True if this is one-past the last value.

Definition at line 123 of file value_stream.h.

123{ return values.empty(); }
Here is the caller graph for this function:

◆ operator*()

template<typename T, typename F = T, std::size_t offset = 0>
value_type lmdb::value_iterator< T, F, offset >::operator* ( ) const
inlinenoexcept
Precondition
!is_end()
Returns
The field F, at offset, within T.

Definition at line 176 of file value_stream.h.

176{ return get_value<T, F, offset>(); }
G get_value() const noexcept
Here is the call graph for this function:

◆ operator++() [1/2]

template<typename T, typename F = T, std::size_t offset = 0>
value_iterator & lmdb::value_iterator< T, F, offset >::operator++ ( )
inline

Invalidates all prior copies of the iterator.

Definition at line 134 of file value_stream.h.

135 {
136 increment();
137 return *this;
138 }
Here is the call graph for this function:

◆ operator++() [2/2]

template<typename T, typename F = T, std::size_t offset = 0>
value_iterator lmdb::value_iterator< T, F, offset >::operator++ ( int )
inline
Returns
A copy that is already invalidated, ignore

Definition at line 141 of file value_stream.h.

142 {
143 value_iterator out{*this};
144 increment();
145 return out;
146 }
value_iterator() noexcept
Construct an "end" iterator.
Here is the call graph for this function:

◆ operator=()

template<typename T, typename F = T, std::size_t offset = 0>
value_iterator & lmdb::value_iterator< T, F, offset >::operator= ( value_iterator< T, F, offset > const & )
default
Here is the call graph for this function:

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/lmdb/value_stream.h