MDBX Containers
Loading...
Searching...
No Matches
mdbxc::AnyValueTable< KeyT > Class Template Referencefinal

Table storing values of arbitrary type associated with a key. More...

#include <AnyValueTable.hpp>

Inheritance diagram for mdbxc::AnyValueTable< KeyT >:
mdbxc::BaseTable

Public Member Functions

 AnyValueTable (std::shared_ptr< Connection > conn, std::string name="any_store", MDBX_db_flags_t flags=MDBX_DB_DEFAULTS|MDBX_CREATE)
 Constructs table using existing connection.
 
 AnyValueTable (const Config &cfg, std::string name="any_store", MDBX_db_flags_t flags=MDBX_DB_DEFAULTS|MDBX_CREATE)
 Constructs table using configuration.
 
 ~AnyValueTable () override=default
 Destructor.
 
template<class T>
void set (const KeyT &key, const T &value, MDBX_txn *txn=nullptr)
 Set value for key, replacing existing value.
 
template<class T>
void set (const KeyT &key, const T &value, const Transaction &txn)
 Set value using external transaction.
 
template<class T>
bool insert (const KeyT &key, const T &value, MDBX_txn *txn=nullptr)
 Insert value if key does not exist.
 
template<class T>
bool insert (const KeyT &key, const T &value, const Transaction &txn)
 Insert value using external transaction.
 
template<class T, class Fn>
void update (const KeyT &key, Fn &&fn, bool create_if_missing=false, MDBX_txn *txn=nullptr)
 Update value using functor.
 
template<class T, class Fn>
void update (const KeyT &key, Fn &&fn, bool create_if_missing, const Transaction &txn)
 Update using external transaction.
 
template<class T>
get (const KeyT &key, MDBX_txn *txn=nullptr) const
 Retrieve stored value or throw if missing.
 
template<class T>
get (const KeyT &key, const Transaction &txn) const
 Retrieve using external transaction.
 
template<class T>
std::pair< bool, T > find_compat (const KeyT &key, MDBX_txn *txn=nullptr) const
 Find value by key.
 
template<class T>
std::pair< bool, T > find_compat (const KeyT &key, const Transaction &txn) const
 Find value by key using external transaction (C++11 mode).
 
template<class T>
get_or (const KeyT &key, T default_value, MDBX_txn *txn=nullptr) const
 Get value or default if missing (C++11 mode).
 
template<class T>
get_or (const KeyT &key, T default_value, const Transaction &txn) const
 Get value or default using external transaction (C++11 mode).
 
template<class KT = KeyT>
bool contains (const KT &key, MDBX_txn *txn=nullptr) const
 Check if key exists.
 
bool contains (const KeyT &key, const Transaction &txn) const
 Check key existence using external transaction.
 
bool erase (const KeyT &key, MDBX_txn *txn=nullptr)
 Erase key from table.
 
bool erase (const KeyT &key, const Transaction &txn)
 Erase using external transaction.
 
std::vector< KeyT > keys (MDBX_txn *txn=nullptr) const
 List all keys stored in table.
 
std::vector< KeyT > keys (const Transaction &txn) const
 List keys using external transaction.
 
void set_type_tag_check (bool enabled) noexcept
 Enable or disable type-tag checking.
 
- Public Member Functions inherited from mdbxc::BaseTable
 BaseTable (std::shared_ptr< Connection > connection, std::string name, MDBX_db_flags_t flags)
 Construct the database table accessor.
 
virtual ~BaseTable ()=default
 
bool is_connected () const
 Checks if the connection is currently active.
 
void connect ()
 Connects to the MDBX environment if not already connected.
 
void disconnect ()
 Disconnects the MDBX environment.
 
void begin (TransactionMode mode=TransactionMode::WRITABLE)
 Begins a manual transaction (must be committed or rolled back later).
 
void commit ()
 Commits the current manual transaction.
 
void rollback ()
 Rolls back the current manual transaction.
 
template<typename Func>
void execute_in_transaction (Func operation, TransactionMode mode=TransactionMode::WRITABLE)
 Executes an operation inside an automatic transaction.
 

Private Member Functions

template<typename F>
void with_transaction (F &&action, TransactionMode mode, MDBX_txn *txn) const
 
