PMEMKV  1.0.3-git1.g023abb3
This is the C++ documentation for PMEMKV.
libpmemkv.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2020, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef LIBPMEMKV_HPP
34 #define LIBPMEMKV_HPP
35 
36 #include <functional>
37 #include <stdexcept>
38 #include <string>
39 #include <utility>
40 
41 #if __cpp_lib_string_view
42 #include <string_view>
43 #endif
44 
45 #include "libpmemkv.h"
46 
60 namespace pmem
61 {
68 namespace kv
69 {
70 
71 #if __cpp_lib_string_view
72 using string_view = std::string_view;
73 #else
74 
80 class string_view {
81 public:
82  string_view() noexcept;
83  string_view(const char *data, size_t size);
84  string_view(const std::string &s);
85  string_view(const char *data);
86 
87  string_view(const string_view &rhs) noexcept = default;
88  string_view &operator=(const string_view &rhs) noexcept = default;
89 
90  const char *data() const noexcept;
91  std::size_t size() const noexcept;
92 
93  int compare(const string_view &other) noexcept;
94 
95 private:
96  const char *_data;
97  std::size_t _size;
98 };
99 #endif
100 
107 typedef int get_kv_function(string_view key, string_view value);
114 typedef void get_v_function(string_view value);
115 
119 using get_kv_callback = pmemkv_get_kv_callback;
123 using get_v_callback = pmemkv_get_v_callback;
124 
131 enum class status {
132  OK = PMEMKV_STATUS_OK,
133  UNKNOWN_ERROR = PMEMKV_STATUS_UNKNOWN_ERROR,
134  NOT_FOUND = PMEMKV_STATUS_NOT_FOUND,
135  NOT_SUPPORTED = PMEMKV_STATUS_NOT_SUPPORTED,
137  INVALID_ARGUMENT = PMEMKV_STATUS_INVALID_ARGUMENT,
140  PMEMKV_STATUS_CONFIG_PARSING_ERROR,
142  PMEMKV_STATUS_CONFIG_TYPE_ERROR,
144  STOPPED_BY_CB = PMEMKV_STATUS_STOPPED_BY_CB,
146  OUT_OF_MEMORY =
147  PMEMKV_STATUS_OUT_OF_MEMORY,
150  PMEMKV_STATUS_WRONG_ENGINE_NAME,
153  PMEMKV_STATUS_TRANSACTION_SCOPE_ERROR,
155 };
156 
176 class config {
177 public:
178  config() noexcept;
179  explicit config(pmemkv_config *cfg) noexcept;
180 
181  ~config();
182 
183  config(const config &other) = delete;
184  config(config &&other) noexcept;
185 
186  config &operator=(const config &other) = delete;
187  config &operator=(config &&other) noexcept;
188 
189  template <typename T>
190  status put_data(const std::string &key, const T *value,
191  const std::size_t number = 1) noexcept;
192  template <typename T>
194  const std::string &key, T *value,
195  void (*deleter)(void *) = [](T *value) { delete value; }) noexcept;
196  status put_uint64(const std::string &key, std::uint64_t value) noexcept;
197  status put_int64(const std::string &key, std::int64_t value) noexcept;
198  status put_string(const std::string &key, const std::string &value) noexcept;
199 
200  template <typename T>
201  status get_data(const std::string &key, T *&value, std::size_t &number) const
202  noexcept;
203  template <typename T>
204  status get_object(const std::string &key, T *&value) const noexcept;
205 
206  status get_uint64(const std::string &key, std::uint64_t &value) const noexcept;
207  status get_int64(const std::string &key, std::int64_t &value) const noexcept;
208  status get_string(const std::string &key, std::string &value) const noexcept;
209 
210  pmemkv_config *release() noexcept;
211 
212 private:
213  int init() noexcept;
214 
215  pmemkv_config *_config;
216 };
217 
230 class db {
231 public:
232  db() noexcept;
233  ~db();
234 
235  db(const db &other) = delete;
236  db(db &&other) noexcept;
237 
238  db &operator=(const db &other) = delete;
239  db &operator=(db &&other) noexcept;
240 
241  status open(const std::string &engine_name) noexcept;
242  status open(const std::string &engine_name, config &&cfg) noexcept;
243 
244  void close() noexcept;
245 
246  status count_all(std::size_t &cnt) noexcept;
247  status count_above(string_view key, std::size_t &cnt) noexcept;
248  status count_below(string_view key, std::size_t &cnt) noexcept;
250  std::size_t &cnt) noexcept;
251 
252  status get_all(get_kv_callback *callback, void *arg) noexcept;
253  status get_all(std::function<get_kv_function> f) noexcept;
254 
255  status get_above(string_view key, get_kv_callback *callback, void *arg) noexcept;
256  status get_above(string_view key, std::function<get_kv_function> f) noexcept;
257 
258  status get_below(string_view key, get_kv_callback *callback, void *arg) noexcept;
259  status get_below(string_view key, std::function<get_kv_function> f) noexcept;
260 
262  void *arg) noexcept;
264  std::function<get_kv_function> f) noexcept;
265 
266  status exists(string_view key) noexcept;
267 
268  status get(string_view key, get_v_callback *callback, void *arg) noexcept;
269  status get(string_view key, std::function<get_v_function> f) noexcept;
270  status get(string_view key, std::string *value) noexcept;
271 
272  status put(string_view key, string_view value) noexcept;
273  status remove(string_view key) noexcept;
274 
275  std::string errormsg();
276 
277 private:
278  pmemkv_db *_db;
279 };
280 
284 inline config::config() noexcept
285 {
286  this->_config = nullptr;
287 }
288 
293 inline config::config(config &&other) noexcept
294 {
295  this->_config = other._config;
296  other._config = nullptr;
297 }
298 
303 inline config &config::operator=(config &&other) noexcept
304 {
305  if (this == &other)
306  return *this;
307 
308  if (this->_config)
309  pmemkv_config_delete(this->_config);
310 
311  this->_config = other._config;
312  other._config = nullptr;
313 
314  return *this;
315 }
316 
321 inline config::config(pmemkv_config *cfg) noexcept
322 {
323  this->_config = cfg;
324 }
325 
330 {
331  if (this->_config)
332  pmemkv_config_delete(this->_config);
333 }
334 
341 inline int config::init() noexcept
342 {
343  if (this->_config == nullptr) {
344  this->_config = pmemkv_config_new();
345 
346  if (this->_config == nullptr)
347  return 1;
348  }
349 
350  return 0;
351 }
352 
363 template <typename T>
364 inline status config::put_data(const std::string &key, const T *value,
365  const std::size_t count) noexcept
366 {
367  if (init() != 0)
368  return status::UNKNOWN_ERROR;
369 
370  return static_cast<status>(pmemkv_config_put_data(
371  this->_config, key.data(), (void *)value, count * sizeof(T)));
372 }
373 
384 template <typename T>
385 inline status config::put_object(const std::string &key, T *value,
386  void (*deleter)(void *)) noexcept
387 {
388  if (init() != 0)
389  return status::UNKNOWN_ERROR;
390 
391  return static_cast<status>(pmemkv_config_put_object(this->_config, key.data(),
392  (void *)value, deleter));
393 }
394 
403 inline status config::put_uint64(const std::string &key, std::uint64_t value) noexcept
404 {
405  if (init() != 0)
406  return status::UNKNOWN_ERROR;
407 
408  return static_cast<status>(
409  pmemkv_config_put_uint64(this->_config, key.data(), value));
410 }
411 
420 inline status config::put_int64(const std::string &key, std::int64_t value) noexcept
421 {
422  if (init() != 0)
423  return status::UNKNOWN_ERROR;
424 
425  return static_cast<status>(
426  pmemkv_config_put_int64(this->_config, key.data(), value));
427 }
428 
437 inline status config::put_string(const std::string &key,
438  const std::string &value) noexcept
439 {
440  if (init() != 0)
441  return status::UNKNOWN_ERROR;
442 
443  return static_cast<status>(
444  pmemkv_config_put_string(this->_config, key.data(), value.data()));
445 }
446 
457 template <typename T>
458 inline status config::get_data(const std::string &key, T *&value,
459  std::size_t &count) const noexcept
460 {
461  if (this->_config == nullptr)
462  return status::NOT_FOUND;
463 
464  std::size_t size;
465  auto s = static_cast<status>(pmemkv_config_get_data(
466  this->_config, key.data(), (const void **)&value, &size));
467 
468  if (s != status::OK)
469  return s;
470 
471  count = size / sizeof(T);
472 
473  return status::OK;
474 }
475 
485 template <typename T>
486 inline status config::get_object(const std::string &key, T *&value) const noexcept
487 {
488  if (this->_config == nullptr)
489  return status::NOT_FOUND;
490 
491  auto s = static_cast<status>(
492  pmemkv_config_get_object(this->_config, key.data(), (void **)&value));
493 
494  return s;
495 }
496 
505 inline status config::get_uint64(const std::string &key, std::uint64_t &value) const
506  noexcept
507 {
508  if (this->_config == nullptr)
509  return status::NOT_FOUND;
510 
511  return static_cast<status>(
512  pmemkv_config_get_uint64(this->_config, key.data(), &value));
513 }
514 
523 inline status config::get_int64(const std::string &key, std::int64_t &value) const
524  noexcept
525 {
526  if (this->_config == nullptr)
527  return status::NOT_FOUND;
528 
529  return static_cast<status>(
530  pmemkv_config_get_int64(this->_config, key.data(), &value));
531 }
532 
541 inline status config::get_string(const std::string &key, std::string &value) const
542  noexcept
543 {
544  if (this->_config == nullptr)
545  return status::NOT_FOUND;
546 
547  const char *data;
548 
549  auto s = static_cast<status>(
550  pmemkv_config_get_string(this->_config, key.data(), &data));
551 
552  if (s != status::OK)
553  return s;
554 
555  value = data;
556 
557  return status::OK;
558 }
559 
566 inline pmemkv_config *config::release() noexcept
567 {
568  auto c = this->_config;
569  this->_config = nullptr;
570  return c;
571 }
572 
573 #if !__cpp_lib_string_view
574 
577 inline string_view::string_view() noexcept : _data(""), _size(0)
578 {
579 }
580 
588 inline string_view::string_view(const char *data, size_t size) : _data(data), _size(size)
589 {
590 }
591 
597 inline string_view::string_view(const std::string &s) : _data(s.c_str()), _size(s.size())
598 {
599 }
600 
608 inline string_view::string_view(const char *data)
609  : _data(data), _size(std::char_traits<char>::length(data))
610 {
611 }
612 
619 inline const char *string_view::data() const noexcept
620 {
621  return _data;
622 }
623 
629 inline std::size_t string_view::size() const noexcept
630 {
631  return _size;
632 }
633 
642 inline int string_view::compare(const string_view &other) noexcept
643 {
644  int ret = std::char_traits<char>::compare(data(), other.data(),
645  std::min(size(), other.size()));
646  if (ret != 0)
647  return ret;
648  if (size() < other.size())
649  return -1;
650  if (size() > other.size())
651  return 1;
652  return 0;
653 }
654 #endif
655 
656 /*
657  * All functions which will be called by C code must be declared as extern "C"
658  * to ensure they have C linkage. It is needed because it is possible that
659  * C and C++ functions use different calling conventions.
660  */
661 extern "C" {
662 static inline int call_get_kv_function(const char *key, size_t keybytes,
663  const char *value, size_t valuebytes, void *arg)
664 {
665  return (*reinterpret_cast<std::function<get_kv_function> *>(arg))(
666  string_view(key, keybytes), string_view(value, valuebytes));
667 }
668 
669 static inline void call_get_v_function(const char *value, size_t valuebytes, void *arg)
670 {
671  (*reinterpret_cast<std::function<get_v_function> *>(arg))(
672  string_view(value, valuebytes));
673 }
674 
675 static inline void call_get_copy(const char *v, size_t vb, void *arg)
676 {
677  auto c = reinterpret_cast<std::string *>(arg);
678  c->assign(v, vb);
679 }
680 }
681 
685 inline db::db() noexcept
686 {
687  this->_db = nullptr;
688 }
689 
696 inline db::db(db &&other) noexcept
697 {
698  this->_db = other._db;
699  other._db = nullptr;
700 }
701 
709 inline db &db::operator=(db &&other) noexcept
710 {
711  if (this == &other)
712  return *this;
713 
714  close();
715 
716  std::swap(this->_db, other._db);
717 
718  return *this;
719 }
720 
728 inline status db::open(const std::string &engine_name) noexcept
729 {
730  return static_cast<status>(
731  pmemkv_open(engine_name.c_str(), nullptr, &(this->_db)));
732 }
733 
742 inline status db::open(const std::string &engine_name, config &&cfg) noexcept
743 {
744  return static_cast<status>(
745  pmemkv_open(engine_name.c_str(), cfg.release(), &(this->_db)));
746 }
747 
751 inline void db::close() noexcept
752 {
753  if (this->_db != nullptr)
754  pmemkv_close(this->_db);
755 
756  this->_db = nullptr;
757 }
758 
762 inline db::~db()
763 {
764  close();
765 }
766 
774 inline status db::count_all(std::size_t &cnt) noexcept
775 {
776  return static_cast<status>(pmemkv_count_all(this->_db, &cnt));
777 }
778 
789 inline status db::count_above(string_view key, std::size_t &cnt) noexcept
790 {
791  return static_cast<status>(
792  pmemkv_count_above(this->_db, key.data(), key.size(), &cnt));
793 }
794 
805 inline status db::count_below(string_view key, std::size_t &cnt) noexcept
806 {
807  return static_cast<status>(
808  pmemkv_count_below(this->_db, key.data(), key.size(), &cnt));
809 }
810 
823  std::size_t &cnt) noexcept
824 {
825  return static_cast<status>(pmemkv_count_between(
826  this->_db, key1.data(), key1.size(), key2.data(), key2.size(), &cnt));
827 }
828 
841 inline status db::get_all(get_kv_callback *callback, void *arg) noexcept
842 {
843  return static_cast<status>(pmemkv_get_all(this->_db, callback, arg));
844 }
845 
856 inline status db::get_all(std::function<get_kv_function> f) noexcept
857 {
858  return static_cast<status>(pmemkv_get_all(this->_db, call_get_kv_function, &f));
859 }
860 
878  void *arg) noexcept
879 {
880  return static_cast<status>(
881  pmemkv_get_above(this->_db, key.data(), key.size(), callback, arg));
882 }
883 
898 inline status db::get_above(string_view key, std::function<get_kv_function> f) noexcept
899 {
900  return static_cast<status>(pmemkv_get_above(this->_db, key.data(), key.size(),
901  call_get_kv_function, &f));
902 }
903 
921  void *arg) noexcept
922 {
923  return static_cast<status>(
924  pmemkv_get_below(this->_db, key.data(), key.size(), callback, arg));
925 }
926 
941 inline status db::get_below(string_view key, std::function<get_kv_function> f) noexcept
942 {
943  return static_cast<status>(pmemkv_get_below(this->_db, key.data(), key.size(),
944  call_get_kv_function, &f));
945 }
946 
965  get_kv_callback *callback, void *arg) noexcept
966 {
967  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
968  key2.data(), key2.size(), callback,
969  arg));
970 }
987  std::function<get_kv_function> f) noexcept
988 {
989  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
990  key2.data(), key2.size(),
991  call_get_kv_function, &f));
992 }
993 
1003 inline status db::exists(string_view key) noexcept
1004 {
1005  return static_cast<status>(pmemkv_exists(this->_db, key.data(), key.size()));
1006 }
1007 
1023 inline status db::get(string_view key, get_v_callback *callback, void *arg) noexcept
1024 {
1025  return static_cast<status>(
1026  pmemkv_get(this->_db, key.data(), key.size(), callback, arg));
1027 }
1028 
1040 inline status db::get(string_view key, std::function<get_v_function> f) noexcept
1041 {
1042  return static_cast<status>(
1043  pmemkv_get(this->_db, key.data(), key.size(), call_get_v_function, &f));
1044 }
1045 
1056 inline status db::get(string_view key, std::string *value) noexcept
1057 {
1058  return static_cast<status>(
1059  pmemkv_get(this->_db, key.data(), key.size(), call_get_copy, value));
1060 }
1061 
1071 inline status db::put(string_view key, string_view value) noexcept
1072 {
1073  return static_cast<status>(pmemkv_put(this->_db, key.data(), key.size(),
1074  value.data(), value.size()));
1075 }
1076 
1085 inline status db::remove(string_view key) noexcept
1086 {
1087  return static_cast<status>(pmemkv_remove(this->_db, key.data(), key.size()));
1088 }
1089 
1097 inline std::string db::errormsg()
1098 {
1099  return std::string(pmemkv_errormsg());
1100 }
1101 
1107 static inline std::string errormsg()
1108 {
1109  return std::string(pmemkv_errormsg());
1110 }
1111 
1112 } /* namespace kv */
1113 } /* namespace pmem */
1114 
1115 #endif /* LIBPMEMKV_HPP */
pmem::kv::config::put_string
status put_string(const std::string &key, const std::string &value) noexcept
Puts string value to a config.
Definition: libpmemkv.hpp:437
pmem::kv::config::get_string
status get_string(const std::string &key, std::string &value) const noexcept
Gets string value from a config item with key name.
Definition: libpmemkv.hpp:541
pmem::kv::string_view::size
std::size_t size() const noexcept
Returns count of characters stored in this pmem::kv::string_view data.
Definition: libpmemkv.hpp:629
pmem::kv::db::db
db() noexcept
Default constructor with uninitialized database.
Definition: libpmemkv.hpp:685
pmem::kv::db::~db
~db()
Default destructor.
Definition: libpmemkv.hpp:762
pmem::kv::config
Holds configuration parameters for engines.
Definition: libpmemkv.hpp:176
pmem
Persistent memory namespace.
pmem::kv::status::INVALID_ARGUMENT
@ INVALID_ARGUMENT
argument to function has wrong value
pmem::kv::status::CONFIG_TYPE_ERROR
@ CONFIG_TYPE_ERROR
config item has different type than expected
pmem::kv::status::OK
@ OK
no error
pmem::kv::db::get
status get(string_view key, get_v_callback *callback, void *arg) noexcept
Executes (C-like) callback function for record with given key.
Definition: libpmemkv.hpp:1023
pmem::kv::db::close
void close() noexcept
Closes pmemkv database.
Definition: libpmemkv.hpp:751
pmem::kv::status::CONFIG_PARSING_ERROR
@ CONFIG_PARSING_ERROR
parsing data to config failed
pmem::kv::status
status
Status returned by pmemkv functions.
Definition: libpmemkv.hpp:131
pmem::kv::config::get_int64
status get_int64(const std::string &key, std::int64_t &value) const noexcept
Gets std::int64_t value from a config item with key name.
Definition: libpmemkv.hpp:523
pmem::kv::config::put_object
status put_object(const std::string &key, T *value, void(*deleter)(void *)=[](T *value) { delete value;}) noexcept
Puts object pointed by value, of type T, with given destructor to a config.
Definition: libpmemkv.hpp:385
pmem::kv::status::NOT_FOUND
@ NOT_FOUND
record (or config item) not found
pmem::kv::config::release
pmemkv_config * release() noexcept
Similarly to std::unique_ptr::release it passes the ownership of underlying pmemkv_config variable an...
Definition: libpmemkv.hpp:566
pmem::kv::db::open
status open(const std::string &engine_name) noexcept
Opens the pmemkv database without any configuration parameters.
Definition: libpmemkv.hpp:728
pmem::kv::string_view::compare
int compare(const string_view &other) noexcept
Compares this string_view with other.
Definition: libpmemkv.hpp:642
pmem::kv::get_kv_function
int get_kv_function(string_view key, string_view value)
The C++ idiomatic function type to use for callback using key-value pair.
Definition: libpmemkv.hpp:107
pmem::kv::config::put_int64
status put_int64(const std::string &key, std::int64_t value) noexcept
Puts std::int64_t value to a config.
Definition: libpmemkv.hpp:420
pmem::kv::db::get_all
status get_all(get_kv_callback *callback, void *arg) noexcept
Executes (C-like) callback function for every record stored in pmem::kv::db.
Definition: libpmemkv.hpp:841
pmem::kv::string_view::_data
const char * _data
Definition: libpmemkv.hpp:96
pmem::kv::db
Main pmemkv class, it provides functions to operate on data in database.
Definition: libpmemkv.hpp:230
pmem::kv::status::STOPPED_BY_CB
@ STOPPED_BY_CB
iteration was stopped by user's callback
pmem::kv::config::_config
pmemkv_config * _config
Definition: libpmemkv.hpp:215
pmem::kv::string_view::string_view
string_view() noexcept
Default constructor with empty data.
Definition: libpmemkv.hpp:577
pmem::kv::status::NOT_SUPPORTED
@ NOT_SUPPORTED
function is not implemented by current engine
pmem::kv::db::get_between
status get_between(string_view key1, string_view key2, get_kv_callback *callback, void *arg) noexcept
Executes (C-like) callback function for every record stored in pmem::kv::db, whose keys are greater t...
Definition: libpmemkv.hpp:964
pmem::kv::db::get_above
status get_above(string_view key, get_kv_callback *callback, void *arg) noexcept
Executes (C-like) callback function for every record stored in pmem::kv::db, whose keys are greater t...
Definition: libpmemkv.hpp:877
pmem::kv::get_v_function
void get_v_function(string_view value)
The C++ idiomatic function type to use for callback using only the value.
Definition: libpmemkv.hpp:114
pmem::kv::db::count_below
status count_below(string_view key, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are less than the given ke...
Definition: libpmemkv.hpp:805
pmem::kv::config::get_data
status get_data(const std::string &key, T *&value, std::size_t &number) const noexcept
Gets object from a config item with key name and copies it into T object value.
Definition: libpmemkv.hpp:458
pmem::kv::config::init
int init() noexcept
Initialization function for config.
Definition: libpmemkv.hpp:341
pmem::kv::config::put_data
status put_data(const std::string &key, const T *value, const std::size_t number=1) noexcept
Puts binary data pointed by value, of type T, with count of elements to a config.
Definition: libpmemkv.hpp:364
pmem::kv::db::count_all
status count_all(std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db.
Definition: libpmemkv.hpp:774
pmem::kv::config::get_uint64
status get_uint64(const std::string &key, std::uint64_t &value) const noexcept
Gets std::uint64_t value from a config item with key name.
Definition: libpmemkv.hpp:505
pmem::kv::db::get_below
status get_below(string_view key, get_kv_callback *callback, void *arg) noexcept
Executes (C-like) callback function for every record stored in pmem::kv::db, whose keys are less than...
Definition: libpmemkv.hpp:920
pmem::kv::db::remove
status remove(string_view key) noexcept
Removes from database record with given key.
Definition: libpmemkv.hpp:1085
pmem::kv::get_kv_callback
pmemkv_get_kv_callback get_kv_callback
Key-value pair callback, C-style.
Definition: libpmemkv.hpp:119
pmem::kv::string_view
Our brief std::string_view implementation.
Definition: libpmemkv.hpp:80
pmem::kv::db::_db
pmemkv_db * _db
Definition: libpmemkv.hpp:278
pmem::kv::db::errormsg
std::string errormsg()
Returns a human readable string describing the last error.
Definition: libpmemkv.hpp:1097
pmem::kv::get_v_callback
pmemkv_get_v_callback get_v_callback
Value-only callback, C-style.
Definition: libpmemkv.hpp:123
pmem::kv::string_view::data
const char * data() const noexcept
Returns pointer to data stored in this pmem::kv::string_view.
Definition: libpmemkv.hpp:619
pmem::kv::config::operator=
config & operator=(const config &other)=delete
pmem::kv::db::count_above
status count_above(string_view key, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are greater than the given...
Definition: libpmemkv.hpp:789
pmem::kv::config::~config
~config()
Default destructor.
Definition: libpmemkv.hpp:329
pmem::kv::config::config
config() noexcept
Default constructor with uninitialized config.
Definition: libpmemkv.hpp:284
pmem::kv::db::exists
status exists(string_view key) noexcept
Checks existence of record with given key.
Definition: libpmemkv.hpp:1003
pmem::kv::config::put_uint64
status put_uint64(const std::string &key, std::uint64_t value) noexcept
Puts std::uint64_t value to a config.
Definition: libpmemkv.hpp:403
pmem::kv::db::operator=
db & operator=(const db &other)=delete
pmem::kv::status::UNKNOWN_ERROR
@ UNKNOWN_ERROR
unknown error
pmem::kv::config::get_object
status get_object(const std::string &key, T *&value) const noexcept
Gets binary data from a config item with key name and assigns pointer to T object value.
Definition: libpmemkv.hpp:486
pmem::kv::string_view::_size
std::size_t _size
Definition: libpmemkv.hpp:97
pmem::kv::db::count_between
status count_between(string_view key1, string_view key2, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are greater than the key1 ...
Definition: libpmemkv.hpp:822
pmem::kv::db::put
status put(string_view key, string_view value) noexcept
Inserts a key-value pair into pmemkv database.
Definition: libpmemkv.hpp:1071
pmem::kv::string_view::operator=
string_view & operator=(const string_view &rhs) noexcept=default
pmem::kv::status::WRONG_ENGINE_NAME
@ WRONG_ENGINE_NAME
engine name does not match any available engine
pmem::kv::status::OUT_OF_MEMORY
@ OUT_OF_MEMORY
operation failed because there is not enough memory (or space on the device)
pmem::kv::status::TRANSACTION_SCOPE_ERROR
@ TRANSACTION_SCOPE_ERROR
an error with the scope of the libpmemobj transaction