mdbx++: добавление перегрузок put/insert/upsert для mdbx::pair.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2024-06-09 14:42:41 +03:00
parent 74ff4dba0a
commit 25efb58790

View File

@ -4552,6 +4552,19 @@ public:
inline value_result try_update_reserve(map_handle map, const slice &key, inline value_result try_update_reserve(map_handle map, const slice &key,
size_t value_length); size_t value_length);
void put(map_handle map, const pair &kv, put_mode mode) {
return put(map, kv.key, kv.value, mode);
}
void insert(map_handle map, const pair &kv) {
return insert(map, kv.key, kv.value);
}
value_result try_insert(map_handle map, const pair &kv) {
return try_insert(map, kv.key, kv.value);
}
void upsert(map_handle map, const pair &kv) {
return upsert(map, kv.key, kv.value);
}
/// \brief Removes all values for given key. /// \brief Removes all values for given key.
inline bool erase(map_handle map, const slice &key); inline bool erase(map_handle map, const slice &key);
@ -4600,6 +4613,10 @@ public:
/// to pages of nested b+tree of multimap's values. /// to pages of nested b+tree of multimap's values.
inline void append(map_handle map, const slice &key, const slice &value, inline void append(map_handle map, const slice &key, const slice &value,
bool multivalue_order_preserved = true); bool multivalue_order_preserved = true);
inline void append(map_handle map, const pair &kv,
bool multivalue_order_preserved = true) {
return append(map, kv.key, kv.value, multivalue_order_preserved);
}
size_t put_multiple(map_handle map, const slice &key, size_t put_multiple(map_handle map, const slice &key,
const size_t value_length, const void *values_array, const size_t value_length, const void *values_array,
@ -5096,6 +5113,7 @@ public:
inline MDBX_error_t put(const slice &key, slice *value, inline MDBX_error_t put(const slice &key, slice *value,
MDBX_put_flags_t flags) noexcept; MDBX_put_flags_t flags) noexcept;
inline void put(const slice &key, slice value, put_mode mode);
inline void insert(const slice &key, slice value); inline void insert(const slice &key, slice value);
inline value_result try_insert(const slice &key, slice value); inline value_result try_insert(const slice &key, slice value);
inline slice insert_reserve(const slice &key, size_t value_length); inline slice insert_reserve(const slice &key, size_t value_length);
@ -5109,6 +5127,15 @@ public:
inline slice update_reserve(const slice &key, size_t value_length); inline slice update_reserve(const slice &key, size_t value_length);
inline value_result try_update_reserve(const slice &key, size_t value_length); inline value_result try_update_reserve(const slice &key, size_t value_length);
void put(const pair &kv, put_mode mode) {
return put(kv.key, kv.value, mode);
}
void insert(const pair &kv) { return insert(kv.key, kv.value); }
value_result try_insert(const pair &kv) {
return try_insert(kv.key, kv.value);
}
void upsert(const pair &kv) { return upsert(kv.key, kv.value); }
/// \brief Removes single key-value pair or all multi-values at the current /// \brief Removes single key-value pair or all multi-values at the current
/// cursor position. /// cursor position.
inline bool erase(bool whole_multivalue = false); inline bool erase(bool whole_multivalue = false);
@ -7137,6 +7164,10 @@ inline MDBX_error_t cursor::put(const slice &key, slice *value,
return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags)); return MDBX_error_t(::mdbx_cursor_put(handle_, &key, value, flags));
} }
inline void cursor::put(const slice &key, slice value, put_mode mode) {
error::success_or_throw(put(key, &value, MDBX_put_flags_t(mode)));
}
inline void cursor::insert(const slice &key, slice value) { inline void cursor::insert(const slice &key, slice value) {
error::success_or_throw( error::success_or_throw(
put(key, &value /* takes the present value in case MDBX_KEYEXIST */, put(key, &value /* takes the present value in case MDBX_KEYEXIST */,