template<class T>
bool put_typed (const KeyT &key, const T &value, bool upsert, MDBX_txn *txn)
 
template<class T>
bool get_typed (const KeyT &key, T &out, MDBX_txn *txn) const
 
bool db_contains (const KeyT &key, MDBX_txn *txn) const
 
bool db_erase (const KeyT &key, MDBX_txn *txn)
 
void db_list_keys (std::vector< KeyT > &out, MDBX_txn *txn) const
 
template<class T>
MDBX_val wrap_with_type_tag (const MDBX_val &raw) const
 
template<class T>
MDBX_val unwrap_and_check_type_tag (const MDBX_val &raw) const
 

Private Attributes

bool m_check_type_tag = false
 Flag enabling type-tag verification.
 

Additional Inherited Members

- Protected Member Functions inherited from mdbxc::BaseTable
MDBX_txn * thread_txn () const
 Returns the transaction bound to the current thread, if any.
 
MDBX_dbi handle () const
 Gets the raw DBI handle.
 
- Protected Attributes inherited from mdbxc::BaseTable
std::shared_ptr< Connectionm_connection
 Shared connection to MDBX environment.
 
MDBX_dbi m_dbi {}
 DBI handle for the opened table.
 

Detailed Description

template<class KeyT>
class mdbxc::AnyValueTable< KeyT >

Table storing values of arbitrary type associated with a key.

Template Parameters
KeyTType of the key used to access values.

Definition at line 17 of file AnyValueTable.hpp.

Constructor & Destructor Documentation

◆ AnyValueTable() [1/2]

template<class KeyT>
mdbxc::AnyValueTable< KeyT >::AnyValueTable ( std::shared_ptr< Connection > conn,
std::string name = "any_store",
MDBX_db_flags_t flags = MDBX_DB_DEFAULTS | MDBX_CREATE )
inline

Constructs table using existing connection.

Parameters
connShared connection to the environment.
nameName of the table.
flagsAdditional MDBX flags.

Definition at line 23 of file AnyValueTable.hpp.

◆ AnyValueTable() [2/2]

template<class KeyT>
mdbxc::AnyValueTable< KeyT >::AnyValueTable ( const Config & cfg,
std::string name = "any_store",
MDBX_db_flags_t flags = MDBX_DB_DEFAULTS | MDBX_CREATE )
inlineexplicit

Constructs table using configuration.

Parameters
cfgConfiguration settings.
nameName of the table.
flagsAdditional MDBX flags.

Definition at line 32 of file AnyValueTable.hpp.

◆ ~AnyValueTable()

template<class KeyT>
mdbxc::AnyValueTable< KeyT >::~AnyValueTable ( )
overridedefault

Destructor.

Member Function Documentation

◆ contains() [1/2]

template<class KeyT>
bool mdbxc::AnyValueTable< KeyT >::contains ( const KeyT & key,
const Transaction & txn ) const
inline

Check key existence using external transaction.

Parameters
keyKey to check.
txnActive transaction wrapper.
Returns
true if key is present, otherwise false.

Definition at line 254 of file AnyValueTable.hpp.

◆ contains() [2/2]

template<class KeyT>
template<class KT = KeyT>
bool mdbxc::AnyValueTable< KeyT >::contains ( const KT & key,
MDBX_txn * txn = nullptr ) const
inline

Check if key exists.

Template Parameters
KTKey type (defaults to KeyT).
Parameters
keyKey to check.
txnOptional transaction handle.
Returns
true if key is present, otherwise false.

Definition at line 244 of file AnyValueTable.hpp.

◆ db_contains()

template<class KeyT>
bool mdbxc::AnyValueTable< KeyT >::db_contains ( const KeyT & key,
MDBX_txn * txn ) const
inlineprivate

Definition at line 349 of file AnyValueTable.hpp.

◆ db_erase()

template<class KeyT>
bool mdbxc::AnyValueTable< KeyT >::db_erase ( const KeyT & key,
MDBX_txn * txn )
inlineprivate

Definition at line 359 of file AnyValueTable.hpp.

◆ db_list_keys()

template<class KeyT>
void mdbxc::AnyValueTable< KeyT >::db_list_keys ( std::vector< KeyT > & out,
MDBX_txn * txn ) const
inlineprivate

Definition at line 369 of file AnyValueTable.hpp.

