14 #error "<lmdb++.h> requires a C++ compiler"
17 #if __cplusplus < 201103L
18 #error "<lmdb++.h> requires a C++11 compiler (CXXFLAGS='-std=c++11')"
33 #include <type_traits>
47 class key_exist_error;
48 class not_found_error;
49 class corrupted_error;
51 class version_mismatch_error;
69 [[noreturn]]
static inline void raise(
const char*
origin,
int rc);
75 const int rc) noexcept
82 int code() const noexcept {
89 const char*
origin() const noexcept {
96 virtual const char*
what() const noexcept {
97 static thread_local
char buffer[1024];
98 std::snprintf(buffer,
sizeof(buffer),
135 using runtime_error::runtime_error;
145 using runtime_error::runtime_error;
155 using fatal_error::fatal_error;
165 using fatal_error::fatal_error;
175 using fatal_error::fatal_error;
185 using runtime_error::runtime_error;
196 using runtime_error::runtime_error;
229 static inline void env_open(MDB_env* env,
230 const char* path,
unsigned int flags,
mode mode);
231 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14)
232 static inline void env_copy(MDB_env* env,
const char* path,
unsigned int flags);
233 static inline void env_copy_fd(MDB_env* env, mdb_filehandle_t fd,
unsigned int flags);
235 static inline void env_copy(MDB_env* env,
const char* path);
236 static inline void env_copy_fd(MDB_env* env, mdb_filehandle_t fd);
238 static inline void env_stat(MDB_env* env, MDB_stat* stat);
239 static inline void env_info(MDB_env* env, MDB_envinfo* stat);
240 static inline void env_sync(MDB_env* env,
bool force);
241 static inline void env_close(MDB_env* env) noexcept;
242 static inline void env_set_flags(MDB_env* env,
unsigned int flags,
bool onoff);
243 static inline void env_get_flags(MDB_env* env,
unsigned int* flags);
244 static inline void env_get_path(MDB_env* env,
const char** path);
245 static inline void env_get_fd(MDB_env* env, mdb_filehandle_t* fd);
251 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11)
266 const int rc = ::mdb_env_create(env);
267 if (rc != MDB_SUCCESS) {
278 const char*
const path,
279 const unsigned int flags,
281 const int rc = ::mdb_env_open(env, path, flags, mode);
282 if (rc != MDB_SUCCESS) {
294 #
if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14)
295 const char*
const path,
296 const unsigned int flags = 0) {
297 const int rc = ::mdb_env_copy2(env, path, flags);
299 const char*
const path) {
300 const int rc = ::mdb_env_copy(env, path);
302 if (rc != MDB_SUCCESS) {
314 #
if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14)
315 const mdb_filehandle_t fd,
316 const unsigned int flags = 0) {
317 const int rc = ::mdb_env_copyfd2(env, fd, flags);
319 const mdb_filehandle_t fd) {
320 const int rc = ::mdb_env_copyfd(env, fd);
322 if (rc != MDB_SUCCESS) {
333 MDB_stat*
const stat) {
334 const int rc = ::mdb_env_stat(env, stat);
335 if (rc != MDB_SUCCESS) {
346 MDB_envinfo*
const stat) {
347 const int rc = ::mdb_env_info(env, stat);
348 if (rc != MDB_SUCCESS) {
359 const bool force =
true) {
360 const int rc = ::mdb_env_sync(env, force);
361 if (rc != MDB_SUCCESS) {
371 ::mdb_env_close(env);
380 const unsigned int flags,
381 const bool onoff =
true) {
382 const int rc = ::mdb_env_set_flags(env, flags, onoff ? 1 : 0);
383 if (rc != MDB_SUCCESS) {
394 unsigned int*
const flags) {
395 const int rc = ::mdb_env_get_flags(env, flags);
396 if (rc != MDB_SUCCESS) {
408 const int rc = ::mdb_env_get_path(env, path);
409 if (rc != MDB_SUCCESS) {
420 mdb_filehandle_t*
const fd) {
421 const int rc = ::mdb_env_get_fd(env, fd);
422 if (rc != MDB_SUCCESS) {
433 const std::size_t size) {
434 const int rc = ::mdb_env_set_mapsize(env, size);
435 if (rc != MDB_SUCCESS) {
446 const unsigned int count) {
447 const int rc = ::mdb_env_set_maxreaders(env, count);
448 if (rc != MDB_SUCCESS) {
459 unsigned int*
const count) {
460 const int rc = ::mdb_env_get_maxreaders(env, count);
461 if (rc != MDB_SUCCESS) {
472 const MDB_dbi count) {
473 const int rc = ::mdb_env_set_maxdbs(env, count);
474 if (rc != MDB_SUCCESS) {
482 static inline unsigned int
484 const int rc = ::mdb_env_get_maxkeysize(env);
488 return static_cast<unsigned int>(rc);
491 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11)
500 const int rc = ::mdb_env_set_userctx(env, ctx);
501 if (rc != MDB_SUCCESS) {
507 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11)
514 return ::mdb_env_get_userctx(env);
523 MDB_env* env, MDB_txn* parent,
unsigned int flags, MDB_txn** txn);
524 static inline MDB_env*
txn_env(MDB_txn*
const txn) noexcept;
526 static inline void txn_abort(MDB_txn* txn) noexcept;
527 static inline void txn_reset(MDB_txn* txn) noexcept;
528 static inline void txn_renew(MDB_txn* txn);
537 MDB_txn*
const parent,
538 const unsigned int flags,
540 const int rc = ::mdb_txn_begin(env, parent, flags, txn);
541 if (rc != MDB_SUCCESS) {
549 static inline MDB_env*
551 return ::mdb_txn_env(
txn);
560 const int rc = ::mdb_txn_commit(txn);
561 if (rc != MDB_SUCCESS) {
571 ::mdb_txn_abort(
txn);
579 ::mdb_txn_reset(
txn);
588 const int rc = ::mdb_txn_renew(txn);
589 if (rc != MDB_SUCCESS) {
599 MDB_txn* txn,
const char* name,
unsigned int flags, MDB_dbi* dbi);
600 static inline void dbi_stat(MDB_txn* txn, MDB_dbi dbi, MDB_stat* stat);
601 static inline void dbi_flags(MDB_txn* txn, MDB_dbi dbi,
unsigned int* flags);
602 static inline void dbi_close(MDB_env* env, MDB_dbi dbi) noexcept;
603 static inline void dbi_drop(MDB_txn* txn, MDB_dbi dbi,
bool del);
604 static inline void dbi_set_compare(MDB_txn* txn, MDB_dbi dbi, MDB_cmp_func* cmp);
605 static inline void dbi_set_dupsort(MDB_txn* txn, MDB_dbi dbi, MDB_cmp_func* cmp);
606 static inline void dbi_set_relfunc(MDB_txn* txn, MDB_dbi dbi, MDB_rel_func* rel);
607 static inline void dbi_set_relctx(MDB_txn* txn, MDB_dbi dbi,
void* ctx);
608 static inline bool dbi_get(MDB_txn* txn, MDB_dbi dbi, MDB_val* key, MDB_val* data);
609 static inline bool dbi_put(MDB_txn* txn, MDB_dbi dbi, MDB_val* key, MDB_val* data,
unsigned int flags);
610 static inline bool dbi_del(MDB_txn* txn, MDB_dbi dbi, MDB_val* key, MDB_val* data);
621 const char*
const name,
622 const unsigned int flags,
623 MDB_dbi*
const dbi) {
624 const int rc = ::mdb_dbi_open(txn, name, flags, dbi);
625 if (rc != MDB_SUCCESS) {
637 MDB_stat*
const result) {
638 const int rc = ::mdb_stat(txn, dbi, result);
639 if (rc != MDB_SUCCESS) {
651 unsigned int*
const flags) {
652 const int rc = ::mdb_dbi_flags(txn, dbi, flags);
653 if (rc != MDB_SUCCESS) {
663 const MDB_dbi
dbi) noexcept {
664 ::mdb_dbi_close(env,
dbi);
673 const bool del =
false) {
674 const int rc = ::mdb_drop(txn, dbi, del ? 1 : 0);
675 if (rc != MDB_SUCCESS) {
687 MDB_cmp_func*
const cmp =
nullptr) {
688 const int rc = ::mdb_set_compare(txn, dbi, cmp);
689 if (rc != MDB_SUCCESS) {
701 MDB_cmp_func*
const cmp =
nullptr) {
702 const int rc = ::mdb_set_dupsort(txn, dbi, cmp);
703 if (rc != MDB_SUCCESS) {
715 MDB_rel_func*
const rel) {
716 const int rc = ::mdb_set_relfunc(txn, dbi, rel);
717 if (rc != MDB_SUCCESS) {
730 const int rc = ::mdb_set_relctx(txn, dbi, ctx);
731 if (rc != MDB_SUCCESS) {
745 MDB_val*
const data) {
746 const int rc = ::mdb_get(txn, dbi, key, data);
747 if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) {
750 return (rc == MDB_SUCCESS);
763 const unsigned int flags = 0) {
764 const int rc = ::mdb_put(txn, dbi, key, data, flags);
765 if (rc != MDB_SUCCESS && rc != MDB_KEYEXIST) {
768 return (rc == MDB_SUCCESS);
780 MDB_val*
const data =
nullptr) {
781 const int rc = ::mdb_del(txn, dbi, key, data);
782 if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) {
785 return (rc == MDB_SUCCESS);
792 static inline void cursor_open(MDB_txn* txn, MDB_dbi dbi, MDB_cursor** cursor);
793 static inline void cursor_close(MDB_cursor* cursor) noexcept;
794 static inline void cursor_renew(MDB_txn* txn, MDB_cursor* cursor);
795 static inline MDB_txn*
cursor_txn(MDB_cursor* cursor) noexcept;
796 static inline MDB_dbi
cursor_dbi(MDB_cursor* cursor) noexcept;
797 static inline bool cursor_get(MDB_cursor* cursor, MDB_val* key, MDB_val* data, MDB_cursor_op op);
798 static inline void cursor_put(MDB_cursor* cursor, MDB_val* key, MDB_val* data,
unsigned int flags);
799 static inline void cursor_del(MDB_cursor* cursor,
unsigned int flags);
800 static inline void cursor_count(MDB_cursor* cursor, std::size_t& count);
810 MDB_cursor**
const cursor) {
811 const int rc = ::mdb_cursor_open(txn, dbi, cursor);
812 if (rc != MDB_SUCCESS) {
822 ::mdb_cursor_close(
cursor);
831 MDB_cursor*
const cursor) {
832 const int rc = ::mdb_cursor_renew(txn, cursor);
833 if (rc != MDB_SUCCESS) {
841 static inline MDB_txn*
843 return ::mdb_cursor_txn(
cursor);
849 static inline MDB_dbi
851 return ::mdb_cursor_dbi(
cursor);
862 const MDB_cursor_op op) {
863 const int rc = ::mdb_cursor_get(cursor, key, data, op);
864 if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) {
867 return (rc == MDB_SUCCESS);
878 const unsigned int flags = 0) {
879 const int rc = ::mdb_cursor_put(cursor, key, data, flags);
880 if (rc != MDB_SUCCESS) {
891 const unsigned int flags = 0) {
892 const int rc = ::mdb_cursor_del(cursor, flags);
893 if (rc != MDB_SUCCESS) {
904 std::size_t& count) {
905 const int rc = ::mdb_cursor_count(cursor, &count);
906 if (rc != MDB_SUCCESS) {
932 val() noexcept = default;
950 const std::size_t
size) noexcept
951 : _val{
size,
const_cast<void*
>(
data)} {}
956 val(
val&& other) noexcept =
default;
966 ~val() noexcept =
default;
971 operator MDB_val*() noexcept {
978 operator const MDB_val*()
const noexcept {
985 std::size_t
size() const noexcept {
994 return reinterpret_cast<T*
>(_val.mv_data);
1000 template<
typename T>
1002 return reinterpret_cast<T*
>(_val.mv_data);
1009 return reinterpret_cast<char*
>(_val.mv_data);
1015 const char*
data() const noexcept {
1016 return reinterpret_cast<char*
>(_val.mv_data);
1022 template<
typename T>
1024 const std::size_t
size) noexcept {
1025 _val.mv_size =
size;
1026 _val.mv_data =
const_cast<void*
>(
reinterpret_cast<const void*
>(
data));
1045 #ifndef __COVERITY__
1046 static_assert(std::is_pod<lmdb::val>::value,
"lmdb::val must be a POD type");
1047 static_assert(
sizeof(
lmdb::val) ==
sizeof(MDB_val),
"sizeof(lmdb::val) != sizeof(MDB_val)");
1065 MDB_env* _handle{
nullptr};
1068 static constexpr
unsigned int default_flags = 0;
1069 static constexpr
mode default_mode = 0644;
1077 static env
create(
const unsigned int flags = default_flags) {
1078 MDB_env* handle{
nullptr};
1081 assert(handle !=
nullptr);
1100 env(MDB_env*
const handle) noexcept
1101 : _handle{handle} {}
1107 std::swap(_handle, other._handle);
1114 if (
this != &other) {
1115 std::swap(_handle, other._handle);
1124 try { close(); }
catch (...) {}
1130 operator MDB_env*()
const noexcept {
1147 void sync(
const bool force =
true) {
1173 const unsigned int flags = default_flags,
1185 const bool onoff =
true) {
1233 MDB_txn* _handle{
nullptr};
1236 static constexpr
unsigned int default_flags = 0;
1247 MDB_txn*
const parent =
nullptr,
1248 const unsigned int flags = default_flags) {
1249 MDB_txn* handle{
nullptr};
1252 assert(handle !=
nullptr);
1262 txn(MDB_txn*
const handle) noexcept
1263 : _handle{handle} {}
1269 std::swap(_handle, other._handle);
1276 if (
this != &other) {
1277 std::swap(_handle, other._handle);
1287 try { abort(); }
catch (...) {}
1295 operator MDB_txn*()
const noexcept {
1309 MDB_env*
env() const noexcept {
1369 static constexpr
unsigned int default_flags = 0;
1370 static constexpr
unsigned int default_put_flags = 0;
1382 const char*
const name =
nullptr,
1383 const unsigned int flags = default_flags) {
1394 dbi(
const MDB_dbi handle) noexcept
1395 : _handle{handle} {}
1401 std::swap(_handle, other._handle);
1408 if (
this != &other) {
1409 std::swap(_handle, other._handle);
1426 operator MDB_dbi() const noexcept {
1456 unsigned int result{};
1468 return stat(txn).ms_entries;
1477 const bool del =
false) {
1489 MDB_cmp_func*
const cmp =
nullptr) {
1501 template<
typename K>
1503 const K& key)
const {
1517 template<
typename K,
typename V>
1518 bool get(MDB_txn*
const txn,
1538 template<
typename V>
1539 bool get(MDB_txn*
const txn,
1540 const char*
const key,
1559 template<
typename K>
1562 const unsigned int flags = default_put_flags) {
1577 template<
typename K,
typename V>
1581 const unsigned int flags = default_put_flags) {
1596 template<
typename V>
1598 const char*
const key,
1600 const unsigned int flags = default_put_flags) {
1616 const char*
const key,
1617 const char*
const val,
1618 const unsigned int flags = default_put_flags) {
1631 template<
typename K>
1654 MDB_cursor* _handle{
nullptr};
1657 static constexpr
unsigned int default_flags = 0;
1668 const MDB_dbi
dbi) {
1669 MDB_cursor* handle{};
1672 assert(handle !=
nullptr);
1683 : _handle{handle} {}
1689 std::swap(_handle, other._handle);
1696 if (
this != &other) {
1697 std::swap(_handle, other._handle);
1706 try { close(); }
catch (...) {}
1712 operator MDB_cursor*()
const noexcept {
1749 MDB_txn*
txn() const noexcept {
1756 MDB_dbi
dbi() const noexcept {
1767 bool get(MDB_val*
const key,
1768 const MDB_cursor_op op) {
1769 return get(key,
nullptr, op);
1780 const MDB_cursor_op op) {
1781 return get(key,
nullptr, op);
1792 bool get(MDB_val*
const key,
1794 const MDB_cursor_op op) {
1808 const MDB_cursor_op op) {
1820 bool get(std::string& key,
1822 const MDB_cursor_op op) {
1824 const bool found =
get(k, v, op);
1826 key.
assign(k.data(), k.size());
1827 val.
assign(v.data(), v.size());
1839 template<
typename K>
1841 const MDB_cursor_op op = MDB_SET) {
1843 return get(k,
nullptr, op);
static void env_create(MDB_env **env)
Definition: lmdb++.h:265
static void cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Definition: lmdb++.h:830
static MDB_env * txn_env(MDB_txn *const txn) noexcept
Definition: lmdb++.h:550
static void txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Definition: lmdb++.h:536
static void env_open(MDB_env *env, const char *path, unsigned int flags, mode mode)
Definition: lmdb++.h:277
val(const void *const data, const std::size_t size) noexcept
Constructor.
Definition: lmdb++.h:949
bool put(MDB_txn *const txn, const char *const key, const V &val, const unsigned int flags=default_put_flags)
Stores a key/value pair into this database.
Definition: lmdb++.h:1597
Exception class for MDB_PANIC errors.
Definition: lmdb++.h:163
env & operator=(env &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1113
cursor(MDB_cursor *const handle) noexcept
Constructor.
Definition: lmdb++.h:1682
static cursor open(MDB_txn *const txn, const MDB_dbi dbi)
Creates an LMDB cursor.
Definition: lmdb++.h:1667
bool put(MDB_txn *const txn, const K &key, const V &val, const unsigned int flags=default_put_flags)
Stores a key/value pair into this database.
Definition: lmdb++.h:1578
static void env_set_max_readers(MDB_env *env, unsigned int count)
Definition: lmdb++.h:445
Base class for LMDB exception conditions.
Definition: lmdb++.h:61
Base class for fatal error conditions.
Definition: lmdb++.h:115
static void env_stat(MDB_env *env, MDB_stat *stat)
Definition: lmdb++.h:332
Exception class for MDB_CORRUPTED errors.
Definition: lmdb++.h:153
const T * data() const noexcept
Returns a pointer to the data;.
Definition: lmdb++.h:1001
static void dbi_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel)
Definition: lmdb++.h:713
unsigned int flags(MDB_txn *const txn) const
Retrieves the flags for this database handle.
Definition: lmdb++.h:1455
static void env_sync(MDB_env *env, bool force)
Definition: lmdb++.h:358
cursor(cursor &&other) noexcept
Move constructor.
Definition: lmdb++.h:1688
static void cursor_del(MDB_cursor *cursor, unsigned int flags)
Definition: lmdb++.h:890
static void txn_reset(MDB_txn *txn) noexcept
Definition: lmdb++.h:578
MDB_stat stat(MDB_txn *const txn) const
Returns statistics for this database.
Definition: lmdb++.h:1443
dbi(dbi &&other) noexcept
Move constructor.
Definition: lmdb++.h:1400
env & open(const char *const path, const unsigned int flags=default_flags, const mode mode=default_mode)
Opens this environment.
Definition: lmdb++.h:1172
static void dbi_drop(MDB_txn *txn, MDB_dbi dbi, bool del)
Definition: lmdb++.h:671
int code() const noexcept
Returns the underlying LMDB error code.
Definition: lmdb++.h:82
static void env_set_mapsize(MDB_env *env, std::size_t size)
Definition: lmdb++.h:432
static void dbi_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx)
Definition: lmdb++.h:727
char * data() noexcept
Returns a pointer to the data;.
Definition: lmdb++.h:1008
Wrapper class for MDB_val structures.
Definition: lmdb++.h:924
val & assign(const char *const data) noexcept
Assigns the value.
Definition: lmdb++.h:1033
static void env_get_max_readers(MDB_env *env, unsigned int *count)
Definition: lmdb++.h:458
Resource class for MDB_cursor* handles.
Definition: lmdb++.h:1652
static void env_get_path(MDB_env *env, const char **path)
Definition: lmdb++.h:406
static void dbi_close(MDB_env *env, MDB_dbi dbi) noexcept
Definition: lmdb++.h:662
MDB_dbi handle() const noexcept
Returns the underlying MDB_dbi handle.
Definition: lmdb++.h:1433
static void cursor_close(MDB_cursor *cursor) noexcept
Definition: lmdb++.h:821
static void env_set_userctx(MDB_env *env, void *ctx)
Definition: lmdb++.h:498
static txn begin(MDB_env *const env, MDB_txn *const parent=nullptr, const unsigned int flags=default_flags)
Creates a new LMDB transaction.
Definition: lmdb++.h:1246
env & set_flags(const unsigned int flags, const bool onoff=true)
Definition: lmdb++.h:1184
~val() noexcept=default
Destructor.
virtual const char * what() const noexcept
Returns the underlying LMDB error code.
Definition: lmdb++.h:96
env(MDB_env *const handle) noexcept
Constructor.
Definition: lmdb++.h:1100
MDB_env * handle() const noexcept
Returns the underlying MDB_env* handle.
Definition: lmdb++.h:1137
txn(txn &&other) noexcept
Move constructor.
Definition: lmdb++.h:1268
dbi(const MDB_dbi handle) noexcept
Constructor.
Definition: lmdb++.h:1394
void renew(MDB_txn *const txn)
Renews this cursor.
Definition: lmdb++.h:1742
static void env_set_max_dbs(MDB_env *env, MDB_dbi count)
Definition: lmdb++.h:471
static void env_close(MDB_env *env) noexcept
Definition: lmdb++.h:370
MDB_cursor * handle() const noexcept
Returns the underlying MDB_cursor* handle.
Definition: lmdb++.h:1719
MDB_txn * txn() const noexcept
Returns the cursor's transaction handle.
Definition: lmdb++.h:1749
static void env_get_flags(MDB_env *env, unsigned int *flags)
Definition: lmdb++.h:393
MDB_dbi dbi() const noexcept
Returns the cursor's database handle.
Definition: lmdb++.h:1756
void close() noexcept
Closes this cursor.
Definition: lmdb++.h:1729
val() noexcept=default
Default constructor.
mdb_mode_t mode
Definition: lmdb++.h:36
static void env_copy(MDB_env *env, const char *path, unsigned int flags)
Definition: lmdb++.h:293
void drop(MDB_txn *const txn, const bool del=false)
Definition: lmdb++.h:1476
static dbi open(MDB_txn *const txn, const char *const name=nullptr, const unsigned int flags=default_flags)
Opens a database handle.
Definition: lmdb++.h:1381
Exception class for MDB_BAD_DBI errors.
Definition: lmdb++.h:194
static void dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Definition: lmdb++.h:620
cursor & operator=(cursor &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1695
bool put(MDB_txn *const txn, const K &key, const unsigned int flags=default_put_flags)
Stores a key into this database.
Definition: lmdb++.h:1560
static bool dbi_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Definition: lmdb++.h:742
txn(MDB_txn *const handle) noexcept
Constructor.
Definition: lmdb++.h:1262
void abort() noexcept
Aborts this transaction.
Definition: lmdb++.h:1329
T * data() noexcept
Returns a pointer to the data;.
Definition: lmdb++.h:993
void sync(const bool force=true)
Flushes data buffers to disk.
Definition: lmdb++.h:1147
const int _code
Definition: lmdb++.h:63
void reset() noexcept
Resets this read-only transaction.
Definition: lmdb++.h:1337
error(const char *const origin, const int rc) noexcept
Constructor.
Definition: lmdb++.h:74
Exception class for MDB_KEYEXIST errors.
Definition: lmdb++.h:133
const char * origin() const noexcept
Returns the origin of the LMDB error.
Definition: lmdb++.h:89
dbi & set_compare(MDB_txn *const txn, MDB_cmp_func *const cmp=nullptr)
Sets a custom key comparison function for this database.
Definition: lmdb++.h:1488
val(const char *const data) noexcept
Constructor.
Definition: lmdb++.h:943
MDB_val _val
Definition: lmdb++.h:926
void close() noexcept
Closes this environment, releasing the memory map.
Definition: lmdb++.h:1157
val & assign(const T *const data, const std::size_t size) noexcept
Assigns the value.
Definition: lmdb++.h:1023
Resource class for MDB_txn* handles.
Definition: lmdb++.h:1231
static MDB_dbi cursor_dbi(MDB_cursor *cursor) noexcept
Definition: lmdb++.h:850
static void raise(const char *origin, int rc)
Throws an error based on the given LMDB return code.
Definition: lmdb++.h:200
bool del(MDB_txn *const txn, const K &key)
Removes a key/value pair from this database.
Definition: lmdb++.h:1632
MDB_env * env() const noexcept
Returns the transaction's MDB_env* handle.
Definition: lmdb++.h:1309
static void dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
Definition: lmdb++.h:649
static bool cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Definition: lmdb++.h:859
static void env_info(MDB_env *env, MDB_envinfo *stat)
Definition: lmdb++.h:345
Resource class for MDB_dbi handles.
Definition: lmdb++.h:1364
txn & operator=(txn &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1275
Resource class for MDB_env* handles.
Definition: lmdb++.h:1063
void renew()
Renews this read-only transaction.
Definition: lmdb++.h:1346
dbi & operator=(dbi &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1407
static MDB_txn * cursor_txn(MDB_cursor *cursor) noexcept
Definition: lmdb++.h:842
~env() noexcept
Destructor.
Definition: lmdb++.h:1123
static void txn_renew(MDB_txn *txn)
Definition: lmdb++.h:587
const char * data() const noexcept
Returns a pointer to the data;.
Definition: lmdb++.h:1015
std::size_t size(MDB_txn *const txn) const
Returns the number of records in this database.
Definition: lmdb++.h:1467
static void cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Definition: lmdb++.h:808
~cursor() noexcept
Destructor.
Definition: lmdb++.h:1705
static unsigned int env_get_max_keysize(MDB_env *env)
Definition: lmdb++.h:483
- C++11 wrapper for LMDB.
Definition: lmdb++.h:35
~dbi() noexcept
Destructor.
Definition: lmdb++.h:1417
env(env &&other) noexcept
Move constructor.
Definition: lmdb++.h:1106
std::size_t size() const noexcept
Returns the size of the data.
Definition: lmdb++.h:985
static bool dbi_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Definition: lmdb++.h:777
static void dbi_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat)
Definition: lmdb++.h:635
static env create(const unsigned int flags=default_flags)
Creates a new LMDB environment.
Definition: lmdb++.h:1077
bool find(const K &key, const MDB_cursor_op op=MDB_SET)
Positions this cursor at the given key.
Definition: lmdb++.h:1840
env & set_max_readers(const unsigned int count)
Definition: lmdb++.h:1203
static void env_set_flags(MDB_env *env, unsigned int flags, bool onoff)
Definition: lmdb++.h:379
bool put(MDB_txn *const txn, const char *const key, const char *const val, const unsigned int flags=default_put_flags)
Stores a key/value pair into this database.
Definition: lmdb++.h:1615
static void txn_commit(MDB_txn *txn)
Definition: lmdb++.h:559
static void env_copy_fd(MDB_env *env, mdb_filehandle_t fd, unsigned int flags)
Definition: lmdb++.h:313
static bool dbi_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags)
Definition: lmdb++.h:759
env & set_mapsize(const std::size_t size)
Definition: lmdb++.h:1194
Exception class for MDB_MAP_FULL errors.
Definition: lmdb++.h:183
static void * env_get_userctx(MDB_env *env)
Definition: lmdb++.h:513
static void cursor_count(MDB_cursor *cursor, std::size_t &count)
Definition: lmdb++.h:903
MDB_txn * handle() const noexcept
Returns the underlying MDB_txn* handle.
Definition: lmdb++.h:1302
static void dbi_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Definition: lmdb++.h:699
~txn() noexcept
Destructor.
Definition: lmdb++.h:1285
Base class for logic error conditions.
Definition: lmdb++.h:107
val & operator=(val &&other) noexcept=default
Move assignment operator.
Exception class for MDB_NOTFOUND errors.
Definition: lmdb++.h:143
Base class for runtime error conditions.
Definition: lmdb++.h:123
env & set_max_dbs(const MDB_dbi count)
Definition: lmdb++.h:1212
static void cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Definition: lmdb++.h:875
static void env_get_fd(MDB_env *env, mdb_filehandle_t *fd)
Definition: lmdb++.h:419
val & assign(const std::string &data) noexcept
Assigns the value.
Definition: lmdb++.h:1040
Exception class for MDB_VERSION_MISMATCH errors.
Definition: lmdb++.h:173
void commit()
Commits this transaction.
Definition: lmdb++.h:1319
static void dbi_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Definition: lmdb++.h:685
static void txn_abort(MDB_txn *txn) noexcept
Definition: lmdb++.h:570