Electroneum
Loading...
Searching...
No Matches
lmdb::basic_table< K, V > Struct Template Reference

Helper for grouping typical LMDB DBI options when key and value are fixed types. More...

#include <table.h>

Inheritance diagram for lmdb::basic_table< K, V >:
Collaboration diagram for lmdb::basic_table< K, V >:

Public Types

using key_type = K
using value_type = V

Public Member Functions

constexpr basic_table (const char *name, unsigned flags=0, MDB_cmp_func value_cmp=nullptr) noexcept
Public Member Functions inherited from lmdb::table
expect< MDB_dbiopen (MDB_txn &write_txn) const noexcept

Static Public Member Functions

static constexpr unsigned compute_flags (const unsigned flags) noexcept
template<typename U, typename F = U, std::size_t offset = 0>
static expect< Fget_value (MDB_val value) noexcept
template<typename D>
static expect< key_stream< K, V, D > > get_key_stream (std::unique_ptr< MDB_cursor, D > cur) noexcept
template<typename D>
static expect< value_stream< V, D > > get_value_stream (K const &key, std::unique_ptr< MDB_cursor, D > cur) noexcept

Additional Inherited Members

Public Attributes inherited from lmdb::table
char const *const name
const unsigned flags
MDB_cmp_func *const key_cmp
MDB_cmp_func *const value_cmp

Detailed Description

template<typename K, typename V>
struct lmdb::basic_table< K, V >

Helper for grouping typical LMDB DBI options when key and value are fixed types.

Definition at line 27 of file table.h.

Member Typedef Documentation

◆ key_type

template<typename K, typename V>
using lmdb::basic_table< K, V >::key_type = K

Definition at line 29 of file table.h.

◆ value_type

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

Definition at line 30 of file table.h.

Constructor & Destructor Documentation

◆ basic_table()

template<typename K, typename V>
lmdb::basic_table< K, V >::basic_table ( const char * name,
unsigned flags = 0,
MDB_cmp_func value_cmp = nullptr )
inlineexplicitconstexprnoexcept

Definition at line 38 of file table.h.

40 {}
Helper for grouping typical LMDB DBI options when key and value are fixed types.
Definition table.h:28
static constexpr unsigned compute_flags(const unsigned flags) noexcept
Definition table.h:33
const unsigned flags
Definition table.h:17
MDB_cmp_func *const value_cmp
Definition table.h:19
char const *const name
Definition table.h:16
Here is the call graph for this function:

Member Function Documentation

◆ compute_flags()

template<typename K, typename V>
constexpr unsigned lmdb::basic_table< K, V >::compute_flags ( const unsigned flags)
inlinestaticconstexprnoexcept
Returns
Additional LMDB flags based on flags value.

Definition at line 33 of file table.h.

34 {
35 return flags | ((flags & MDB_DUPSORT) ? MDB_DUPFIXED : 0);
36 }
Here is the caller graph for this function:

◆ get_key_stream()

template<typename K, typename V>
template<typename D>
expect< key_stream< K, V, D > > lmdb::basic_table< K, V >::get_key_stream ( std::unique_ptr< MDB_cursor, D > cur)
inlinestaticnoexcept
Precondition
cur != nullptr.
Parameters
curActive cursor on table. Returned in object on success, otherwise destroyed.
Returns
A handle to the first key/value in the table linked to cur or an empty key_stream.

Definition at line 78 of file table.h.

79 {
80 ELECTRONEUM_PRECOND(cur != nullptr);
81
84 const int err = mdb_cursor_get(cur.get(), &key, &value, MDB_FIRST);
85 if (err)
86 {
87 if (err != MDB_NOTFOUND)
88 return {lmdb::error(err)};
89 cur.reset(); // return empty set
90 }
92 }
#define ELECTRONEUM_PRECOND(...)
If precondition fails, return error::kInvalidArgument in current scope.
Definition expect.h:39
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
error
Tracks LMDB error codes.
Definition error.h:45
Here is the call graph for this function:

◆ get_value()

template<typename K, typename V>
template<typename U, typename F = U, std::size_t offset = 0>
expect< F > lmdb::basic_table< K, V >::get_value ( MDB_val value)
inlinestaticnoexcept
Template Parameters
Umust be same as V; used for sanity checking.
Fis the type within U that is being extracted.
offsetto F within U.
Note
If using F and offset to retrieve a specific field, use ELECTRONEUM_FIELD macro in src/lmdb/util.h which calculates the offset automatically.
Returns
Value of type F at offset within value which has type U.

Definition at line 55 of file table.h.

56 {
57 static_assert(std::is_same<U, V>(), "bad ELECTRONEUM_FIELD?");
58 static_assert(std::is_pod<F>(), "F must be POD");
59 static_assert(sizeof(F) + offset <= sizeof(U), "bad field type and/or offset");
60
61 if (value.mv_size != sizeof(U))
63
64 F out;
65 std::memcpy(std::addressof(out), static_cast<char*>(value.mv_data) + offset, sizeof(out));
66 return out;
67 }

◆ get_value_stream()

template<typename K, typename V>
template<typename D>
expect< value_stream< V, D > > lmdb::basic_table< K, V >::get_value_stream ( K const & key,
std::unique_ptr< MDB_cursor, D > cur )
inlinestaticnoexcept
Precondition
cur != nullptr.
Parameters
curActive cursor on table. Returned in object on success, otherwise destroyed.
Returns
A handle to the first value at key in the table linked to cur or an empty value_stream.

Definition at line 103 of file table.h.

104 {
105 ELECTRONEUM_PRECOND(cur != nullptr);
106
109 const int err = mdb_cursor_get(cur.get(), &key_bytes, &value, MDB_SET);
110 if (err)
111 {
112 if (err != MDB_NOTFOUND)
113 return {lmdb::error(err)};
114 cur.reset(); // return empty set
115 }
117 }
MDB_val to_val(T &&value) noexcept
Definition util.h:88
Here is the call graph for this function:

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