◆ erase() [1/2]

template<class KeyT>
bool mdbxc::AnyValueTable< KeyT >::erase ( const KeyT & key,
const Transaction & txn )
inline

Erase using external transaction.

Parameters
keyKey to remove.
txnActive transaction wrapper.
Returns
true if key was removed, otherwise false.

Definition at line 272 of file AnyValueTable.hpp.

◆ erase() [2/2]

template<class KeyT>
bool mdbxc::AnyValueTable< KeyT >::erase ( const KeyT & key,
MDBX_txn * txn = nullptr )
inline

Erase key from table.

Parameters
keyKey to remove.
txnOptional transaction handle.
Returns
true if key was removed, otherwise false.

Definition at line 262 of file AnyValueTable.hpp.

◆ find_compat() [1/2]

template<class KeyT>
template<class T>
std::pair< bool, T > mdbxc::AnyValueTable< KeyT >::find_compat ( const KeyT & key,
const Transaction & txn ) const
inline

Find value by key using external transaction (C++11 mode).

Template Parameters
TExpected value type.
Parameters
keyKey to search for.
txnActive transaction wrapper.
Returns
Pair of success flag and retrieved value.

Definition at line 205 of file AnyValueTable.hpp.

◆ find_compat() [2/2]

template<class KeyT>
template<class T>
std::pair< bool, T > mdbxc::AnyValueTable< KeyT >::find_compat ( const KeyT & key,
MDBX_txn * txn = nullptr ) const
inline

Find value by key.

Returns
Optional with value or std::nullopt.

Find value by key returning C++11-compatible result.

Template Parameters
TExpected value type.
Parameters
keyKey to search for.
txnOptional transaction handle.
Returns
Pair of success flag and retrieved value.

Definition at line 185 of file AnyValueTable.hpp.

◆ get() [1/2]

template<class KeyT>
template<class T>
T mdbxc::AnyValueTable< KeyT >::get ( const KeyT & key,
const Transaction & txn ) const
inline

Retrieve using external transaction.

Definition at line 127 of file AnyValueTable.hpp.

◆ get() [2/2]

template<class KeyT>
template<class T>
T mdbxc::AnyValueTable< KeyT >::get ( const KeyT & key,
MDBX_txn * txn = nullptr ) const
inline

Retrieve stored value or throw if missing.

Parameters
keyKey to look up.
txnOptional transaction handle.
Exceptions
std::out_of_rangeif key not found.
std::bad_castif type tag check fails.

Definition at line 113 of file AnyValueTable.hpp.

◆ get_or() [1/2]

template<class KeyT>
template<class T>
T mdbxc::AnyValueTable< KeyT >::get_or ( const KeyT & key,
T default_value,
const Transaction & txn ) const
inline

Get value or default using external transaction (C++11 mode).

Template Parameters
TExpected value type.
Parameters
keyKey to look up.
default_valueValue returned when key not found.
txnActive transaction wrapper.
Returns
Stored value or default_value when the key is absent.

Definition at line 231 of file AnyValueTable.hpp.

◆ get_or() [2/2]

template<class KeyT>
template<class T>
T mdbxc::AnyValueTable< KeyT >::get_or ( const KeyT & key,
T default_value,
MDBX_txn * txn = nullptr ) const
inline

Get value or default if missing (C++11 mode).

Template Parameters
TExpected value type.
Parameters
keyKey to look up.
default_valueValue returned when key not found.
txnOptional transaction handle.
Returns
Stored value or default_value when the key is absent.

Definition at line 216 of file AnyValueTable.hpp.

◆ get_typed()

template<class KeyT>
template<class T>
bool mdbxc::AnyValueTable< KeyT >::get_typed ( const KeyT & key,
T & out,
MDBX_txn * txn ) const
inlineprivate

Definition at line 337 of file AnyValueTable.hpp.

◆ insert() [1/2]

template<class KeyT>
template<class T>
bool mdbxc::AnyValueTable< KeyT >::insert ( const KeyT & key,
const T & value,
const Transaction & txn )
inline

Insert value using external transaction.

Definition at line 73 of file AnyValueTable.hpp.

◆ insert() [2/2]

