Electroneum
Public Member Functions | Private Attributes | List of all members
lmdb::value_stream< T, D > Class Template Reference

#include <value_stream.h>

Public Member Functions

 value_stream (std::unique_ptr< MDB_cursor, D > cur)
 Take ownership of cur without changing position. nullptr valid. More...
 
 value_stream (value_stream &&)=default
 
 value_stream (value_stream const &)=delete
 
 ~value_stream ()=default
 
value_streamoperator= (value_stream &&)=default
 
value_streamoperator= (value_stream const &)=delete
 
std::unique_ptr< MDB_cursor, D > give_cursor () noexcept
 
void reset ()
 
std::size_t count () const
 
template<typename U = T, typename F = U, std::size_t offset = 0>
value_iterator< U, F, offset > make_iterator () const
 
template<typename U = T, typename F = U, std::size_t offset = 0>
boost::iterator_range< value_iterator< U, F, offset > > make_range () const
 

Private Attributes

std::unique_ptr< MDB_cursor, D > cur
 

Detailed Description

template<typename T, typename D>
class lmdb::value_stream< T, D >

C++ wrapper for a LMDB read-only cursor on a fixed-sized value T.

Template Parameters
Tvalue type being stored by each record.
Dcleanup functor for the cursor; usually unique per db/table.

Constructor & Destructor Documentation

◆ value_stream() [1/3]

template<typename T , typename D >
lmdb::value_stream< T, D >::value_stream ( std::unique_ptr< MDB_cursor, D >  cur)
inlineexplicit

Take ownership of cur without changing position. nullptr valid.

◆ value_stream() [2/3]

template<typename T , typename D >
lmdb::value_stream< T, D >::value_stream ( value_stream< T, D > &&  )
default

◆ value_stream() [3/3]

template<typename T , typename D >
lmdb::value_stream< T, D >::value_stream ( value_stream< T, D > const &  )
delete

◆ ~value_stream()

template<typename T , typename D >
lmdb::value_stream< T, D >::~value_stream ( )
default

Member Function Documentation

◆ count()

template<typename T , typename D >
std::size_t lmdb::value_stream< T, D >::count ( ) const
inline
Exceptions
std::system_errorif LMDB has unexpected errors.
Returns
Number of values at this key.

◆ give_cursor()

template<typename T , typename D >
std::unique_ptr<MDB_cursor, D> lmdb::value_stream< T, D >::give_cursor ( )
inlinenoexcept

Give up ownership of the cursor. count(), make_iterator() and make_range() can still be invoked, but return the empty set.

Returns
Currently owned LMDB cursor.

◆ make_iterator()

template<typename T , typename D >
template<typename U = T, typename F = U, std::size_t offset = 0>
value_iterator<U, F, offset> lmdb::value_stream< T, D >::make_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 entire value (T). 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.

◆ make_range()

template<typename T , typename D >
template<typename U = T, typename F = U, std::size_t offset = 0>
boost::iterator_range<value_iterator<U, F, offset> > lmdb::value_stream< T, D >::make_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.

◆ operator=() [1/2]

template<typename T , typename D >
value_stream& lmdb::value_stream< T, D >::operator= ( value_stream< T, D > &&  )
default

◆ operator=() [2/2]

template<typename T , typename D >
value_stream& lmdb::value_stream< T, D >::operator= ( value_stream< T, D > const &  )
delete

◆ reset()

template<typename T , typename D >
void lmdb::value_stream< T, D >::reset ( )
inline

Place the stream back at the first value. Newly created iterators will start at the first value again.

Note
Invalidates all current iterators from this, including those created with make_iterator or make_range.

Member Data Documentation

◆ cur

template<typename T , typename D >
std::unique_ptr<MDB_cursor, D> lmdb::value_stream< T, D >::cur
private

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