Go to the documentation of this file.
14 #error "<lmdb++.h> requires a C++ compiler"
17 #if __cplusplus < 201103L
18 #if !defined(_MSC_VER) || _MSC_VER < 1900
19 #error "<lmdb++.h> requires a C++11 compiler (CXXFLAGS='-std=c++11')"
20 #endif // _MSC_VER check
35 #include <type_traits>
49 class key_exist_error;
50 class not_found_error;
51 class corrupted_error;
53 class version_mismatch_error;
71 [[noreturn]]
static inline void raise(
const char*
origin,
int rc);
77 const int rc) noexcept
84 int code() const noexcept {
91 const char*
origin() const noexcept {
98 virtual const char*
what() const noexcept {
99 static thread_local
char buffer[1024];
100 std::snprintf(buffer,
sizeof(buffer),
137 using runtime_error::runtime_error;
147 using runtime_error::runtime_error;
157 using fatal_error::fatal_error;
167 using fatal_error::fatal_error;
177 using fatal_error::fatal_error;
187 using runtime_error::runtime_error;
198 using runtime_error::runtime_error;
231 static inline void env_open(MDB_env* env,
232 const char* path,
unsigned int flags,
mode mode);
233 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14)
234 static inline void env_copy(MDB_env* env,
const char* path,
unsigned int flags);
235 static inline void env_copy_fd(MDB_env* env, mdb_filehandle_t fd,
unsigned int flags);
237 static inline void env_copy(MDB_env* env,
const char* path);
238 static inline void env_copy_fd(MDB_env* env, mdb_filehandle_t fd);
240 static inline void env_stat(MDB_env* env, MDB_stat* stat);
241 static inline void env_info(MDB_env* env, MDB_envinfo* stat);
242 static inline void env_sync(MDB_env* env,
bool force);
243 static inline void env_close(MDB_env* env) noexcept;
244 static inline void env_set_flags(MDB_env* env,
unsigned int flags,
bool onoff);
245 static inline void env_get_flags(MDB_env* env,
unsigned int* flags);
246 static inline void env_get_path(MDB_env* env,
const char** path);
247 static inline void env_get_fd(MDB_env* env, mdb_filehandle_t* fd);
253 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11)
268 const int rc = ::mdb_env_create(
env);
269 if (rc != MDB_SUCCESS) {
280 const char*
const path,
281 const unsigned int flags,
283 const int rc = ::mdb_env_open(
env, path, flags,
mode);
284 if (rc != MDB_SUCCESS) {
296 #
if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14)
297 const char*
const path,
298 const unsigned int flags = 0) {
299 const int rc = ::mdb_env_copy2(
env, path, flags);
301 const char*
const path) {
302 const int rc = ::mdb_env_copy(
env, path);
304 if (rc != MDB_SUCCESS) {
316 #
if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 14)
317 const mdb_filehandle_t fd,
318 const unsigned int flags = 0) {
319 const int rc = ::mdb_env_copyfd2(
env, fd, flags);
321 const mdb_filehandle_t fd) {
322 const int rc = ::mdb_env_copyfd(
env, fd);
324 if (rc != MDB_SUCCESS) {
335 MDB_stat*
const stat) {
336 const int rc = ::mdb_env_stat(
env, stat);
337 if (rc != MDB_SUCCESS) {
348 MDB_envinfo*
const stat) {
349 const int rc = ::mdb_env_info(
env, stat);
350 if (rc != MDB_SUCCESS) {
361 const bool force =
true) {
362 const int rc = ::mdb_env_sync(
env, force);
363 if (rc != MDB_SUCCESS) {
373 ::mdb_env_close(
env);
382 const unsigned int flags,
383 const bool onoff =
true) {
384 const int rc = ::mdb_env_set_flags(
env, flags, onoff ? 1 : 0);
385 if (rc != MDB_SUCCESS) {
396 unsigned int*
const flags) {
397 const int rc = ::mdb_env_get_flags(
env, flags);
398 if (rc != MDB_SUCCESS) {
410 const int rc = ::mdb_env_get_path(
env, path);
411 if (rc != MDB_SUCCESS) {
422 mdb_filehandle_t*
const fd) {
423 const int rc = ::mdb_env_get_fd(
env, fd);
424 if (rc != MDB_SUCCESS) {
435 const std::size_t size) {
436 const int rc = ::mdb_env_set_mapsize(
env, size);
437 if (rc != MDB_SUCCESS) {
448 const unsigned int count) {
449 const int rc = ::mdb_env_set_maxreaders(
env, count);
450 if (rc != MDB_SUCCESS) {
461 unsigned int*
const count) {
462 const int rc = ::mdb_env_get_maxreaders(
env, count);
463 if (rc != MDB_SUCCESS) {
474 const MDB_dbi count) {
475 const int rc = ::mdb_env_set_maxdbs(
env, count);
476 if (rc != MDB_SUCCESS) {
484 static inline unsigned int
486 const int rc = ::mdb_env_get_maxkeysize(
env);
490 return static_cast<unsigned int>(rc);
493 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11)
502 const int rc = ::mdb_env_set_userctx(
env, ctx);
503 if (rc != MDB_SUCCESS) {
509 #if MDB_VERSION_FULL >= MDB_VERINT(0, 9, 11)
516 return ::mdb_env_get_userctx(
env);
525 MDB_env* env, MDB_txn* parent,
unsigned int flags, MDB_txn** txn);
526 static inline MDB_env*
txn_env(MDB_txn* txn) noexcept;
528 static inline std::size_t txn_id(MDB_txn* txn) noexcept;
531 static inline void txn_abort(MDB_txn* txn) noexcept;
532 static inline void txn_reset(MDB_txn* txn) noexcept;
533 static inline void txn_renew(MDB_txn* txn);
542 MDB_txn*
const parent,
543 const unsigned int flags,
545 const int rc = ::mdb_txn_begin(
env, parent, flags,
txn);
546 if (rc != MDB_SUCCESS) {
554 static inline MDB_env*
556 return ::mdb_txn_env(
txn);
563 static inline std::size_t
564 lmdb::txn_id(MDB_txn*
const txn) noexcept {
565 return ::mdb_txn_id(txn);
575 const int rc = ::mdb_txn_commit(
txn);
576 if (rc != MDB_SUCCESS) {
586 ::mdb_txn_abort(
txn);
594 ::mdb_txn_reset(
txn);
603 const int rc = ::mdb_txn_renew(
txn);
604 if (rc != MDB_SUCCESS) {
614 MDB_txn* txn,
const char* name,
unsigned int flags, MDB_dbi* dbi);
615 static inline void dbi_stat(MDB_txn* txn, MDB_dbi dbi, MDB_stat* stat);
616 static inline void dbi_flags(MDB_txn* txn, MDB_dbi dbi,
unsigned int* flags);
617 static inline void dbi_close(MDB_env* env, MDB_dbi dbi) noexcept;
618 static inline void dbi_drop(MDB_txn* txn, MDB_dbi dbi,
bool del);
619 static inline void dbi_set_compare(MDB_txn* txn, MDB_dbi dbi, MDB_cmp_func* cmp);
620 static inline void dbi_set_dupsort(MDB_txn* txn, MDB_dbi dbi, MDB_cmp_func* cmp);
621 static inline void dbi_set_relfunc(MDB_txn* txn, MDB_dbi dbi, MDB_rel_func* rel);
622 static inline void dbi_set_relctx(MDB_txn* txn, MDB_dbi dbi,
void* ctx);
623 static inline bool dbi_get(MDB_txn* txn, MDB_dbi dbi,
const MDB_val* key, MDB_val* data);
624 static inline bool dbi_put(MDB_txn* txn, MDB_dbi dbi,
const MDB_val* key, MDB_val* data,
unsigned int flags);
625 static inline bool dbi_del(MDB_txn* txn, MDB_dbi dbi,
const MDB_val* key,
const MDB_val* data);
636 const char*
const name,
637 const unsigned int flags,
638 MDB_dbi*
const dbi) {
639 const int rc = ::mdb_dbi_open(
txn, name, flags,
dbi);
640 if (rc != MDB_SUCCESS) {
652 MDB_stat*
const result) {
653 const int rc = ::mdb_stat(
txn,
dbi, result);
654 if (rc != MDB_SUCCESS) {
666 unsigned int*
const flags) {
667 const int rc = ::mdb_dbi_flags(
txn,
dbi, flags);
668 if (rc != MDB_SUCCESS) {
678 const MDB_dbi
dbi) noexcept {
679 ::mdb_dbi_close(
env,
dbi);
688 const bool del =
false) {
689 const int rc = ::mdb_drop(
txn,
dbi, del ? 1 : 0);
690 if (rc != MDB_SUCCESS) {
702 MDB_cmp_func*
const cmp =
nullptr) {
703 const int rc = ::mdb_set_compare(
txn,
dbi, cmp);
704 if (rc != MDB_SUCCESS) {
716 MDB_cmp_func*
const cmp =
nullptr) {
717 const int rc = ::mdb_set_dupsort(
txn,
dbi, cmp);
718 if (rc != MDB_SUCCESS) {
730 MDB_rel_func*
const rel) {
731 const int rc = ::mdb_set_relfunc(
txn,
dbi, rel);
732 if (rc != MDB_SUCCESS) {
745 const int rc = ::mdb_set_relctx(
txn,
dbi, ctx);
746 if (rc != MDB_SUCCESS) {
759 const MDB_val*
const key,
760 MDB_val*
const data) {
761 const int rc = ::mdb_get(
txn,
dbi,
const_cast<MDB_val*
>(key), data);
762 if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) {
765 return (rc == MDB_SUCCESS);
776 const MDB_val*
const key,
778 const unsigned int flags = 0) {
779 const int rc = ::mdb_put(
txn,
dbi,
const_cast<MDB_val*
>(key), data, flags);
780 if (rc != MDB_SUCCESS && rc != MDB_KEYEXIST) {
783 return (rc == MDB_SUCCESS);
794 const MDB_val*
const key,
795 const MDB_val*
const data =
nullptr) {
796 const int rc = ::mdb_del(
txn,
dbi,
const_cast<MDB_val*
>(key),
const_cast<MDB_val*
>(data));
797 if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) {
800 return (rc == MDB_SUCCESS);
807 static inline void cursor_open(MDB_txn* txn, MDB_dbi dbi, MDB_cursor** cursor);
808 static inline void cursor_close(MDB_cursor* cursor) noexcept;
809 static inline void cursor_renew(MDB_txn* txn, MDB_cursor* cursor);
810 static inline MDB_txn*
cursor_txn(MDB_cursor* cursor) noexcept;
811 static inline MDB_dbi
cursor_dbi(MDB_cursor* cursor) noexcept;
812 static inline bool cursor_get(MDB_cursor* cursor, MDB_val* key, MDB_val* data, MDB_cursor_op op);
813 static inline void cursor_put(MDB_cursor* cursor, MDB_val* key, MDB_val* data,
unsigned int flags);
814 static inline void cursor_del(MDB_cursor* cursor,
unsigned int flags);
815 static inline void cursor_count(MDB_cursor* cursor, std::size_t& count);
825 MDB_cursor**
const cursor) {
827 if (rc != MDB_SUCCESS) {
837 ::mdb_cursor_close(
cursor);
846 MDB_cursor*
const cursor) {
847 const int rc = ::mdb_cursor_renew(
txn,
cursor);
848 if (rc != MDB_SUCCESS) {
856 static inline MDB_txn*
858 return ::mdb_cursor_txn(
cursor);
864 static inline MDB_dbi
866 return ::mdb_cursor_dbi(
cursor);
877 const MDB_cursor_op op) {
878 const int rc = ::mdb_cursor_get(
cursor, key, data, op);
879 if (rc != MDB_SUCCESS && rc != MDB_NOTFOUND) {
882 return (rc == MDB_SUCCESS);
893 const unsigned int flags = 0) {
894 const int rc = ::mdb_cursor_put(
cursor, key, data, flags);
895 if (rc != MDB_SUCCESS) {
906 const unsigned int flags = 0) {
907 const int rc = ::mdb_cursor_del(
cursor, flags);
908 if (rc != MDB_SUCCESS) {
919 std::size_t& count) {
920 const int rc = ::mdb_cursor_count(
cursor, &count);
921 if (rc != MDB_SUCCESS) {
947 val() noexcept = default;
965 const std::size_t
size) noexcept
971 val(
val&& other) noexcept =
default;
981 ~val() noexcept = default;
986 operator MDB_val*() noexcept {
993 operator const MDB_val*()
const noexcept {
1007 std::size_t
size() const noexcept {
1008 return _val.mv_size;
1014 template<
typename T>
1016 return reinterpret_cast<T*
>(
_val.mv_data);
1022 template<
typename T>
1024 return reinterpret_cast<T*
>(
_val.mv_data);
1031 return reinterpret_cast<char*
>(
_val.mv_data);
1037 const char*
data() const noexcept {
1038 return reinterpret_cast<char*
>(
_val.mv_data);
1044 template<
typename T>
1046 const std::size_t
size) noexcept {
1048 _val.mv_data =
const_cast<void*
>(
reinterpret_cast<const void*
>(
data));
1067 #if !(defined(__COVERITY__) || defined(_MSC_VER))
1068 static_assert(std::is_pod<lmdb::val>::value,
"lmdb::val must be a POD type");
1069 static_assert(
sizeof(
lmdb::val) ==
sizeof(MDB_val),
"sizeof(lmdb::val) != sizeof(MDB_val)");
1100 MDB_env*
handle{
nullptr};
1103 assert(
handle !=
nullptr);
1129 std::swap(
_handle, other._handle);
1136 if (
this != &other) {
1137 std::swap(
_handle, other._handle);
1146 try {
close(); }
catch (...) {}
1152 operator MDB_env*()
const noexcept {
1169 void sync(
const bool force =
true) {
1207 const bool onoff =
true) {
1269 MDB_txn*
const parent =
nullptr,
1271 MDB_txn*
handle{
nullptr};
1274 assert(
handle !=
nullptr);
1291 std::swap(
_handle, other._handle);
1298 if (
this != &other) {
1299 std::swap(
_handle, other._handle);
1309 try {
abort(); }
catch (...) {}
1317 operator MDB_txn*()
const noexcept {
1331 MDB_env*
env() const noexcept {
1404 const char*
const name =
nullptr,
1423 std::swap(
_handle, other._handle);
1430 if (
this != &other) {
1431 std::swap(
_handle, other._handle);
1448 operator MDB_dbi() const noexcept {
1478 unsigned int result{};
1499 const bool del =
false) {
1511 MDB_cmp_func*
const cmp =
nullptr) {
1537 template<
typename K>
1539 const K& key)
const {
1553 template<
typename K,
typename V>
1574 template<
typename V>
1576 const char*
const key,
1578 const lmdb::val k{key, std::strlen(key)};
1611 template<
typename K>
1629 template<
typename K,
typename V>
1648 template<
typename V>
1650 const char*
const key,
1653 const lmdb::val k{key, std::strlen(key)};
1668 const char*
const key,
1669 const char*
const val,
1671 const lmdb::val k{key, std::strlen(key)};
1695 template<
typename K>
1732 const MDB_dbi
dbi) {
1736 assert(
handle !=
nullptr);
1753 std::swap(
_handle, other._handle);
1760 if (
this != &other) {
1761 std::swap(
_handle, other._handle);
1770 try {
close(); }
catch (...) {}
1776 operator MDB_cursor*()
const noexcept {
1813 MDB_txn*
txn() const noexcept {
1820 MDB_dbi
dbi() const noexcept {
1832 const MDB_cursor_op op) {
1833 return get(key,
nullptr, op);
1844 const MDB_cursor_op op) {
1845 return get(key,
nullptr, op);
1858 const MDB_cursor_op op) {
1872 const MDB_cursor_op op) {
1886 const MDB_cursor_op op) {
1888 const bool found =
get(k, v, op);
1890 key.assign(k.data(), k.size());
1903 template<
typename K>
1905 const MDB_cursor_op op = MDB_SET) {
1907 return get(k,
nullptr, op);
val & assign(const std::string &data) noexcept
Assigns the value.
Definition: lmdb++.h:1062
virtual const char * what() const noexcept
Returns the underlying LMDB error code.
Definition: lmdb++.h:98
static unsigned int env_get_max_keysize(MDB_env *env)
Definition: lmdb++.h:485
static void env_set_flags(MDB_env *env, unsigned int flags, bool onoff)
Definition: lmdb++.h:381
~txn() noexcept
Destructor.
Definition: lmdb++.h:1307
env(MDB_env *const handle) noexcept
Constructor.
Definition: lmdb++.h:1122
bool del(MDB_txn *const txn, const val &key)
Removes a key/value pair from this database.
Definition: lmdb++.h:1683
Exception class for MDB_NOTFOUND errors.
Definition: lmdb++.h:145
static void dbi_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel)
Definition: lmdb++.h:728
env & operator=(env &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1135
static void cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Definition: lmdb++.h:823
bool get(lmdb::val &key, const MDB_cursor_op op)
Retrieves a key from the database.
Definition: lmdb++.h:1843
MDB_cursor * _handle
Definition: lmdb++.h:1718
MDB_txn * txn() const noexcept
Returns the cursor's transaction handle.
Definition: lmdb++.h:1813
static constexpr unsigned int default_put_flags
Definition: lmdb++.h:1392
const char * origin() const noexcept
Returns the origin of the LMDB error.
Definition: lmdb++.h:91
cursor & operator=(cursor &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1759
static constexpr unsigned int default_flags
Definition: lmdb++.h:1721
static void env_sync(MDB_env *env, bool force)
Definition: lmdb++.h:360
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:1612
static void env_info(MDB_env *env, MDB_envinfo *stat)
Definition: lmdb++.h:347
std::size_t size(MDB_txn *const txn) const
Returns the number of records in this database.
Definition: lmdb++.h:1489
bool get(MDB_txn *const txn, const K &key) const
Retrieves a key from this database.
Definition: lmdb++.h:1538
bool get(MDB_txn *const txn, const val &key, val &data)
Retrieves a key/value pair from this database.
Definition: lmdb++.h:1524
mdb_mode_t mode
Definition: lmdb++.h:38
MDB_cursor * handle() const noexcept
Returns the underlying MDB_cursor* handle.
Definition: lmdb++.h:1783
static void txn_renew(MDB_txn *txn)
Definition: lmdb++.h:602
void sync(const bool force=true)
Flushes data buffers to disk.
Definition: lmdb++.h:1169
static void env_get_fd(MDB_env *env, mdb_filehandle_t *fd)
Definition: lmdb++.h:421
static constexpr unsigned int default_flags
Definition: lmdb++.h:1090
MDB_env * _handle
Definition: lmdb++.h:1087
static void cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Definition: lmdb++.h:845
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:1403
MDB_env * env() const noexcept
Returns the transaction's MDB_env* handle.
Definition: lmdb++.h:1331
val(const void *const data, const std::size_t size) noexcept
Constructor.
Definition: lmdb++.h:964
unsigned int flags(MDB_txn *const txn) const
Retrieves the flags for this database handle.
Definition: lmdb++.h:1477
T * data() noexcept
Returns a pointer to the data.
Definition: lmdb++.h:1015
txn & operator=(txn &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1297
val & assign(const char *const data) noexcept
Assigns the value.
Definition: lmdb++.h:1055
static void env_set_userctx(MDB_env *env, void *ctx)
Definition: lmdb++.h:500
~cursor() noexcept
Destructor.
Definition: lmdb++.h:1769
static constexpr unsigned int default_flags
Definition: lmdb++.h:1391
MDB_env * handle() const noexcept
Returns the underlying MDB_env* handle.
Definition: lmdb++.h:1159
bool put(MDB_txn *const txn, const val &key, val &data, const unsigned int flags=default_put_flags)
Stores a key/value pair into this database.
Definition: lmdb++.h:1596
txn(txn &&other) noexcept
Move constructor.
Definition: lmdb++.h:1290
bool get(MDB_val *const key, const MDB_cursor_op op)
Retrieves a key from the database.
Definition: lmdb++.h:1831
static void txn_commit(MDB_txn *txn)
Definition: lmdb++.h:574
static cursor open(MDB_txn *const txn, const MDB_dbi dbi)
Creates an LMDB cursor.
Definition: lmdb++.h:1731
MDB_txn * handle() const noexcept
Returns the underlying MDB_txn* handle.
Definition: lmdb++.h:1324
static MDB_dbi cursor_dbi(MDB_cursor *cursor) noexcept
Definition: lmdb++.h:865
static void env_copy(MDB_env *env, const char *path, unsigned int flags)
Definition: lmdb++.h:295
bool get(std::string &key, std::string &val, const MDB_cursor_op op)
Retrieves a key/value pair from the database.
Definition: lmdb++.h:1884
static void txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Definition: lmdb++.h:541
static void env_get_flags(MDB_env *env, unsigned int *flags)
Definition: lmdb++.h:395
cursor(MDB_cursor *const handle) noexcept
Constructor.
Definition: lmdb++.h:1746
env & set_mapsize(const std::size_t size)
Definition: lmdb++.h:1216
static void env_get_path(MDB_env *env, const char **path)
Definition: lmdb++.h:408
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:1510
static void * env_get_userctx(MDB_env *env)
Definition: lmdb++.h:515
cursor(cursor &&other) noexcept
Move constructor.
Definition: lmdb++.h:1752
static void cursor_count(MDB_cursor *cursor, std::size_t &count)
Definition: lmdb++.h:918
Wrapper class for MDB_val structures.
Definition: lmdb++.h:939
static env create(const unsigned int flags=default_flags)
Creates a new LMDB environment.
Definition: lmdb++.h:1099
Exception class for MDB_BAD_DBI errors.
Definition: lmdb++.h:196
static bool cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Definition: lmdb++.h:874
static void dbi_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx)
Definition: lmdb++.h:742
bool empty() const noexcept
Determines whether this value is empty.
Definition: lmdb++.h:1000
env & open(const char *const path, const unsigned int flags=default_flags, const mode mode=default_mode)
Opens this environment.
Definition: lmdb++.h:1194
Resource class for MDB_dbi handles.
Definition: lmdb++.h:1386
bool find(const K &key, const MDB_cursor_op op=MDB_SET)
Positions this cursor at the given key.
Definition: lmdb++.h:1904
~env() noexcept
Destructor.
Definition: lmdb++.h:1145
txn(MDB_txn *const handle) noexcept
Constructor.
Definition: lmdb++.h:1284
env & set_flags(const unsigned int flags, const bool onoff=true)
Definition: lmdb++.h:1206
static void env_copy_fd(MDB_env *env, mdb_filehandle_t fd, unsigned int flags)
Definition: lmdb++.h:315
bool del(MDB_txn *const txn, const K &key)
Removes a key/value pair from this database.
Definition: lmdb++.h:1696
static void env_close(MDB_env *env) noexcept
Definition: lmdb++.h:372
static void env_set_max_readers(MDB_env *env, unsigned int count)
Definition: lmdb++.h:447
val() noexcept=default
Default constructor.
static bool dbi_put(MDB_txn *txn, MDB_dbi dbi, const MDB_val *key, MDB_val *data, unsigned int flags)
Definition: lmdb++.h:774
Base class for fatal error conditions.
Definition: lmdb++.h:117
MDB_dbi handle() const noexcept
Returns the underlying MDB_dbi handle.
Definition: lmdb++.h:1455
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:1667
bool get(MDB_txn *const txn, const char *const key, V &val) const
Retrieves a key/value pair from this database.
Definition: lmdb++.h:1575
Exception class for MDB_CORRUPTED errors.
Definition: lmdb++.h:155
static void dbi_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat)
Definition: lmdb++.h:650
int code() const noexcept
Returns the underlying LMDB error code.
Definition: lmdb++.h:84
env & set_max_dbs(const MDB_dbi count)
Definition: lmdb++.h:1234
Exception class for MDB_VERSION_MISMATCH errors.
Definition: lmdb++.h:175
dbi(const MDB_dbi handle) noexcept
Constructor.
Definition: lmdb++.h:1416
std::size_t size() const noexcept
Returns the size of the data.
Definition: lmdb++.h:1007
void abort() noexcept
Aborts this transaction.
Definition: lmdb++.h:1351
Exception class for MDB_MAP_FULL errors.
Definition: lmdb++.h:185
static void env_stat(MDB_env *env, MDB_stat *stat)
Definition: lmdb++.h:334
static void raise(const char *origin, int rc)
Throws an error based on the given LMDB return code.
Definition: lmdb++.h:202
val(const char *const data) noexcept
Constructor.
Definition: lmdb++.h:958
val & assign(const T *const data, const std::size_t size) noexcept
Assigns the value.
Definition: lmdb++.h:1045
MDB_val _val
Definition: lmdb++.h:941
void close() noexcept
Closes this environment, releasing the memory map.
Definition: lmdb++.h:1179
static void env_set_max_dbs(MDB_env *env, MDB_dbi count)
Definition: lmdb++.h:473
static void cursor_close(MDB_cursor *cursor) noexcept
Definition: lmdb++.h:836
val & operator=(val &&other) noexcept=default
Move assignment operator.
static MDB_txn * cursor_txn(MDB_cursor *cursor) noexcept
Definition: lmdb++.h:857
Base class for runtime error conditions.
Definition: lmdb++.h:125
static void dbi_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Definition: lmdb++.h:714
static void env_get_max_readers(MDB_env *env, unsigned int *count)
Definition: lmdb++.h:460
Exception class for MDB_KEYEXIST errors.
Definition: lmdb++.h:135
void commit()
Commits this transaction.
Definition: lmdb++.h:1341
Base class for logic error conditions.
Definition: lmdb++.h:109
static void txn_reset(MDB_txn *txn) noexcept
Definition: lmdb++.h:593
MDB_dbi dbi() const noexcept
Returns the cursor's database handle.
Definition: lmdb++.h:1820
static void dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
Definition: lmdb++.h:664
Exception class for MDB_PANIC errors.
Definition: lmdb++.h:165
char * data() noexcept
Returns a pointer to the data.
Definition: lmdb++.h:1030
bool get(lmdb::val &key, lmdb::val &val, const MDB_cursor_op op)
Retrieves a key/value pair from the database.
Definition: lmdb++.h:1870
static void cursor_del(MDB_cursor *cursor, unsigned int flags)
Definition: lmdb++.h:905
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:1268
Resource class for MDB_txn* handles.
Definition: lmdb++.h:1253
Resource class for MDB_cursor* handles.
Definition: lmdb++.h:1716
static bool dbi_del(MDB_txn *txn, MDB_dbi dbi, const MDB_val *key, const MDB_val *data)
Definition: lmdb++.h:792
static void env_open(MDB_env *env, const char *path, unsigned int flags, mode mode)
Definition: lmdb++.h:279
bool get(MDB_val *const key, MDB_val *const val, const MDB_cursor_op op)
Retrieves a key/value pair from the database.
Definition: lmdb++.h:1856
env & set_max_readers(const unsigned int count)
Definition: lmdb++.h:1225
void reset() noexcept
Resets this read-only transaction.
Definition: lmdb++.h:1359
const T * data() const noexcept
Returns a pointer to the data.
Definition: lmdb++.h:1023
void close() noexcept
Closes this cursor.
Definition: lmdb++.h:1793
~dbi() noexcept
Destructor.
Definition: lmdb++.h:1439
void drop(MDB_txn *const txn, const bool del=false)
Definition: lmdb++.h:1498
MDB_dbi _handle
Definition: lmdb++.h:1388
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:1630
void renew(MDB_txn *const txn)
Renews this cursor.
Definition: lmdb++.h:1806
Resource class for MDB_env* handles.
Definition: lmdb++.h:1085
bool get(MDB_txn *const txn, const K &key, V &val) const
Retrieves a key/value pair from this database.
Definition: lmdb++.h:1554
static void dbi_close(MDB_env *env, MDB_dbi dbi) noexcept
Definition: lmdb++.h:677
static constexpr unsigned int default_flags
Definition: lmdb++.h:1258
const int _code
Definition: lmdb++.h:65
static MDB_env * txn_env(MDB_txn *txn) noexcept
Definition: lmdb++.h:555
static bool dbi_get(MDB_txn *txn, MDB_dbi dbi, const MDB_val *key, MDB_val *data)
Definition: lmdb++.h:757
static void env_set_mapsize(MDB_env *env, std::size_t size)
Definition: lmdb++.h:434
static void cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Definition: lmdb++.h:890
dbi(dbi &&other) noexcept
Move constructor.
Definition: lmdb++.h:1422
MDB_txn * _handle
Definition: lmdb++.h:1255
void renew()
Renews this read-only transaction.
Definition: lmdb++.h:1368
~val() noexcept=default
Destructor.
error(const char *const origin, const int rc) noexcept
Constructor.
Definition: lmdb++.h:76
Base class for LMDB exception conditions.
Definition: lmdb++.h:63
static constexpr mode default_mode
Definition: lmdb++.h:1091
static void dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Definition: lmdb++.h:635
static void dbi_drop(MDB_txn *txn, MDB_dbi dbi, bool del)
Definition: lmdb++.h:686
static void txn_abort(MDB_txn *txn) noexcept
Definition: lmdb++.h:585
<lmdb++.h> - C++11 wrapper for LMDB.
Definition: lmdb++.h:37
static void env_create(MDB_env **env)
Definition: lmdb++.h:267
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:1649
static void dbi_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Definition: lmdb++.h:700
const char * data() const noexcept
Returns a pointer to the data.
Definition: lmdb++.h:1037
MDB_stat stat(MDB_txn *const txn) const
Returns statistics for this database.
Definition: lmdb++.h:1465
dbi & operator=(dbi &&other) noexcept
Move assignment operator.
Definition: lmdb++.h:1429
env(env &&other) noexcept
Move constructor.
Definition: lmdb++.h:1128