template<class KeyT>
template<class T>
bool mdbxc::AnyValueTable< KeyT >::insert ( const KeyT & key,
const T & value,
MDBX_txn * txn = nullptr )
inline

Insert value if key does not exist.

Returns
true if inserted, false if key already exists.

Definition at line 63 of file AnyValueTable.hpp.

◆ keys() [1/2]

template<class KeyT>
std::vector< KeyT > mdbxc::AnyValueTable< KeyT >::keys ( const Transaction & txn) const
inline

List keys using external transaction.

Parameters
txnActive transaction wrapper.
Returns
Vector containing every key stored in the table.

Definition at line 288 of file AnyValueTable.hpp.

◆ keys() [2/2]

template<class KeyT>
std::vector< KeyT > mdbxc::AnyValueTable< KeyT >::keys ( MDBX_txn * txn = nullptr) const
inline

List all keys stored in table.

Parameters
txnOptional transaction handle.
Returns
Vector containing every key stored in the table.

Definition at line 279 of file AnyValueTable.hpp.

◆ put_typed()

template<class KeyT>
template<class T>
bool mdbxc::AnyValueTable< KeyT >::put_typed ( const KeyT & key,
const T & value,
bool upsert,
MDBX_txn * txn )
inlineprivate

Definition at line 321 of file AnyValueTable.hpp.

◆ set() [1/2]

template<class KeyT>
template<class T>
void mdbxc::AnyValueTable< KeyT >::set ( const KeyT & key,
const T & value,
const Transaction & txn )
inline

Set value using external transaction.

Definition at line 56 of file AnyValueTable.hpp.

◆ set() [2/2]

template<class KeyT>
template<class T>
void mdbxc::AnyValueTable< KeyT >::set ( const KeyT & key,
const T & value,
MDBX_txn * txn = nullptr )
inline

Set value for key, replacing existing value.

Template Parameters
TType of value.
Parameters
keyKey to update.
valueValue to store.
txnOptional transaction handle.

Definition at line 48 of file AnyValueTable.hpp.

◆ set_type_tag_check()

template<class KeyT>
void mdbxc::AnyValueTable< KeyT >::set_type_tag_check ( bool enabled)
inlinenoexcept

Enable or disable type-tag checking.

Parameters
enabledEnables check when set to true.

Definition at line 294 of file AnyValueTable.hpp.

◆ unwrap_and_check_type_tag()

template<class KeyT>
template<class T>
MDBX_val mdbxc::AnyValueTable< KeyT >::unwrap_and_check_type_tag ( const MDBX_val & raw) const
inlineprivate

Definition at line 386 of file AnyValueTable.hpp.

◆ update() [1/2]

template<class KeyT>
template<class T, class Fn>
void mdbxc::AnyValueTable< KeyT >::update ( const KeyT & key,
Fn && fn,
bool create_if_missing,
const Transaction & txn )
inline

Update using external transaction.

Definition at line 101 of file AnyValueTable.hpp.

◆ update() [2/2]

template<class KeyT>
template<class T, class Fn>
void mdbxc::AnyValueTable< KeyT >::update ( const KeyT & key,
Fn && fn,
bool create_if_missing = false,
MDBX_txn * txn = nullptr )
inline

Update value using functor.

Template Parameters
TExpected type of stored value.
FnFunctor accepting reference to value.
Parameters
keyKey to modify.
fnFunction applied to the value.
create_if_missingCreate default value if key is absent.
txnOptional transaction handle.

Definition at line 85 of file AnyValueTable.hpp.

◆ with_transaction()

template<class KeyT>
template<typename F>
void mdbxc::AnyValueTable< KeyT >::with_transaction ( F && action,
TransactionMode mode,
MDBX_txn * txn ) const
inlineprivate

Definition at line 300 of file AnyValueTable.hpp.

◆ wrap_with_type_tag()

template<class KeyT>
template<class T>
MDBX_val mdbxc::AnyValueTable< KeyT >::wrap_with_type_tag ( const MDBX_val & raw) const
inlineprivate

Definition at line 380 of file AnyValueTable.hpp.

Member Data Documentation

◆ m_check_type_tag

template<class KeyT>
bool mdbxc::AnyValueTable< KeyT >::m_check_type_tag = false
private

Flag enabling type-tag verification.

Definition at line 297 of file AnyValueTable.hpp.


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