PMEMKV  1.3.1-git1.g6468f74
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 <iostream>
9 #include <libpmemobj++/string_view.hpp>
10 #include <memory>
11 #include <stdexcept>
12 #include <string>
13 #include <utility>
14 
15 #include "libpmemkv.h"
16 #include <libpmemobj/pool_base.h>
17 
31 namespace pmem
32 {
39 namespace kv
40 {
41 
43 
50 typedef int get_kv_function(string_view key, string_view value);
57 typedef void get_v_function(string_view value);
58 
60 
64 using get_kv_callback = pmemkv_get_kv_callback;
68 using get_v_callback = pmemkv_get_v_callback;
69 
76 enum class status {
77  OK = PMEMKV_STATUS_OK,
78  UNKNOWN_ERROR = PMEMKV_STATUS_UNKNOWN_ERROR,
79  NOT_FOUND = PMEMKV_STATUS_NOT_FOUND,
80  NOT_SUPPORTED = PMEMKV_STATUS_NOT_SUPPORTED,
82  INVALID_ARGUMENT = PMEMKV_STATUS_INVALID_ARGUMENT,
84  CONFIG_PARSING_ERROR =
85  PMEMKV_STATUS_CONFIG_PARSING_ERROR,
86  CONFIG_TYPE_ERROR =
87  PMEMKV_STATUS_CONFIG_TYPE_ERROR,
89  STOPPED_BY_CB = PMEMKV_STATUS_STOPPED_BY_CB,
91  OUT_OF_MEMORY =
92  PMEMKV_STATUS_OUT_OF_MEMORY,
94  WRONG_ENGINE_NAME =
95  PMEMKV_STATUS_WRONG_ENGINE_NAME,
97  TRANSACTION_SCOPE_ERROR =
98  PMEMKV_STATUS_TRANSACTION_SCOPE_ERROR,
100  DEFRAG_ERROR = PMEMKV_STATUS_DEFRAG_ERROR,
103  PMEMKV_STATUS_COMPARATOR_MISMATCH,
105 };
106 
107 inline std::ostream &operator<<(std::ostream &os, const status &s)
108 {
109  static const std::string statuses[] = {"OK",
110  "UNKNOWN_ERROR",
111  "NOT_FOUND",
112  "NOT_SUPPORTED",
113  "INVALID_ARGUMENT",
114  "CONFIG_PARSING_ERROR",
115  "CONFIG_TYPE_ERROR",
116  "STOPPED_BY_CB",
117  "OUT_OF_MEMORY",
118  "WRONG_ENGINE_NAME",
119  "TRANSACTION_SCOPE_ERROR",
120  "DEFRAG_ERROR",
121  "COMPARATOR_MISMATCH"};
122 
123  int status_no = static_cast<int>(s);
124  os << statuses[status_no] << " (" << status_no << ")";
125 
126  return os;
127 }
128 
148 class config {
149 public:
150  config() noexcept;
151  explicit config(pmemkv_config *cfg) noexcept;
152 
153  ~config();
154 
155  config(const config &other) = delete;
156  config(config &&other) noexcept;
157 
158  config &operator=(const config &other) = delete;
159  config &operator=(config &&other) noexcept;
160 
161  template <typename T>
162  status put_data(const std::string &key, const T *value,
163  const std::size_t number = 1) noexcept;
164 
165  template <typename T>
166  status put_object(const std::string &key, T *value,
167  void (*deleter)(void *)) noexcept;
168  template <typename T, typename D>
169  status put_object(const std::string &key, std::unique_ptr<T, D> object) noexcept;
170  status put_uint64(const std::string &key, std::uint64_t value) noexcept;
171  status put_int64(const std::string &key, std::int64_t value) noexcept;
172  status put_string(const std::string &key, const std::string &value) noexcept;
173 
174  status put_size(std::uint64_t size) noexcept;
175  status put_path(const std::string &path) noexcept;
176  status put_force_create(bool value) noexcept;
177  status put_oid(PMEMoid *oid) noexcept;
178  template <typename Comparator>
179  status put_comparator(Comparator &&comparator);
180 
181  template <typename T>
182  status get_data(const std::string &key, T *&value, std::size_t &number) const
183  noexcept;
184  template <typename T>
185  status get_object(const std::string &key, T *&value) const noexcept;
186 
187  status get_uint64(const std::string &key, std::uint64_t &value) const noexcept;
188  status get_int64(const std::string &key, std::int64_t &value) const noexcept;
189  status get_string(const std::string &key, std::string &value) const noexcept;
190 
191  pmemkv_config *release() noexcept;
192 
193 private:
194  int init() noexcept;
195 
196  pmemkv_config *_config;
197 };
198 
211 class db {
212 public:
213  db() noexcept;
214  ~db();
215 
216  db(const db &other) = delete;
217  db(db &&other) noexcept;
218 
219  db &operator=(const db &other) = delete;
220  db &operator=(db &&other) noexcept;
221 
222  status open(const std::string &engine_name) noexcept;
223  status open(const std::string &engine_name, config &&cfg) noexcept;
224 
225  void close() noexcept;
226 
227  status count_all(std::size_t &cnt) noexcept;
228  status count_above(string_view key, std::size_t &cnt) noexcept;
229  status count_equal_above(string_view key, std::size_t &cnt) noexcept;
230  status count_equal_below(string_view key, std::size_t &cnt) noexcept;
231  status count_below(string_view key, std::size_t &cnt) noexcept;
232  status count_between(string_view key1, string_view key2,
233  std::size_t &cnt) noexcept;
234 
235  status get_all(get_kv_callback *callback, void *arg) noexcept;
236  status get_all(std::function<get_kv_function> f) noexcept;
237 
238  status get_above(string_view key, get_kv_callback *callback, void *arg) noexcept;
239  status get_above(string_view key, std::function<get_kv_function> f) noexcept;
240 
241  status get_equal_above(string_view key, get_kv_callback *callback,
242  void *arg) noexcept;
243  status get_equal_above(string_view key,
244  std::function<get_kv_function> f) noexcept;
245 
246  status get_equal_below(string_view key, get_kv_callback *callback,
247  void *arg) noexcept;
248  status get_equal_below(string_view key,
249  std::function<get_kv_function> f) noexcept;
250 
251  status get_below(string_view key, get_kv_callback *callback, void *arg) noexcept;
252  status get_below(string_view key, std::function<get_kv_function> f) noexcept;
253 
254  status get_between(string_view key1, string_view key2, get_kv_callback *callback,
255  void *arg) noexcept;
256  status get_between(string_view key1, string_view key2,
257  std::function<get_kv_function> f) noexcept;
258 
259  status exists(string_view key) noexcept;
260 
261  status get(string_view key, get_v_callback *callback, void *arg) noexcept;
262  status get(string_view key, std::function<get_v_function> f) noexcept;
263  status get(string_view key, std::string *value) noexcept;
264 
265  status put(string_view key, string_view value) noexcept;
266  status remove(string_view key) noexcept;
267  status defrag(double start_percent = 0, double amount_percent = 100);
268 
269  std::string errormsg();
270 
271 private:
272  pmemkv_db *_db;
273 };
274 
282 namespace internal
283 {
284 
285 /*
286  * Abstracts unique_ptr - exposes only void *get() method and a destructor.
287  * This class is needed for C callbacks which cannot be templated
288  * (type of object and deleter must be abstracted away).
289  */
292  {
293  }
294 
295  virtual void *get() = 0;
296 };
297 
298 template <typename T, typename D>
300  unique_ptr_wrapper(std::unique_ptr<T, D> ptr) : ptr(std::move(ptr))
301  {
302  }
303 
304  void *get() override
305  {
306  return ptr.get();
307  }
308 
309  std::unique_ptr<T, D> ptr;
310 };
311 
313 public:
315  {
316  }
317  virtual int compare(string_view key1, string_view key2) = 0;
318 };
319 
320 template <typename Comparator>
322  comparator_wrapper(const Comparator &cmp) : cmp(cmp)
323  {
324  }
325 
326  comparator_wrapper(Comparator &&cmp) : cmp(std::move(cmp))
327  {
328  }
329 
330  int compare(string_view key1, string_view key2) override
331  {
332  return cmp.compare(key1, key2);
333  }
334 
335  Comparator cmp;
336 };
337 
340  std::unique_ptr<comparator_base> ptr,
341  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *>
342  c_cmp)
343  : ptr(std::move(ptr)), c_cmp(std::move(c_cmp))
344  {
345  }
346 
347  void *get() override
348  {
349  return c_cmp.get();
350  }
351 
352  std::unique_ptr<comparator_base> ptr;
353  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *> c_cmp;
354 };
355 
356 /*
357  * All functions which will be called by C code must be declared as extern "C"
358  * to ensure they have C linkage. It is needed because it is possible that
359  * C and C++ functions use different calling conventions.
360  */
361 extern "C" {
362 static inline void call_up_destructor(void *object)
363 {
364  auto *ptr = static_cast<unique_ptr_wrapper_base *>(object);
365  delete ptr;
366 }
367 
368 static inline void *call_up_get(void *object)
369 {
370  auto *ptr = static_cast<unique_ptr_wrapper_base *>(object);
371  return ptr->get();
372 }
373 
374 static inline int call_comparator_function(const char *k1, size_t kb1, const char *k2,
375  size_t kb2, void *arg)
376 {
377  auto *cmp = static_cast<comparator_base *>(arg);
378  return cmp->compare(string_view(k1, kb1), string_view(k2, kb2));
379 }
380 } /* extern "C" */
381 } /* namespace internal */
382 
386 inline config::config() noexcept
387 {
388  this->_config = nullptr;
389 }
390 
395 inline config::config(config &&other) noexcept
396 {
397  this->_config = other._config;
398  other._config = nullptr;
399 }
400 
405 inline config &config::operator=(config &&other) noexcept
406 {
407  if (this == &other)
408  return *this;
409 
410  if (this->_config)
411  pmemkv_config_delete(this->_config);
412 
413  this->_config = other._config;
414  other._config = nullptr;
415 
416  return *this;
417 }
418 
423 inline config::config(pmemkv_config *cfg) noexcept
424 {
425  this->_config = cfg;
426 }
427 
432 {
433  if (this->_config)
434  pmemkv_config_delete(this->_config);
435 }
436 
443 inline int config::init() noexcept
444 {
445  if (this->_config == nullptr) {
446  this->_config = pmemkv_config_new();
447 
448  if (this->_config == nullptr)
449  return 1;
450  }
451 
452  return 0;
453 }
454 
465 template <typename T>
466 inline status config::put_data(const std::string &key, const T *value,
467  const std::size_t count) noexcept
468 {
469  if (init() != 0)
470  return status::UNKNOWN_ERROR;
471 
472  return static_cast<status>(pmemkv_config_put_data(
473  this->_config, key.data(), (void *)value, count * sizeof(T)));
474 }
475 
486 template <typename T>
487 inline status config::put_object(const std::string &key, T *value,
488  void (*deleter)(void *)) noexcept
489 {
490  if (init() != 0)
491  return status::UNKNOWN_ERROR;
492 
493  return static_cast<status>(pmemkv_config_put_object(this->_config, key.data(),
494  (void *)value, deleter));
495 }
496 
505 template <typename T, typename D>
506 inline status config::put_object(const std::string &key,
507  std::unique_ptr<T, D> object) noexcept
508 {
509  if (init() != 0)
510  return status::UNKNOWN_ERROR;
511 
513 
514  try {
515  wrapper = new internal::unique_ptr_wrapper<T, D>(std::move(object));
516  } catch (std::bad_alloc &e) {
517  return status::OUT_OF_MEMORY;
518  } catch (...) {
519  return status::UNKNOWN_ERROR;
520  }
521 
522  return static_cast<status>(pmemkv_config_put_object_cb(
523  this->_config, key.data(), (void *)wrapper, internal::call_up_get,
524  internal::call_up_destructor));
525 }
526 
543 template <typename Comparator>
544 inline status config::put_comparator(Comparator &&comparator)
545 {
546  static_assert(
547  std::is_same<decltype(std::declval<Comparator>().compare(
548  std::declval<string_view>(),
549  std::declval<string_view>())),
550  int>::value,
551  "Comparator should implement `int compare(pmem::kv::string_view, pmem::kv::string_view)` method");
552  static_assert(std::is_convertible<decltype(std::declval<Comparator>().name()),
553  std::string>::value,
554  "Comparator should implement `std::string name()` method");
555 
556  std::unique_ptr<internal::comparator_base> wrapper;
557 
558  try {
559  wrapper = std::unique_ptr<internal::comparator_base>(
561  std::forward<Comparator>(comparator)));
562  } catch (std::bad_alloc &e) {
563  return status::OUT_OF_MEMORY;
564  } catch (...) {
565  return status::UNKNOWN_ERROR;
566  }
567 
568  auto cmp =
569  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *>(
570  pmemkv_comparator_new(&internal::call_comparator_function,
571  std::string(comparator.name()).c_str(),
572  wrapper.get()),
573  &pmemkv_comparator_delete);
574  if (cmp == nullptr)
575  return status::UNKNOWN_ERROR;
576 
578 
579  try {
580  entry = new internal::comparator_config_entry(std::move(wrapper),
581  std::move(cmp));
582  } catch (std::bad_alloc &e) {
583  return status::OUT_OF_MEMORY;
584  } catch (...) {
585  return status::UNKNOWN_ERROR;
586  }
587 
588  return static_cast<status>(pmemkv_config_put_object_cb(
589  this->_config, "comparator", (void *)entry, internal::call_up_get,
590  internal::call_up_destructor));
591 }
592 
601 inline status config::put_uint64(const std::string &key, std::uint64_t value) noexcept
602 {
603  if (init() != 0)
604  return status::UNKNOWN_ERROR;
605 
606  return static_cast<status>(
607  pmemkv_config_put_uint64(this->_config, key.data(), value));
608 }
609 
618 inline status config::put_int64(const std::string &key, std::int64_t value) noexcept
619 {
620  if (init() != 0)
621  return status::UNKNOWN_ERROR;
622 
623  return static_cast<status>(
624  pmemkv_config_put_int64(this->_config, key.data(), value));
625 }
626 
635 inline status config::put_string(const std::string &key,
636  const std::string &value) noexcept
637 {
638  if (init() != 0)
639  return status::UNKNOWN_ERROR;
640 
641  return static_cast<status>(
642  pmemkv_config_put_string(this->_config, key.data(), value.data()));
643 }
644 
652 inline status config::put_size(std::uint64_t size) noexcept
653 {
654  return put_uint64("size", size);
655 }
656 
665 inline status config::put_path(const std::string &path) noexcept
666 {
667  return put_string("path", path);
668 }
669 
677 inline status config::put_force_create(bool value) noexcept
678 {
679  return put_uint64("force_create", value ? 1 : 0);
680 }
681 
691 inline status config::put_oid(PMEMoid *oid) noexcept
692 {
693  if (init() != 0)
694  return status::UNKNOWN_ERROR;
695 
696  return static_cast<status>(pmemkv_config_put_oid(this->_config, oid));
697 }
698 
709 template <typename T>
710 inline status config::get_data(const std::string &key, T *&value,
711  std::size_t &count) const noexcept
712 {
713  if (this->_config == nullptr)
714  return status::NOT_FOUND;
715 
716  std::size_t size;
717  auto s = static_cast<status>(pmemkv_config_get_data(
718  this->_config, key.data(), (const void **)&value, &size));
719 
720  if (s != status::OK)
721  return s;
722 
723  count = size / sizeof(T);
724 
725  return status::OK;
726 }
727 
737 template <typename T>
738 inline status config::get_object(const std::string &key, T *&value) const noexcept
739 {
740  if (this->_config == nullptr)
741  return status::NOT_FOUND;
742 
743  auto s = static_cast<status>(
744  pmemkv_config_get_object(this->_config, key.data(), (void **)&value));
745 
746  return s;
747 }
748 
757 inline status config::get_uint64(const std::string &key, std::uint64_t &value) const
758  noexcept
759 {
760  if (this->_config == nullptr)
761  return status::NOT_FOUND;
762 
763  return static_cast<status>(
764  pmemkv_config_get_uint64(this->_config, key.data(), &value));
765 }
766 
775 inline status config::get_int64(const std::string &key, std::int64_t &value) const
776  noexcept
777 {
778  if (this->_config == nullptr)
779  return status::NOT_FOUND;
780 
781  return static_cast<status>(
782  pmemkv_config_get_int64(this->_config, key.data(), &value));
783 }
784 
793 inline status config::get_string(const std::string &key, std::string &value) const
794  noexcept
795 {
796  if (this->_config == nullptr)
797  return status::NOT_FOUND;
798 
799  const char *data;
800 
801  auto s = static_cast<status>(
802  pmemkv_config_get_string(this->_config, key.data(), &data));
803 
804  if (s != status::OK)
805  return s;
806 
807  value = data;
808 
809  return status::OK;
810 }
811 
818 inline pmemkv_config *config::release() noexcept
819 {
820  auto c = this->_config;
821  this->_config = nullptr;
822  return c;
823 }
824 
825 /*
826  * All functions which will be called by C code must be declared as extern "C"
827  * to ensure they have C linkage. It is needed because it is possible that
828  * C and C++ functions use different calling conventions.
829  */
830 extern "C" {
831 static inline int call_get_kv_function(const char *key, size_t keybytes,
832  const char *value, size_t valuebytes, void *arg)
833 {
834  return (*reinterpret_cast<std::function<get_kv_function> *>(arg))(
835  string_view(key, keybytes), string_view(value, valuebytes));
836 }
837 
838 static inline void call_get_v_function(const char *value, size_t valuebytes, void *arg)
839 {
840  (*reinterpret_cast<std::function<get_v_function> *>(arg))(
841  string_view(value, valuebytes));
842 }
843 
844 static inline void call_get_copy(const char *v, size_t vb, void *arg)
845 {
846  auto c = reinterpret_cast<std::string *>(arg);
847  c->assign(v, vb);
848 }
849 }
850 
854 inline db::db() noexcept
855 {
856  this->_db = nullptr;
857 }
858 
865 inline db::db(db &&other) noexcept
866 {
867  this->_db = other._db;
868  other._db = nullptr;
869 }
870 
878 inline db &db::operator=(db &&other) noexcept
879 {
880  if (this == &other)
881  return *this;
882 
883  close();
884 
885  std::swap(this->_db, other._db);
886 
887  return *this;
888 }
889 
897 inline status db::open(const std::string &engine_name) noexcept
898 {
899  return static_cast<status>(
900  pmemkv_open(engine_name.c_str(), nullptr, &(this->_db)));
901 }
902 
911 inline status db::open(const std::string &engine_name, config &&cfg) noexcept
912 {
913  return static_cast<status>(
914  pmemkv_open(engine_name.c_str(), cfg.release(), &(this->_db)));
915 }
916 
920 inline void db::close() noexcept
921 {
922  if (this->_db != nullptr)
923  pmemkv_close(this->_db);
924 
925  this->_db = nullptr;
926 }
927 
931 inline db::~db()
932 {
933  close();
934 }
935 
943 inline status db::count_all(std::size_t &cnt) noexcept
944 {
945  return static_cast<status>(pmemkv_count_all(this->_db, &cnt));
946 }
947 
958 inline status db::count_above(string_view key, std::size_t &cnt) noexcept
959 {
960  return static_cast<status>(
961  pmemkv_count_above(this->_db, key.data(), key.size(), &cnt));
962 }
963 
974 inline status db::count_equal_above(string_view key, std::size_t &cnt) noexcept
975 {
976  return static_cast<status>(
977  pmemkv_count_equal_above(this->_db, key.data(), key.size(), &cnt));
978 }
979 
990 inline status db::count_equal_below(string_view key, std::size_t &cnt) noexcept
991 {
992  return static_cast<status>(
993  pmemkv_count_equal_below(this->_db, key.data(), key.size(), &cnt));
994 }
995 
1006 inline status db::count_below(string_view key, std::size_t &cnt) noexcept
1007 {
1008  return static_cast<status>(
1009  pmemkv_count_below(this->_db, key.data(), key.size(), &cnt));
1010 }
1011 
1024  std::size_t &cnt) noexcept
1025 {
1026  return static_cast<status>(pmemkv_count_between(
1027  this->_db, key1.data(), key1.size(), key2.data(), key2.size(), &cnt));
1028 }
1029 
1042 inline status db::get_all(get_kv_callback *callback, void *arg) noexcept
1043 {
1044  return static_cast<status>(pmemkv_get_all(this->_db, callback, arg));
1045 }
1046 
1057 inline status db::get_all(std::function<get_kv_function> f) noexcept
1058 {
1059  return static_cast<status>(pmemkv_get_all(this->_db, call_get_kv_function, &f));
1060 }
1061 
1079  void *arg) noexcept
1080 {
1081  return static_cast<status>(
1082  pmemkv_get_above(this->_db, key.data(), key.size(), callback, arg));
1083 }
1084 
1099 inline status db::get_above(string_view key, std::function<get_kv_function> f) noexcept
1100 {
1101  return static_cast<status>(pmemkv_get_above(this->_db, key.data(), key.size(),
1102  call_get_kv_function, &f));
1103 }
1104 
1123  void *arg) noexcept
1124 {
1125  return static_cast<status>(
1126  pmemkv_get_equal_above(this->_db, key.data(), key.size(), callback, arg));
1127 }
1128 
1145  std::function<get_kv_function> f) noexcept
1146 {
1147  return static_cast<status>(pmemkv_get_equal_above(
1148  this->_db, key.data(), key.size(), call_get_kv_function, &f));
1149 }
1150 
1169  void *arg) noexcept
1170 {
1171  return static_cast<status>(
1172  pmemkv_get_equal_below(this->_db, key.data(), key.size(), callback, arg));
1173 }
1174 
1191  std::function<get_kv_function> f) noexcept
1192 {
1193  return static_cast<status>(pmemkv_get_equal_below(
1194  this->_db, key.data(), key.size(), call_get_kv_function, &f));
1195 }
1196 
1214  void *arg) noexcept
1215 {
1216  return static_cast<status>(
1217  pmemkv_get_below(this->_db, key.data(), key.size(), callback, arg));
1218 }
1219 
1234 inline status db::get_below(string_view key, std::function<get_kv_function> f) noexcept
1235 {
1236  return static_cast<status>(pmemkv_get_below(this->_db, key.data(), key.size(),
1237  call_get_kv_function, &f));
1238 }
1239 
1258  get_kv_callback *callback, void *arg) noexcept
1259 {
1260  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
1261  key2.data(), key2.size(), callback,
1262  arg));
1263 }
1280  std::function<get_kv_function> f) noexcept
1281 {
1282  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
1283  key2.data(), key2.size(),
1284  call_get_kv_function, &f));
1285 }
1286 
1296 inline status db::exists(string_view key) noexcept
1297 {
1298  return static_cast<status>(pmemkv_exists(this->_db, key.data(), key.size()));
1299 }
1300 
1316 inline status db::get(string_view key, get_v_callback *callback, void *arg) noexcept
1317 {
1318  return static_cast<status>(
1319  pmemkv_get(this->_db, key.data(), key.size(), callback, arg));
1320 }
1321 
1333 inline status db::get(string_view key, std::function<get_v_function> f) noexcept
1334 {
1335  return static_cast<status>(
1336  pmemkv_get(this->_db, key.data(), key.size(), call_get_v_function, &f));
1337 }
1338 
1349 inline status db::get(string_view key, std::string *value) noexcept
1350 {
1351  return static_cast<status>(
1352  pmemkv_get(this->_db, key.data(), key.size(), call_get_copy, value));
1353 }
1354 
1364 inline status db::put(string_view key, string_view value) noexcept
1365 {
1366  return static_cast<status>(pmemkv_put(this->_db, key.data(), key.size(),
1367  value.data(), value.size()));
1368 }
1369 
1378 inline status db::remove(string_view key) noexcept
1379 {
1380  return static_cast<status>(pmemkv_remove(this->_db, key.data(), key.size()));
1381 }
1382 
1392 inline status db::defrag(double start_percent, double amount_percent)
1393 
1394 {
1395  return static_cast<status>(
1396  pmemkv_defrag(this->_db, start_percent, amount_percent));
1397 }
1398 
1406 inline std::string db::errormsg()
1407 {
1408  return std::string(pmemkv_errormsg());
1409 }
1410 
1416 static inline std::string errormsg()
1417 {
1418  return std::string(pmemkv_errormsg());
1419 }
1420 
1421 } /* namespace kv */
1422 } /* namespace pmem */
1423 
1424 #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:635
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:487
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:793
pmem::kv::internal::comparator_wrapper::comparator_wrapper
comparator_wrapper(const Comparator &cmp)
Definition: libpmemkv.hpp:322
pmem::kv::db::db
db() noexcept
Default constructor with uninitialized database.
Definition: libpmemkv.hpp:854
pmem::kv::internal::comparator_config_entry::ptr
std::unique_ptr< comparator_base > ptr
Definition: libpmemkv.hpp:352
pmem::kv::db::~db
~db()
Default destructor.
Definition: libpmemkv.hpp:931
pmem::kv::config
Holds configuration parameters for engines.
Definition: libpmemkv.hpp:148
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:1316
pmem::kv::config::put_force_create
status put_force_create(bool value) noexcept
Puts force_create parameter to a config, For supporting engines If false, pmemkv opens file specified...
Definition: libpmemkv.hpp:677
pmem::kv::db::close
void close() noexcept
Closes pmemkv database.
Definition: libpmemkv.hpp:920
pmem::kv::internal::unique_ptr_wrapper::unique_ptr_wrapper
unique_ptr_wrapper(std::unique_ptr< T, D > ptr)
Definition: libpmemkv.hpp:300
pmem::kv::status
status
Status returned by pmemkv functions.
Definition: libpmemkv.hpp:76
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:775
pmem::kv::config::put_size
status put_size(std::uint64_t size) noexcept
Puts size to a config.
Definition: libpmemkv.hpp:652
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:818
pmem::kv::operator<<
std::ostream & operator<<(std::ostream &os, const status &s)
Definition: libpmemkv.hpp:107
pmem::kv::db::open
status open(const std::string &engine_name) noexcept
Opens the pmemkv database without any configuration parameters.
Definition: libpmemkv.hpp:897
pmem::kv::config::put_oid
status put_oid(PMEMoid *oid) noexcept
Puts PMEMoid object to a config.
Definition: libpmemkv.hpp:691
pmem::kv::internal::comparator_config_entry
Definition: libpmemkv.hpp:338
pmem::kv::string_view
obj::string_view string_view
Definition: libpmemkv.hpp:42
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:50
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:618
pmem::kv::internal::comparator_base
Definition: libpmemkv.hpp:312
pmem::kv::internal::unique_ptr_wrapper_base
Definition: libpmemkv.hpp:290
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:1042
pmem::kv::internal::unique_ptr_wrapper::get
void * get() override
Definition: libpmemkv.hpp:304
pmem::kv::internal::comparator_wrapper
Definition: libpmemkv.hpp:321
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:974
pmem::kv::db
Main pmemkv class, it provides functions to operate on data in database.
Definition: libpmemkv.hpp:211
pmem::kv::db::db
db(const db &other)=delete
pmem::kv::config::_config
pmemkv_config * _config
Definition: libpmemkv.hpp:196
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:339
pmem::kv::config::put_comparator
status put_comparator(Comparator &&comparator)
Puts comparator object to a config.
Definition: libpmemkv.hpp:544
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:1168
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:1257
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:1392
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:1078
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:57
pmem::kv::comparator_function
int comparator_function(string_view key1, string_view key2)
Definition: libpmemkv.hpp:59
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:1006
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:710
pmem::kv::config::init
int init() noexcept
Initialization function for config.
Definition: libpmemkv.hpp:443
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:466
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:943
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:757
pmem::kv::internal::comparator_wrapper::comparator_wrapper
comparator_wrapper(Comparator &&cmp)
Definition: libpmemkv.hpp:326
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:1122
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:1213
pmem::kv::internal::unique_ptr_wrapper_base::~unique_ptr_wrapper_base
virtual ~unique_ptr_wrapper_base()
Definition: libpmemkv.hpp:291
pmem::kv::db::remove
status remove(string_view key) noexcept
Removes from database record with given key.
Definition: libpmemkv.hpp:1378
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:64
pmem::kv::db::errormsg
std::string errormsg()
Returns a human readable string describing the last error.
Definition: libpmemkv.hpp:1406
pmem::kv::internal::comparator_config_entry::c_cmp
std::unique_ptr< pmemkv_comparator, decltype(pmemkv_comparator_delete) * > c_cmp
Definition: libpmemkv.hpp:353
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:990
pmem::kv::internal::unique_ptr_wrapper::ptr
std::unique_ptr< T, D > ptr
Definition: libpmemkv.hpp:309
pmem::kv::get_v_callback
pmemkv_get_v_callback get_v_callback
Value-only callback, C-style.
Definition: libpmemkv.hpp:68
pmem::kv::internal::comparator_config_entry::get
void * get() override
Definition: libpmemkv.hpp:347
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:958
pmem::kv::internal::unique_ptr_wrapper
Definition: libpmemkv.hpp:299
pmem::kv::config::~config
~config()
Default destructor.
Definition: libpmemkv.hpp:431
pmem::kv::config::config
config() noexcept
Default constructor with uninitialized config.
Definition: libpmemkv.hpp:386
pmem::kv::db::exists
status exists(string_view key) noexcept
Checks existence of record with given key.
Definition: libpmemkv.hpp:1296
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:601
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:738
pmem::kv::config::config
config(const config &other)=delete
pmem::kv::config::put_path
status put_path(const std::string &path) noexcept
Puts path to a config.
Definition: libpmemkv.hpp:665
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:1023
pmem::kv::db::put
status put(string_view key, string_view value) noexcept
Inserts a key-value pair into pmemkv database.
Definition: libpmemkv.hpp:1364
pmem::kv::internal::comparator_wrapper::cmp
Comparator cmp
Definition: libpmemkv.hpp:335
pmem::kv::internal::comparator_wrapper::compare
int compare(string_view key1, string_view key2) override
Definition: libpmemkv.hpp:330
pmem::kv::internal::comparator_base::~comparator_base
virtual ~comparator_base()
Definition: libpmemkv.hpp:314