PMEMKV  1.2.1-git1.g9b6e240
This is the C++ documentation for PMEMKV.
libpmemkv.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2017-2020, Intel Corporation */
3 
4 #ifndef LIBPMEMKV_HPP
5 #define LIBPMEMKV_HPP
6 
7 #include <functional>
8 #include <memory>
9 #include <stdexcept>
10 #include <string>
11 #include <utility>
12 
13 #if __cpp_lib_string_view
14 #include <string_view>
15 #endif
16 
17 #include "libpmemkv.h"
18 
32 namespace pmem
33 {
40 namespace kv
41 {
42 
43 #if __cpp_lib_string_view
44 using string_view = std::string_view;
45 #else
46 
52 class string_view {
53 public:
54  string_view() noexcept;
55  string_view(const char *data, size_t size);
56  string_view(const std::string &s);
57  string_view(const char *data);
58 
59  string_view(const string_view &rhs) noexcept = default;
60  string_view &operator=(const string_view &rhs) noexcept = default;
61 
62  const char *data() const noexcept;
63  std::size_t size() const noexcept;
64 
65  int compare(const string_view &other) noexcept;
66 
67 private:
68  const char *_data;
69  std::size_t _size;
70 };
71 #endif
72 
79 typedef int get_kv_function(string_view key, string_view value);
86 typedef void get_v_function(string_view value);
87 
89 
93 using get_kv_callback = pmemkv_get_kv_callback;
97 using get_v_callback = pmemkv_get_v_callback;
98 
105 enum class status {
106  OK = PMEMKV_STATUS_OK,
107  UNKNOWN_ERROR = PMEMKV_STATUS_UNKNOWN_ERROR,
108  NOT_FOUND = PMEMKV_STATUS_NOT_FOUND,
109  NOT_SUPPORTED = PMEMKV_STATUS_NOT_SUPPORTED,
111  INVALID_ARGUMENT = PMEMKV_STATUS_INVALID_ARGUMENT,
113  CONFIG_PARSING_ERROR =
114  PMEMKV_STATUS_CONFIG_PARSING_ERROR,
115  CONFIG_TYPE_ERROR =
116  PMEMKV_STATUS_CONFIG_TYPE_ERROR,
118  STOPPED_BY_CB = PMEMKV_STATUS_STOPPED_BY_CB,
120  OUT_OF_MEMORY =
121  PMEMKV_STATUS_OUT_OF_MEMORY,
123  WRONG_ENGINE_NAME =
124  PMEMKV_STATUS_WRONG_ENGINE_NAME,
126  TRANSACTION_SCOPE_ERROR =
127  PMEMKV_STATUS_TRANSACTION_SCOPE_ERROR,
129  DEFRAG_ERROR = PMEMKV_STATUS_DEFRAG_ERROR,
132  PMEMKV_STATUS_COMPARATOR_MISMATCH,
134 };
135 
155 class config {
156 public:
157  config() noexcept;
158  explicit config(pmemkv_config *cfg) noexcept;
159 
160  ~config();
161 
162  config(const config &other) = delete;
163  config(config &&other) noexcept;
164 
165  config &operator=(const config &other) = delete;
166  config &operator=(config &&other) noexcept;
167 
168  template <typename Comparator>
169  status put_comparator(Comparator &&comparator);
170 
171  template <typename T>
172  status put_data(const std::string &key, const T *value,
173  const std::size_t number = 1) noexcept;
174 
175  template <typename T>
176  status put_object(const std::string &key, T *value,
177  void (*deleter)(void *)) noexcept;
178  template <typename T, typename D>
179  status put_object(const std::string &key, std::unique_ptr<T, D> object) noexcept;
180  status put_uint64(const std::string &key, std::uint64_t value) noexcept;
181  status put_int64(const std::string &key, std::int64_t value) noexcept;
182  status put_string(const std::string &key, const std::string &value) noexcept;
183 
184  template <typename T>
185  status get_data(const std::string &key, T *&value, std::size_t &number) const
186  noexcept;
187  template <typename T>
188  status get_object(const std::string &key, T *&value) const noexcept;
189 
190  status get_uint64(const std::string &key, std::uint64_t &value) const noexcept;
191  status get_int64(const std::string &key, std::int64_t &value) const noexcept;
192  status get_string(const std::string &key, std::string &value) const noexcept;
193 
194  pmemkv_config *release() noexcept;
195 
196 private:
197  int init() noexcept;
198 
199  pmemkv_config *_config;
200 };
201 
214 class db {
215 public:
216  db() noexcept;
217  ~db();
218 
219  db(const db &other) = delete;
220  db(db &&other) noexcept;
221 
222  db &operator=(const db &other) = delete;
223  db &operator=(db &&other) noexcept;
224 
225  status open(const std::string &engine_name) noexcept;
226  status open(const std::string &engine_name, config &&cfg) noexcept;
227 
228  void close() noexcept;
229 
230  status count_all(std::size_t &cnt) noexcept;
231  status count_above(string_view key, std::size_t &cnt) noexcept;
232  status count_equal_above(string_view key, std::size_t &cnt) noexcept;
233  status count_equal_below(string_view key, std::size_t &cnt) noexcept;
234  status count_below(string_view key, std::size_t &cnt) noexcept;
235  status count_between(string_view key1, string_view key2,
236  std::size_t &cnt) noexcept;
237 
238  status get_all(get_kv_callback *callback, void *arg) noexcept;
239  status get_all(std::function<get_kv_function> f) noexcept;
240 
241  status get_above(string_view key, get_kv_callback *callback, void *arg) noexcept;
242  status get_above(string_view key, std::function<get_kv_function> f) noexcept;
243 
244  status get_equal_above(string_view key, get_kv_callback *callback,
245  void *arg) noexcept;
246  status get_equal_above(string_view key,
247  std::function<get_kv_function> f) noexcept;
248 
249  status get_equal_below(string_view key, get_kv_callback *callback,
250  void *arg) noexcept;
251  status get_equal_below(string_view key,
252  std::function<get_kv_function> f) noexcept;
253 
254  status get_below(string_view key, get_kv_callback *callback, void *arg) noexcept;
255  status get_below(string_view key, std::function<get_kv_function> f) noexcept;
256 
257  status get_between(string_view key1, string_view key2, get_kv_callback *callback,
258  void *arg) noexcept;
259  status get_between(string_view key1, string_view key2,
260  std::function<get_kv_function> f) noexcept;
261 
262  status exists(string_view key) noexcept;
263 
264  status get(string_view key, get_v_callback *callback, void *arg) noexcept;
265  status get(string_view key, std::function<get_v_function> f) noexcept;
266  status get(string_view key, std::string *value) noexcept;
267 
268  status put(string_view key, string_view value) noexcept;
269  status remove(string_view key) noexcept;
270  status defrag(double start_percent = 0, double amount_percent = 100);
271 
272  std::string errormsg();
273 
274 private:
275  pmemkv_db *_db;
276 };
277 
285 namespace internal
286 {
287 
288 /*
289  * Abstracts unique_ptr - exposes only void *get() method and a destructor.
290  * This class is needed for C callbacks which cannot be templated
291  * (type of object and deleter must be abstracted away).
292  */
295  {
296  }
297 
298  virtual void *get() = 0;
299 };
300 
301 template <typename T, typename D>
303  unique_ptr_wrapper(std::unique_ptr<T, D> ptr) : ptr(std::move(ptr))
304  {
305  }
306 
307  void *get() override
308  {
309  return ptr.get();
310  }
311 
312  std::unique_ptr<T, D> ptr;
313 };
314 
316 public:
318  {
319  }
320  virtual int compare(string_view key1, string_view key2) = 0;
321 };
322 
323 template <typename Comparator>
325  comparator_wrapper(const Comparator &cmp) : cmp(cmp)
326  {
327  }
328 
329  comparator_wrapper(Comparator &&cmp) : cmp(std::move(cmp))
330  {
331  }
332 
333  int compare(string_view key1, string_view key2) override
334  {
335  return cmp.compare(key1, key2);
336  }
337 
338  Comparator cmp;
339 };
340 
343  std::unique_ptr<comparator_base> ptr,
344  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *>
345  c_cmp)
346  : ptr(std::move(ptr)), c_cmp(std::move(c_cmp))
347  {
348  }
349 
350  void *get() override
351  {
352  return c_cmp.get();
353  }
354 
355  std::unique_ptr<comparator_base> ptr;
356  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *> c_cmp;
357 };
358 
359 /*
360  * All functions which will be called by C code must be declared as extern "C"
361  * to ensure they have C linkage. It is needed because it is possible that
362  * C and C++ functions use different calling conventions.
363  */
364 extern "C" {
365 static inline void call_up_destructor(void *object)
366 {
367  auto *ptr = static_cast<unique_ptr_wrapper_base *>(object);
368  delete ptr;
369 }
370 
371 static inline void *call_up_get(void *object)
372 {
373  auto *ptr = static_cast<unique_ptr_wrapper_base *>(object);
374  return ptr->get();
375 }
376 
377 static inline int call_comparator_function(const char *k1, size_t kb1, const char *k2,
378  size_t kb2, void *arg)
379 {
380  auto *cmp = static_cast<comparator_base *>(arg);
381  return cmp->compare(string_view(k1, kb1), string_view(k2, kb2));
382 }
383 } /* extern "C" */
384 } /* namespace internal */
385 
389 inline config::config() noexcept
390 {
391  this->_config = nullptr;
392 }
393 
398 inline config::config(config &&other) noexcept
399 {
400  this->_config = other._config;
401  other._config = nullptr;
402 }
403 
408 inline config &config::operator=(config &&other) noexcept
409 {
410  if (this == &other)
411  return *this;
412 
413  if (this->_config)
414  pmemkv_config_delete(this->_config);
415 
416  this->_config = other._config;
417  other._config = nullptr;
418 
419  return *this;
420 }
421 
426 inline config::config(pmemkv_config *cfg) noexcept
427 {
428  this->_config = cfg;
429 }
430 
435 {
436  if (this->_config)
437  pmemkv_config_delete(this->_config);
438 }
439 
446 inline int config::init() noexcept
447 {
448  if (this->_config == nullptr) {
449  this->_config = pmemkv_config_new();
450 
451  if (this->_config == nullptr)
452  return 1;
453  }
454 
455  return 0;
456 }
457 
468 template <typename T>
469 inline status config::put_data(const std::string &key, const T *value,
470  const std::size_t count) noexcept
471 {
472  if (init() != 0)
473  return status::UNKNOWN_ERROR;
474 
475  return static_cast<status>(pmemkv_config_put_data(
476  this->_config, key.data(), (void *)value, count * sizeof(T)));
477 }
478 
489 template <typename T>
490 inline status config::put_object(const std::string &key, T *value,
491  void (*deleter)(void *)) noexcept
492 {
493  if (init() != 0)
494  return status::UNKNOWN_ERROR;
495 
496  return static_cast<status>(pmemkv_config_put_object(this->_config, key.data(),
497  (void *)value, deleter));
498 }
499 
508 template <typename T, typename D>
509 inline status config::put_object(const std::string &key,
510  std::unique_ptr<T, D> object) noexcept
511 {
512  if (init() != 0)
513  return status::UNKNOWN_ERROR;
514 
516 
517  try {
518  wrapper = new internal::unique_ptr_wrapper<T, D>(std::move(object));
519  } catch (std::bad_alloc &e) {
520  return status::OUT_OF_MEMORY;
521  } catch (...) {
522  return status::UNKNOWN_ERROR;
523  }
524 
525  return static_cast<status>(pmemkv_config_put_object_cb(
526  this->_config, key.data(), (void *)wrapper, internal::call_up_get,
527  internal::call_up_destructor));
528 }
529 
546 template <typename Comparator>
547 inline status config::put_comparator(Comparator &&comparator)
548 {
549  static_assert(
550  std::is_same<decltype(std::declval<Comparator>().compare(
551  std::declval<string_view>(),
552  std::declval<string_view>())),
553  int>::value,
554  "Comparator should implement `int compare(pmem::kv::string_view, pmem::kv::string_view)` method");
555  static_assert(std::is_convertible<decltype(std::declval<Comparator>().name()),
556  std::string>::value,
557  "Comparator should implement `std::string name()` method");
558 
559  std::unique_ptr<internal::comparator_base> wrapper;
560 
561  try {
562  wrapper = std::unique_ptr<internal::comparator_base>(
564  std::forward<Comparator>(comparator)));
565  } catch (std::bad_alloc &e) {
566  return status::OUT_OF_MEMORY;
567  } catch (...) {
568  return status::UNKNOWN_ERROR;
569  }
570 
571  auto cmp =
572  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *>(
573  pmemkv_comparator_new(&internal::call_comparator_function,
574  std::string(comparator.name()).c_str(),
575  wrapper.get()),
576  &pmemkv_comparator_delete);
577  if (cmp == nullptr)
578  return status::UNKNOWN_ERROR;
579 
581 
582  try {
583  entry = new internal::comparator_config_entry(std::move(wrapper),
584  std::move(cmp));
585  } catch (std::bad_alloc &e) {
586  return status::OUT_OF_MEMORY;
587  } catch (...) {
588  return status::UNKNOWN_ERROR;
589  }
590 
591  return static_cast<status>(pmemkv_config_put_object_cb(
592  this->_config, "comparator", (void *)entry, internal::call_up_get,
593  internal::call_up_destructor));
594 }
595 
604 inline status config::put_uint64(const std::string &key, std::uint64_t value) noexcept
605 {
606  if (init() != 0)
607  return status::UNKNOWN_ERROR;
608 
609  return static_cast<status>(
610  pmemkv_config_put_uint64(this->_config, key.data(), value));
611 }
612 
621 inline status config::put_int64(const std::string &key, std::int64_t value) noexcept
622 {
623  if (init() != 0)
624  return status::UNKNOWN_ERROR;
625 
626  return static_cast<status>(
627  pmemkv_config_put_int64(this->_config, key.data(), value));
628 }
629 
638 inline status config::put_string(const std::string &key,
639  const std::string &value) noexcept
640 {
641  if (init() != 0)
642  return status::UNKNOWN_ERROR;
643 
644  return static_cast<status>(
645  pmemkv_config_put_string(this->_config, key.data(), value.data()));
646 }
647 
658 template <typename T>
659 inline status config::get_data(const std::string &key, T *&value,
660  std::size_t &count) const noexcept
661 {
662  if (this->_config == nullptr)
663  return status::NOT_FOUND;
664 
665  std::size_t size;
666  auto s = static_cast<status>(pmemkv_config_get_data(
667  this->_config, key.data(), (const void **)&value, &size));
668 
669  if (s != status::OK)
670  return s;
671 
672  count = size / sizeof(T);
673 
674  return status::OK;
675 }
676 
686 template <typename T>
687 inline status config::get_object(const std::string &key, T *&value) const noexcept
688 {
689  if (this->_config == nullptr)
690  return status::NOT_FOUND;
691 
692  auto s = static_cast<status>(
693  pmemkv_config_get_object(this->_config, key.data(), (void **)&value));
694 
695  return s;
696 }
697 
706 inline status config::get_uint64(const std::string &key, std::uint64_t &value) const
707  noexcept
708 {
709  if (this->_config == nullptr)
710  return status::NOT_FOUND;
711 
712  return static_cast<status>(
713  pmemkv_config_get_uint64(this->_config, key.data(), &value));
714 }
715 
724 inline status config::get_int64(const std::string &key, std::int64_t &value) const
725  noexcept
726 {
727  if (this->_config == nullptr)
728  return status::NOT_FOUND;
729 
730  return static_cast<status>(
731  pmemkv_config_get_int64(this->_config, key.data(), &value));
732 }
733 
742 inline status config::get_string(const std::string &key, std::string &value) const
743  noexcept
744 {
745  if (this->_config == nullptr)
746  return status::NOT_FOUND;
747 
748  const char *data;
749 
750  auto s = static_cast<status>(
751  pmemkv_config_get_string(this->_config, key.data(), &data));
752 
753  if (s != status::OK)
754  return s;
755 
756  value = data;
757 
758  return status::OK;
759 }
760 
767 inline pmemkv_config *config::release() noexcept
768 {
769  auto c = this->_config;
770  this->_config = nullptr;
771  return c;
772 }
773 
774 #if !__cpp_lib_string_view
775 
778 inline string_view::string_view() noexcept : _data(""), _size(0)
779 {
780 }
781 
789 inline string_view::string_view(const char *data, size_t size) : _data(data), _size(size)
790 {
791 }
792 
798 inline string_view::string_view(const std::string &s) : _data(s.c_str()), _size(s.size())
799 {
800 }
801 
809 inline string_view::string_view(const char *data)
810  : _data(data), _size(std::char_traits<char>::length(data))
811 {
812 }
813 
820 inline const char *string_view::data() const noexcept
821 {
822  return _data;
823 }
824 
830 inline std::size_t string_view::size() const noexcept
831 {
832  return _size;
833 }
834 
843 inline int string_view::compare(const string_view &other) noexcept
844 {
845  int ret = std::char_traits<char>::compare(data(), other.data(),
846  std::min(size(), other.size()));
847  if (ret != 0)
848  return ret;
849  if (size() < other.size())
850  return -1;
851  if (size() > other.size())
852  return 1;
853  return 0;
854 }
855 #endif
856 
857 /*
858  * All functions which will be called by C code must be declared as extern "C"
859  * to ensure they have C linkage. It is needed because it is possible that
860  * C and C++ functions use different calling conventions.
861  */
862 extern "C" {
863 static inline int call_get_kv_function(const char *key, size_t keybytes,
864  const char *value, size_t valuebytes, void *arg)
865 {
866  return (*reinterpret_cast<std::function<get_kv_function> *>(arg))(
867  string_view(key, keybytes), string_view(value, valuebytes));
868 }
869 
870 static inline void call_get_v_function(const char *value, size_t valuebytes, void *arg)
871 {
872  (*reinterpret_cast<std::function<get_v_function> *>(arg))(
873  string_view(value, valuebytes));
874 }
875 
876 static inline void call_get_copy(const char *v, size_t vb, void *arg)
877 {
878  auto c = reinterpret_cast<std::string *>(arg);
879  c->assign(v, vb);
880 }
881 }
882 
886 inline db::db() noexcept
887 {
888  this->_db = nullptr;
889 }
890 
897 inline db::db(db &&other) noexcept
898 {
899  this->_db = other._db;
900  other._db = nullptr;
901 }
902 
910 inline db &db::operator=(db &&other) noexcept
911 {
912  if (this == &other)
913  return *this;
914 
915  close();
916 
917  std::swap(this->_db, other._db);
918 
919  return *this;
920 }
921 
929 inline status db::open(const std::string &engine_name) noexcept
930 {
931  return static_cast<status>(
932  pmemkv_open(engine_name.c_str(), nullptr, &(this->_db)));
933 }
934 
943 inline status db::open(const std::string &engine_name, config &&cfg) noexcept
944 {
945  return static_cast<status>(
946  pmemkv_open(engine_name.c_str(), cfg.release(), &(this->_db)));
947 }
948 
952 inline void db::close() noexcept
953 {
954  if (this->_db != nullptr)
955  pmemkv_close(this->_db);
956 
957  this->_db = nullptr;
958 }
959 
963 inline db::~db()
964 {
965  close();
966 }
967 
975 inline status db::count_all(std::size_t &cnt) noexcept
976 {
977  return static_cast<status>(pmemkv_count_all(this->_db, &cnt));
978 }
979 
990 inline status db::count_above(string_view key, std::size_t &cnt) noexcept
991 {
992  return static_cast<status>(
993  pmemkv_count_above(this->_db, key.data(), key.size(), &cnt));
994 }
995 
1006 inline status db::count_equal_above(string_view key, std::size_t &cnt) noexcept
1007 {
1008  return static_cast<status>(
1009  pmemkv_count_equal_above(this->_db, key.data(), key.size(), &cnt));
1010 }
1011 
1022 inline status db::count_equal_below(string_view key, std::size_t &cnt) noexcept
1023 {
1024  return static_cast<status>(
1025  pmemkv_count_equal_below(this->_db, key.data(), key.size(), &cnt));
1026 }
1027 
1038 inline status db::count_below(string_view key, std::size_t &cnt) noexcept
1039 {
1040  return static_cast<status>(
1041  pmemkv_count_below(this->_db, key.data(), key.size(), &cnt));
1042 }
1043 
1056  std::size_t &cnt) noexcept
1057 {
1058  return static_cast<status>(pmemkv_count_between(
1059  this->_db, key1.data(), key1.size(), key2.data(), key2.size(), &cnt));
1060 }
1061 
1074 inline status db::get_all(get_kv_callback *callback, void *arg) noexcept
1075 {
1076  return static_cast<status>(pmemkv_get_all(this->_db, callback, arg));
1077 }
1078 
1089 inline status db::get_all(std::function<get_kv_function> f) noexcept
1090 {
1091  return static_cast<status>(pmemkv_get_all(this->_db, call_get_kv_function, &f));
1092 }
1093 
1111  void *arg) noexcept
1112 {
1113  return static_cast<status>(
1114  pmemkv_get_above(this->_db, key.data(), key.size(), callback, arg));
1115 }
1116 
1131 inline status db::get_above(string_view key, std::function<get_kv_function> f) noexcept
1132 {
1133  return static_cast<status>(pmemkv_get_above(this->_db, key.data(), key.size(),
1134  call_get_kv_function, &f));
1135 }
1136 
1155  void *arg) noexcept
1156 {
1157  return static_cast<status>(
1158  pmemkv_get_equal_above(this->_db, key.data(), key.size(), callback, arg));
1159 }
1160 
1177  std::function<get_kv_function> f) noexcept
1178 {
1179  return static_cast<status>(pmemkv_get_equal_above(
1180  this->_db, key.data(), key.size(), call_get_kv_function, &f));
1181 }
1182 
1201  void *arg) noexcept
1202 {
1203  return static_cast<status>(
1204  pmemkv_get_equal_below(this->_db, key.data(), key.size(), callback, arg));
1205 }
1206 
1223  std::function<get_kv_function> f) noexcept
1224 {
1225  return static_cast<status>(pmemkv_get_equal_below(
1226  this->_db, key.data(), key.size(), call_get_kv_function, &f));
1227 }
1228 
1246  void *arg) noexcept
1247 {
1248  return static_cast<status>(
1249  pmemkv_get_below(this->_db, key.data(), key.size(), callback, arg));
1250 }
1251 
1266 inline status db::get_below(string_view key, std::function<get_kv_function> f) noexcept
1267 {
1268  return static_cast<status>(pmemkv_get_below(this->_db, key.data(), key.size(),
1269  call_get_kv_function, &f));
1270 }
1271 
1290  get_kv_callback *callback, void *arg) noexcept
1291 {
1292  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
1293  key2.data(), key2.size(), callback,
1294  arg));
1295 }
1312  std::function<get_kv_function> f) noexcept
1313 {
1314  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
1315  key2.data(), key2.size(),
1316  call_get_kv_function, &f));
1317 }
1318 
1328 inline status db::exists(string_view key) noexcept
1329 {
1330  return static_cast<status>(pmemkv_exists(this->_db, key.data(), key.size()));
1331 }
1332 
1348 inline status db::get(string_view key, get_v_callback *callback, void *arg) noexcept
1349 {
1350  return static_cast<status>(
1351  pmemkv_get(this->_db, key.data(), key.size(), callback, arg));
1352 }
1353 
1365 inline status db::get(string_view key, std::function<get_v_function> f) noexcept
1366 {
1367  return static_cast<status>(
1368  pmemkv_get(this->_db, key.data(), key.size(), call_get_v_function, &f));
1369 }
1370 
1381 inline status db::get(string_view key, std::string *value) noexcept
1382 {
1383  return static_cast<status>(
1384  pmemkv_get(this->_db, key.data(), key.size(), call_get_copy, value));
1385 }
1386 
1396 inline status db::put(string_view key, string_view value) noexcept
1397 {
1398  return static_cast<status>(pmemkv_put(this->_db, key.data(), key.size(),
1399  value.data(), value.size()));
1400 }
1401 
1410 inline status db::remove(string_view key) noexcept
1411 {
1412  return static_cast<status>(pmemkv_remove(this->_db, key.data(), key.size()));
1413 }
1414 
1424 inline status db::defrag(double start_percent, double amount_percent)
1425 
1426 {
1427  return static_cast<status>(
1428  pmemkv_defrag(this->_db, start_percent, amount_percent));
1429 }
1430 
1438 inline std::string db::errormsg()
1439 {
1440  return std::string(pmemkv_errormsg());
1441 }
1442 
1448 static inline std::string errormsg()
1449 {
1450  return std::string(pmemkv_errormsg());
1451 }
1452 
1453 } /* namespace kv */
1454 } /* namespace pmem */
1455 
1456 #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:638
pmem::kv::config::put_object
status put_object(const std::string &key, T *value, void(*deleter)(void *)) noexcept
Puts object pointed by value, of type T, with given destructor to a config.
Definition: libpmemkv.hpp:490
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:742
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:830
pmem::kv::internal::comparator_wrapper::comparator_wrapper
comparator_wrapper(const Comparator &cmp)
Definition: libpmemkv.hpp:325
pmem::kv::db::db
db() noexcept
Default constructor with uninitialized database.
Definition: libpmemkv.hpp:886
pmem::kv::internal::comparator_config_entry::ptr
std::unique_ptr< comparator_base > ptr
Definition: libpmemkv.hpp:355
pmem::kv::db::~db
~db()
Default destructor.
Definition: libpmemkv.hpp:963
pmem::kv::config
Holds configuration parameters for engines.
Definition: libpmemkv.hpp:155
pmem
Persistent memory namespace.
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:1348
pmem::kv::db::close
void close() noexcept
Closes pmemkv database.
Definition: libpmemkv.hpp:952
pmem::kv::internal::unique_ptr_wrapper::unique_ptr_wrapper
unique_ptr_wrapper(std::unique_ptr< T, D > ptr)
Definition: libpmemkv.hpp:303
pmem::kv::status
status
Status returned by pmemkv functions.
Definition: libpmemkv.hpp:105
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:724
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:767
pmem::kv::db::open
status open(const std::string &engine_name) noexcept
Opens the pmemkv database without any configuration parameters.
Definition: libpmemkv.hpp:929
pmem::kv::string_view::compare
int compare(const string_view &other) noexcept
Compares this string_view with other.
Definition: libpmemkv.hpp:843
pmem::kv::internal::comparator_config_entry
Definition: libpmemkv.hpp:341
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:79
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:621
pmem::kv::internal::comparator_base
Definition: libpmemkv.hpp:315
pmem::kv::internal::unique_ptr_wrapper_base
Definition: libpmemkv.hpp:293
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:1074
pmem::kv::string_view::_data
const char * _data
Definition: libpmemkv.hpp:68
pmem::kv::internal::unique_ptr_wrapper::get
void * get() override
Definition: libpmemkv.hpp:307
pmem::kv::internal::comparator_wrapper
Definition: libpmemkv.hpp:324
pmem::kv::db::count_equal_above
status count_equal_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 or equal ...
Definition: libpmemkv.hpp:1006
pmem::kv::db
Main pmemkv class, it provides functions to operate on data in database.
Definition: libpmemkv.hpp:214
pmem::kv::db::db
db(const db &other)=delete
pmem::kv::internal::comparator_config_entry::comparator_config_entry
comparator_config_entry(std::unique_ptr< comparator_base > ptr, std::unique_ptr< pmemkv_comparator, decltype(pmemkv_comparator_delete) * > c_cmp)
Definition: libpmemkv.hpp:342
pmem::kv::config::put_comparator
status put_comparator(Comparator &&comparator)
Puts comparator object to a config.
Definition: libpmemkv.hpp:547
pmem::kv::db::get_equal_below
status get_equal_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 lower tha...
Definition: libpmemkv.hpp:1200
pmem::kv::string_view::string_view
string_view() noexcept
Default constructor with empty data.
Definition: libpmemkv.hpp:778
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:1289
pmem::kv::db::defrag
status defrag(double start_percent=0, double amount_percent=100)
Defragments approximately 'amount_percent' percent of elements in the database starting from 'start_p...
Definition: libpmemkv.hpp:1424
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:1110
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:86
pmem::kv::comparator_function
int comparator_function(string_view key1, string_view key2)
Definition: libpmemkv.hpp:88
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:1038
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:659
pmem::kv::config::init
int init() noexcept
Initialization function for config.
Definition: libpmemkv.hpp:446
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:469
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:975
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:706
pmem::kv::internal::comparator_wrapper::comparator_wrapper
comparator_wrapper(Comparator &&cmp)
Definition: libpmemkv.hpp:329
pmem::kv::db::get_equal_above
status get_equal_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:1154
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 lower tha...
Definition: libpmemkv.hpp:1245
pmem::kv::internal::unique_ptr_wrapper_base::~unique_ptr_wrapper_base
virtual ~unique_ptr_wrapper_base()
Definition: libpmemkv.hpp:294
pmem::kv::db::remove
status remove(string_view key) noexcept
Removes from database record with given key.
Definition: libpmemkv.hpp:1410
pmem::kv::internal::comparator_base::compare
virtual int compare(string_view key1, string_view key2)=0
pmem::kv::get_kv_callback
pmemkv_get_kv_callback get_kv_callback
Key-value pair callback, C-style.
Definition: libpmemkv.hpp:93
pmem::kv::string_view
Our brief std::string_view implementation.
Definition: libpmemkv.hpp:52
pmem::kv::db::errormsg
std::string errormsg()
Returns a human readable string describing the last error.
Definition: libpmemkv.hpp:1438
pmem::kv::internal::comparator_config_entry::c_cmp
std::unique_ptr< pmemkv_comparator, decltype(pmemkv_comparator_delete) * > c_cmp
Definition: libpmemkv.hpp:356
pmem::kv::db::count_equal_below
status count_equal_below(string_view key, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are lower than or equal to...
Definition: libpmemkv.hpp:1022
pmem::kv::internal::unique_ptr_wrapper::ptr
std::unique_ptr< T, D > ptr
Definition: libpmemkv.hpp:312
pmem::kv::get_v_callback
pmemkv_get_v_callback get_v_callback
Value-only callback, C-style.
Definition: libpmemkv.hpp:97
pmem::kv::internal::comparator_config_entry::get
void * get() override
Definition: libpmemkv.hpp:350
pmem::kv::string_view::data
const char * data() const noexcept
Returns pointer to data stored in this pmem::kv::string_view.
Definition: libpmemkv.hpp:820
pmem::kv::config::operator=
config & operator=(const config &other)=delete
pmem::kv::internal::unique_ptr_wrapper_base::get
virtual void * get()=0
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:990
pmem::kv::internal::unique_ptr_wrapper
Definition: libpmemkv.hpp:302
pmem::kv::config::~config
~config()
Default destructor.
Definition: libpmemkv.hpp:434
pmem::kv::config::config
config() noexcept
Default constructor with uninitialized config.
Definition: libpmemkv.hpp:389
pmem::kv::db::exists
status exists(string_view key) noexcept
Checks existence of record with given key.
Definition: libpmemkv.hpp:1328
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:604
pmem::kv::db::operator=
db & operator=(const db &other)=delete
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:687
pmem::kv::config::config
config(const config &other)=delete
pmem::kv::string_view::_size
std::size_t _size
Definition: libpmemkv.hpp:69
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:1055
pmem::kv::db::put
status put(string_view key, string_view value) noexcept
Inserts a key-value pair into pmemkv database.
Definition: libpmemkv.hpp:1396
pmem::kv::string_view::operator=
string_view & operator=(const string_view &rhs) noexcept=default
pmem::kv::string_view::string_view
string_view(const string_view &rhs) noexcept=default
pmem::kv::internal::comparator_wrapper::cmp
Comparator cmp
Definition: libpmemkv.hpp:338
pmem::kv::internal::comparator_wrapper::compare
int compare(string_view key1, string_view key2) override
Definition: libpmemkv.hpp:333
pmem::kv::internal::comparator_base::~comparator_base
virtual ~comparator_base()
Definition: libpmemkv.hpp:317