lmdb++
Loading...
Searching...
No Matches
lmdb::cursor Class Reference

Resource class for MDB_cursor* handles. More...

#include <lmdb++.h>

Public Member Functions

 cursor (MDB_cursor *const handle) noexcept
 Constructor.
 
 cursor (cursor &&other) noexcept
 Move constructor.
 
cursoroperator= (cursor &&other) noexcept
 Move assignment operator.
 
 ~cursor () noexcept
 Destructor.
 
 operator MDB_cursor * () const noexcept
 Returns the underlying MDB_cursor* handle.
 
MDB_cursor * handle () const noexcept
 Returns the underlying MDB_cursor* handle.
 
void close () noexcept
 Closes this cursor.
 
void renew (MDB_txn *const txn)
 Renews this cursor.
 
MDB_txn * txn () const noexcept
 Returns the cursor's transaction handle.
 
MDB_dbi dbi () const noexcept
 Returns the cursor's database handle.
 
bool get (std::string_view &key, const MDB_cursor_op op)
 Retrieves a key from the database.
 
bool get (std::string_view &key, std::string_view &val, const MDB_cursor_op op)
 Retrieves a key/value pair from the database.
 
bool put (const std::string_view &key, const std::string_view &val, const unsigned int flags=0)
 Stores key/data pairs into the database.
 
void del (unsigned int flags=0)
 Delete current key/data pair.
 
size_t count ()
 Return count of duplicates for current key.
 

Static Public Member Functions

static cursor open (MDB_txn *const txn, const MDB_dbi dbi)
 Creates an LMDB cursor.
 

Static Public Attributes

static constexpr unsigned int default_flags = 0
 

Protected Attributes

MDB_cursor * _handle {nullptr}
 

Detailed Description

Resource class for MDB_cursor* handles.

Note
Instances of this class are movable, but not copyable.
See also
http://symas.com/mdb/doc/group__internal.html#structMDB__cursor

Constructor & Destructor Documentation

◆ cursor() [1/2]

lmdb::cursor::cursor ( MDB_cursor *const handle)
inlinenoexcept

Constructor.

Parameters
handlea valid MDB_cursor* handle

◆ cursor() [2/2]

lmdb::cursor::cursor ( cursor && other)
inlinenoexcept

Move constructor.

◆ ~cursor()

lmdb::cursor::~cursor ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ close()

void lmdb::cursor::close ( )
inlinenoexcept

Closes this cursor.

Note
this method is idempotent
Postcondition
handle() == nullptr

◆ count()

size_t lmdb::cursor::count ( )
inline

Return count of duplicates for current key.

This call is only valid on databases that support sorted duplicate data items MDB_DUPSORT.

◆ dbi()

MDB_dbi lmdb::cursor::dbi ( ) const
inlinenoexcept

Returns the cursor's database handle.

◆ del()

void lmdb::cursor::del ( unsigned int flags = 0)
inline

Delete current key/data pair.

Parameters
flagsOptions for this operation. Values: MDB_NODUPDATA - delete all of the data items for the current key. This flag may only be specified if the database was opened with MDB_DUPSORT.

◆ get() [1/2]

bool lmdb::cursor::get ( std::string_view & key,
const MDB_cursor_op op )
inline

Retrieves a key from the database.

Parameters
key
op
Exceptions
lmdb::erroron failure

◆ get() [2/2]

bool lmdb::cursor::get ( std::string_view & key,
std::string_view & val,
const MDB_cursor_op op )
inline

Retrieves a key/value pair from the database.

Parameters
key
val
op
Exceptions
lmdb::erroron failure

◆ handle()

MDB_cursor * lmdb::cursor::handle ( ) const
inlinenoexcept

Returns the underlying MDB_cursor* handle.

◆ open()

static cursor lmdb::cursor::open ( MDB_txn *const txn,
const MDB_dbi dbi )
inlinestatic

Creates an LMDB cursor.

Parameters
txnthe transaction handle
dbithe database handle
Exceptions
lmdb::erroron failure

◆ operator MDB_cursor *()

lmdb::cursor::operator MDB_cursor * ( ) const
inlinenoexcept

Returns the underlying MDB_cursor* handle.

◆ operator=()

cursor & lmdb::cursor::operator= ( cursor && other)
inlinenoexcept

Move assignment operator.

◆ put()

bool lmdb::cursor::put ( const std::string_view & key,
const std::string_view & val,
const unsigned int flags = 0 )
inline

Stores key/data pairs into the database.

The cursor is positioned at the new item, or on failure usually near it.

See MDB docs for flag values.

Parameters
key
val
flags
Exceptions
lmdb::erroron failure

◆ renew()

void lmdb::cursor::renew ( MDB_txn *const txn)
inline

Renews this cursor.

Parameters
txnthe transaction scope
Exceptions
lmdb::erroron failure

◆ txn()

MDB_txn * lmdb::cursor::txn ( ) const
inlinenoexcept

Returns the cursor's transaction handle.

Member Data Documentation

◆ _handle

MDB_cursor* lmdb::cursor::_handle {nullptr}
protected

◆ default_flags

unsigned int lmdb::cursor::default_flags = 0
staticconstexpr

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