PMEMKV  1.4.1-git1.g7db5b8f
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-2021, Intel Corporation */
3 
4 #ifndef LIBPMEMKV_HPP
5 #define LIBPMEMKV_HPP
6 
7 #include <cassert>
8 #include <functional>
9 #include <iostream>
10 #include <libpmemobj++/slice.hpp>
11 #include <libpmemobj++/string_view.hpp>
12 #include <memory>
13 #include <stdexcept>
14 #include <string>
15 #include <utility>
16 
17 #include "libpmemkv.h"
18 #include <libpmemobj/pool_base.h>
19 
33 namespace pmem
34 {
41 namespace kv
42 {
48 
55 typedef int get_kv_function(string_view key, string_view value);
62 typedef void get_v_function(string_view value);
63 
67 using get_kv_callback = pmemkv_get_kv_callback;
71 using get_v_callback = pmemkv_get_v_callback;
72 
84 enum class status {
85  OK = PMEMKV_STATUS_OK,
86  UNKNOWN_ERROR = PMEMKV_STATUS_UNKNOWN_ERROR,
87  NOT_FOUND = PMEMKV_STATUS_NOT_FOUND,
88  NOT_SUPPORTED = PMEMKV_STATUS_NOT_SUPPORTED,
90  INVALID_ARGUMENT = PMEMKV_STATUS_INVALID_ARGUMENT,
92  CONFIG_PARSING_ERROR =
93  PMEMKV_STATUS_CONFIG_PARSING_ERROR,
94  CONFIG_TYPE_ERROR =
95  PMEMKV_STATUS_CONFIG_TYPE_ERROR,
97  STOPPED_BY_CB = PMEMKV_STATUS_STOPPED_BY_CB,
99  OUT_OF_MEMORY =
100  PMEMKV_STATUS_OUT_OF_MEMORY,
102  WRONG_ENGINE_NAME =
103  PMEMKV_STATUS_WRONG_ENGINE_NAME,
105  TRANSACTION_SCOPE_ERROR =
106  PMEMKV_STATUS_TRANSACTION_SCOPE_ERROR,
108  DEFRAG_ERROR = PMEMKV_STATUS_DEFRAG_ERROR,
111  PMEMKV_STATUS_COMPARATOR_MISMATCH,
113 };
114 
124 inline std::ostream &operator<<(std::ostream &os, const status &s)
125 {
126  static const std::string statuses[] = {"OK",
127  "UNKNOWN_ERROR",
128  "NOT_FOUND",
129  "NOT_SUPPORTED",
130  "INVALID_ARGUMENT",
131  "CONFIG_PARSING_ERROR",
132  "CONFIG_TYPE_ERROR",
133  "STOPPED_BY_CB",
134  "OUT_OF_MEMORY",
135  "WRONG_ENGINE_NAME",
136  "TRANSACTION_SCOPE_ERROR",
137  "DEFRAG_ERROR",
138  "COMPARATOR_MISMATCH"};
139 
140  int status_no = static_cast<int>(s);
141  os << statuses[status_no] << " (" << status_no << ")";
142 
143  return os;
144 }
145 
150 class bad_result_access : public std::runtime_error {
151 public:
152  bad_result_access(const char *what_arg) : std::runtime_error(what_arg)
153  {
154  }
155 
156  const char *what() const noexcept final
157  {
158  return std::runtime_error::what();
159  }
160 
161 private:
162 };
163 
174 template <typename T>
175 class result {
176  union {
177  T value;
178  };
179 
181 
182 public:
183  result(const T &val) noexcept(noexcept(T(std::declval<T>())));
184  result(const status &err) noexcept;
185  result(const result &other) noexcept(noexcept(T(std::declval<T>())));
186  result(result &&other) noexcept(noexcept(T(std::declval<T>())));
187  result(T &&val) noexcept(noexcept(T(std::declval<T>())));
188 
189  ~result();
190 
191  result &
192  operator=(const result &other) noexcept(noexcept(std::declval<T>().~T()) &&
193  noexcept(T(std::declval<T>())));
194  result &operator=(result &&other) noexcept(noexcept(std::declval<T>().~T()) &&
195  noexcept(T(std::declval<T>())));
196 
197  bool is_ok() const noexcept;
198 
199  const T &get_value() const &;
200  T &get_value() &;
201 
202  T &&get_value() &&;
203 
204  status get_status() const noexcept;
205 };
206 
212 template <typename T>
213 result<T>::result(const T &val) noexcept(noexcept(T(std::declval<T>())))
214  : value(val), s(status::OK)
215 {
216 }
217 
223 template <typename T>
225 {
226  assert(s != status::OK);
227 }
228 
234 template <typename T>
235 result<T>::result(const result &other) noexcept(noexcept(T(std::declval<T>())))
236  : s(other.s)
237 {
238  if (s == status::OK)
239  new (&value) T(other.value);
240 }
241 
247 template <typename T>
248 result<T>::result(result &&other) noexcept(noexcept(T(std::declval<T>()))) : s(other.s)
249 {
250  if (s == status::OK)
251  new (&value) T(std::move(other.value));
252 
253  other.s = status::UNKNOWN_ERROR;
254 }
255 
259 template <typename T>
261 {
262  if (s == status::OK)
263  value.~T();
264 }
265 
271 template <typename T>
272 result<T> &
273 result<T>::operator=(const result &other) noexcept(noexcept(std::declval<T>().~T()) &&
274  noexcept(T(std::declval<T>())))
275 {
276  if (s == status::OK && other.is_ok())
277  value = other.value;
278  else if (other.is_ok())
279  new (&value) T(other.value);
280  else if (s == status::OK)
281  value.~T();
282 
283  s = other.s;
284 
285  return *this;
286 }
287 
293 template <typename T>
294 result<T> &
295 result<T>::operator=(result &&other) noexcept(noexcept(std::declval<T>().~T()) &&
296  noexcept(T(std::declval<T>())))
297 {
298  if (s == status::OK && other.is_ok())
299  value = std::move(other.value);
300  else if (other.is_ok())
301  new (&value) T(std::move(other.value));
302  else if (s == status::OK)
303  value.~T();
304 
305  s = other.s;
306  other.s = status::UNKNOWN_ERROR;
307 
308  return *this;
309 }
310 
316 template <typename T>
317 result<T>::result(T &&val) noexcept(noexcept(T(std::declval<T>())))
318  : value(std::move(val)), s(status::OK)
319 {
320 }
321 
327 template <typename T>
328 bool result<T>::is_ok() const noexcept
329 {
330  return s == status::OK;
331 }
332 
342 template <typename T>
343 const T &result<T>::get_value() const &
344 {
345  if (s == status::OK)
346  return value;
347  else
348  throw bad_result_access("bad_result_access: value doesn't exist");
349 }
350 
360 template <typename T>
362 {
363  if (s == status::OK)
364  return value;
365  else
366  throw bad_result_access("bad_result_access: value doesn't exist");
367 }
368 
378 template <typename T>
380 {
381  if (s == status::OK) {
382  s = status::UNKNOWN_ERROR;
383  return std::move(value);
384  } else
385  throw bad_result_access("bad_result_access: value doesn't exist");
386 }
387 
396 template <typename T>
398 {
399  return s;
400 }
401 
402 template <typename T>
403 bool operator==(const result<T> &lhs, const status &rhs)
404 {
405  return lhs.get_status() == rhs;
406 }
407 
408 template <typename T>
409 bool operator==(const status &lhs, const result<T> &rhs)
410 {
411  return lhs == rhs.get_status();
412 }
413 
414 template <typename T>
415 bool operator!=(const result<T> &lhs, const status &rhs)
416 {
417  return lhs.get_status() != rhs;
418 }
419 
420 template <typename T>
421 bool operator!=(const status &lhs, const result<T> &rhs)
422 {
423  return lhs != rhs.get_status();
424 }
425 
445 class config {
446 public:
447  config() noexcept;
448  explicit config(pmemkv_config *cfg) noexcept;
449 
450  template <typename T>
451  status put_data(const std::string &key, const T *value,
452  const std::size_t number = 1) noexcept;
453 
454  template <typename T>
455  status put_object(const std::string &key, T *value,
456  void (*deleter)(void *)) noexcept;
457  template <typename T, typename D>
458  status put_object(const std::string &key, std::unique_ptr<T, D> object) noexcept;
459  status put_uint64(const std::string &key, std::uint64_t value) noexcept;
460  status put_int64(const std::string &key, std::int64_t value) noexcept;
461  status put_string(const std::string &key, const std::string &value) noexcept;
462 
463  status put_size(std::uint64_t size) noexcept;
464  status put_path(const std::string &path) noexcept;
465  status put_force_create(bool value) noexcept;
466  status put_oid(PMEMoid *oid) noexcept;
467  template <typename Comparator>
468  status put_comparator(Comparator &&comparator);
469 
470  template <typename T>
471  status get_data(const std::string &key, T *&value, std::size_t &number) const
472  noexcept;
473  template <typename T>
474  status get_object(const std::string &key, T *&value) const noexcept;
475 
476  status get_uint64(const std::string &key, std::uint64_t &value) const noexcept;
477  status get_int64(const std::string &key, std::int64_t &value) const noexcept;
478  status get_string(const std::string &key, std::string &value) const noexcept;
479 
480  pmemkv_config *release() noexcept;
481 
482 private:
483  int init() noexcept;
484 
485  std::unique_ptr<pmemkv_config, decltype(&pmemkv_config_delete)> config_;
486 };
487 
503 class tx {
504 public:
505  tx(pmemkv_tx *tx_) noexcept;
506 
507  status put(string_view key, string_view value) noexcept;
508  status remove(string_view key) noexcept;
509  status commit() noexcept;
510  void abort() noexcept;
511 
512 private:
513  std::unique_ptr<pmemkv_tx, decltype(&pmemkv_tx_end)> tx_;
514 };
515 
537 class db {
538  template <bool IsConst>
539  class iterator;
540 
541 public:
544 
545  db() noexcept;
546 
547  status open(const std::string &engine_name, config &&cfg = config{}) noexcept;
548 
549  void close() noexcept;
550 
551  status count_all(std::size_t &cnt) noexcept;
552  status count_above(string_view key, std::size_t &cnt) noexcept;
553  status count_equal_above(string_view key, std::size_t &cnt) noexcept;
554  status count_equal_below(string_view key, std::size_t &cnt) noexcept;
555  status count_below(string_view key, std::size_t &cnt) noexcept;
556  status count_between(string_view key1, string_view key2,
557  std::size_t &cnt) noexcept;
558 
559  status get_all(get_kv_callback *callback, void *arg) noexcept;
560  status get_all(std::function<get_kv_function> f) noexcept;
561 
562  status get_above(string_view key, get_kv_callback *callback, void *arg) noexcept;
563  status get_above(string_view key, std::function<get_kv_function> f) noexcept;
564 
565  status get_equal_above(string_view key, get_kv_callback *callback,
566  void *arg) noexcept;
567  status get_equal_above(string_view key,
568  std::function<get_kv_function> f) noexcept;
569 
570  status get_equal_below(string_view key, get_kv_callback *callback,
571  void *arg) noexcept;
572  status get_equal_below(string_view key,
573  std::function<get_kv_function> f) noexcept;
574 
575  status get_below(string_view key, get_kv_callback *callback, void *arg) noexcept;
576  status get_below(string_view key, std::function<get_kv_function> f) noexcept;
577 
578  status get_between(string_view key1, string_view key2, get_kv_callback *callback,
579  void *arg) noexcept;
580  status get_between(string_view key1, string_view key2,
581  std::function<get_kv_function> f) noexcept;
582 
583  status exists(string_view key) noexcept;
584 
585  status get(string_view key, get_v_callback *callback, void *arg) noexcept;
586  status get(string_view key, std::function<get_v_function> f) noexcept;
587  status get(string_view key, std::string *value) noexcept;
588 
589  status put(string_view key, string_view value) noexcept;
590  status remove(string_view key) noexcept;
591  status defrag(double start_percent = 0, double amount_percent = 100);
592 
593  result<tx> tx_begin() noexcept;
594 
595  result<read_iterator> new_read_iterator();
596  result<write_iterator> new_write_iterator();
597 
598  std::string errormsg();
599 
600 private:
601  std::unique_ptr<pmemkv_db, decltype(&pmemkv_close)> db_;
602 };
603 
625 template <bool IsConst>
626 class db::iterator {
627  using iterator_type = typename std::conditional<IsConst, pmemkv_iterator,
628  pmemkv_write_iterator>::type;
629 
630  template <typename T>
631  class OutputIterator;
632 
633 public:
635 
636  status seek(string_view key) noexcept;
637  status seek_lower(string_view key) noexcept;
638  status seek_lower_eq(string_view key) noexcept;
639  status seek_higher(string_view key) noexcept;
640  status seek_higher_eq(string_view key) noexcept;
641 
642  status seek_to_first() noexcept;
643  status seek_to_last() noexcept;
644 
645  status is_next() noexcept;
646  status next() noexcept;
647  status prev() noexcept;
648 
649  result<string_view> key() noexcept;
650 
652  read_range(size_t pos = 0,
653  size_t n = std::numeric_limits<size_t>::max()) noexcept;
654 
655  template <bool IC = IsConst>
656  typename std::enable_if<!IC, result<pmem::obj::slice<OutputIterator<char>>>>::type
657  write_range(size_t pos = 0,
658  size_t n = std::numeric_limits<size_t>::max()) noexcept;
659 
660  template <bool IC = IsConst>
661  typename std::enable_if<!IC, status>::type commit() noexcept;
662  template <bool IC = IsConst>
663  typename std::enable_if<!IC>::type abort() noexcept;
664 
665 private:
666  std::unique_ptr<
668  typename std::conditional<IsConst, decltype(&pmemkv_iterator_delete),
669  decltype(&pmemkv_write_iterator_delete)>::type>
670  it_;
671 
672  pmemkv_iterator *get_raw_it();
673 };
674 
679 template <bool IsConst>
680 template <typename T>
681 class db::iterator<IsConst>::OutputIterator {
682  struct assign_only;
683 
684 public:
686  using pointer = void;
687  using difference_type = std::ptrdiff_t;
688  using value_type = void;
689  using iterator_category = std::output_iterator_tag;
690 
691  OutputIterator(T *x);
692 
693  reference operator*();
694 
695  OutputIterator &operator++();
696  OutputIterator operator++(int);
697 
698  OutputIterator &operator--();
699  OutputIterator operator--(int);
700 
701  assign_only operator[](difference_type pos);
702 
703  difference_type operator-(const OutputIterator &other) const;
704 
705  bool operator!=(const OutputIterator &other) const;
706 
707 private:
708  struct assign_only {
710 
711  assign_only(T *x);
712 
713  assign_only &operator=(const T &x);
714 
715  private:
716  T *c;
717  };
718 
720 };
721 
722 template <bool IsConst>
723 template <typename T>
725 {
726 }
727 
728 template <bool IsConst>
729 template <typename T>
732 {
733  return ao;
734 }
735 
736 template <bool IsConst>
737 template <typename T>
740 {
741  ao.c += sizeof(T);
742  return *this;
743 }
744 
745 template <bool IsConst>
746 template <typename T>
749 {
750  auto tmp = *this;
751  ++(*this);
752  return tmp;
753 }
754 
755 template <bool IsConst>
756 template <typename T>
759 {
760  ao.c -= sizeof(T);
761  return *this;
762 }
763 
764 template <bool IsConst>
765 template <typename T>
768 {
769  auto tmp = *this;
770  --(*this);
771  return tmp;
772 }
773 
774 template <bool IsConst>
775 template <typename T>
778 {
779  return assign_only(ao.c + pos);
780 }
781 
782 template <bool IsConst>
783 template <typename T>
786 {
787  return this->ao.c - other.ao.c;
788 }
789 
790 template <bool IsConst>
791 template <typename T>
793  const OutputIterator &other) const
794 {
795  return this->ao.c != other.ao.c;
796 }
797 
798 template <bool IsConst>
799 template <typename T>
801 {
802 }
803 
804 template <bool IsConst>
805 template <typename T>
808 {
809  *c = x;
810  return *this;
811 }
812 
813 template <>
814 inline db::iterator<true>::iterator(iterator_type *it) : it_(it, &pmemkv_iterator_delete)
815 {
816 }
817 
818 template <>
820  : it_(it, &pmemkv_write_iterator_delete)
821 {
822 }
823 
837 template <bool IsConst>
839 {
840  return static_cast<status>(
841  pmemkv_iterator_seek(this->get_raw_it(), key.data(), key.size()));
842 }
843 
857 template <bool IsConst>
859 {
860  return static_cast<status>(
861  pmemkv_iterator_seek_lower(this->get_raw_it(), key.data(), key.size()));
862 }
863 
877 template <bool IsConst>
879 {
880  return static_cast<status>(pmemkv_iterator_seek_lower_eq(this->get_raw_it(),
881  key.data(), key.size()));
882 }
883 
897 template <bool IsConst>
899 {
900  return static_cast<status>(
901  pmemkv_iterator_seek_higher(this->get_raw_it(), key.data(), key.size()));
902 }
903 
917 template <bool IsConst>
919 {
920  return static_cast<status>(pmemkv_iterator_seek_higher_eq(
921  this->get_raw_it(), key.data(), key.size()));
922 }
923 
935 template <bool IsConst>
937 {
938  return static_cast<status>(pmemkv_iterator_seek_to_first(this->get_raw_it()));
939 }
940 
952 template <bool IsConst>
954 {
955  return static_cast<status>(pmemkv_iterator_seek_to_last(this->get_raw_it()));
956 }
957 
968 template <bool IsConst>
970 {
971  return static_cast<status>(pmemkv_iterator_is_next(this->get_raw_it()));
972 }
973 
987 template <bool IsConst>
989 {
990  return static_cast<status>(pmemkv_iterator_next(this->get_raw_it()));
991 }
992 
1006 template <bool IsConst>
1008 {
1009  return static_cast<status>(pmemkv_iterator_prev(this->get_raw_it()));
1010 }
1011 
1021 template <bool IsConst>
1023 {
1024  const char *c;
1025  size_t size;
1026  auto s = static_cast<status>(pmemkv_iterator_key(this->get_raw_it(), &c, &size));
1027 
1028  if (s == status::OK)
1029  return {string_view{c, size}};
1030  else
1031  return {s};
1032 }
1033 
1050 template <bool IsConst>
1052  size_t n) noexcept
1053 {
1054  const char *data;
1055  size_t size;
1056  auto s = static_cast<status>(
1057  pmemkv_iterator_read_range(this->get_raw_it(), pos, n, &data, &size));
1058 
1059  if (s == status::OK)
1060  return {string_view{data, size}};
1061  else
1062  return {s};
1063 }
1064 
1084 template <>
1085 template <>
1087 db::iterator<false>::write_range(size_t pos, size_t n) noexcept
1088 {
1089  char *data;
1090  size_t size;
1091  auto s = static_cast<status>(
1092  pmemkv_write_iterator_write_range(this->it_.get(), pos, n, &data, &size));
1093 
1094  if (s == status::OK) {
1095  try {
1096  return {{data, data + size}};
1097  } catch (std::out_of_range &e) {
1098  return {status::INVALID_ARGUMENT};
1099  }
1100  } else
1101  return {s};
1102 }
1103 
1113 template <>
1114 template <>
1116 {
1117  auto s = static_cast<status>(pmemkv_write_iterator_commit(this->it_.get()));
1118  return s;
1119 }
1120 
1124 template <>
1125 template <>
1126 inline void db::iterator<false>::abort() noexcept
1127 {
1128  pmemkv_write_iterator_abort(this->it_.get());
1129 }
1130 
1131 template <>
1132 inline pmemkv_iterator *db::iterator<true>::get_raw_it()
1133 {
1134  return it_.get();
1135 }
1136 
1137 template <>
1138 inline pmemkv_iterator *db::iterator<false>::get_raw_it()
1139 {
1140  return it_.get()->iter;
1141 }
1142 
1149 namespace internal
1150 {
1151 
1152 /*
1153  * Abstracts unique_ptr - exposes only void *get() method and a destructor.
1154  * This class is needed for C callbacks which cannot be templated
1155  * (type of object and deleter must be abstracted away).
1156  */
1159  {
1160  }
1161 
1162  virtual void *get() = 0;
1163 };
1164 
1165 template <typename T, typename D>
1167  unique_ptr_wrapper(std::unique_ptr<T, D> ptr) : ptr(std::move(ptr))
1168  {
1169  }
1170 
1171  void *get() override
1172  {
1173  return ptr.get();
1174  }
1175 
1176  std::unique_ptr<T, D> ptr;
1177 };
1178 
1180 public:
1182  {
1183  }
1184  virtual int compare(string_view key1, string_view key2) = 0;
1185 };
1186 
1187 template <typename Comparator>
1189  comparator_wrapper(const Comparator &cmp) : cmp(cmp)
1190  {
1191  }
1192 
1193  comparator_wrapper(Comparator &&cmp) : cmp(std::move(cmp))
1194  {
1195  }
1196 
1197  int compare(string_view key1, string_view key2) override
1198  {
1199  return cmp.compare(key1, key2);
1200  }
1201 
1202  Comparator cmp;
1203 };
1204 
1207  std::unique_ptr<comparator_base> ptr,
1208  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *>
1209  c_cmp)
1210  : ptr(std::move(ptr)), c_cmp(std::move(c_cmp))
1211  {
1212  }
1213 
1214  void *get() override
1215  {
1216  return c_cmp.get();
1217  }
1218 
1219  std::unique_ptr<comparator_base> ptr;
1220  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *> c_cmp;
1221 };
1222 
1223 /*
1224  * All functions which will be called by C code must be declared as extern "C"
1225  * to ensure they have C linkage. It is needed because it is possible that
1226  * C and C++ functions use different calling conventions.
1227  */
1228 extern "C" {
1229 static inline void call_up_destructor(void *object)
1230 {
1231  auto *ptr = static_cast<unique_ptr_wrapper_base *>(object);
1232  delete ptr;
1233 }
1234 
1235 static inline void *call_up_get(void *object)
1236 {
1237  auto *ptr = static_cast<unique_ptr_wrapper_base *>(object);
1238  return ptr->get();
1239 }
1240 
1241 static inline int call_comparator_function(const char *k1, size_t kb1, const char *k2,
1242  size_t kb2, void *arg)
1243 {
1244  auto *cmp = static_cast<comparator_base *>(arg);
1245  return cmp->compare(string_view(k1, kb1), string_view(k2, kb2));
1246 }
1247 } /* extern "C" */
1248 } /* namespace internal */
1249 
1253 inline config::config() noexcept : config_(nullptr, &pmemkv_config_delete)
1254 {
1255 }
1256 
1261 inline config::config(pmemkv_config *cfg) noexcept : config_(cfg, &pmemkv_config_delete)
1262 {
1263 }
1264 
1271 inline int config::init() noexcept
1272 {
1273  if (this->config_.get() == nullptr) {
1274  this->config_ = {pmemkv_config_new(), &pmemkv_config_delete};
1275 
1276  if (this->config_.get() == nullptr)
1277  return 1;
1278  }
1279 
1280  return 0;
1281 }
1282 
1293 template <typename T>
1294 inline status config::put_data(const std::string &key, const T *value,
1295  const std::size_t count) noexcept
1296 {
1297  if (init() != 0)
1298  return status::UNKNOWN_ERROR;
1299 
1300  return static_cast<status>(pmemkv_config_put_data(
1301  this->config_.get(), key.data(), (void *)value, count * sizeof(T)));
1302 }
1303 
1314 template <typename T>
1315 inline status config::put_object(const std::string &key, T *value,
1316  void (*deleter)(void *)) noexcept
1317 {
1318  if (init() != 0)
1319  return status::UNKNOWN_ERROR;
1320 
1321  return static_cast<status>(pmemkv_config_put_object(
1322  this->config_.get(), key.data(), (void *)value, deleter));
1323 }
1324 
1333 template <typename T, typename D>
1334 inline status config::put_object(const std::string &key,
1335  std::unique_ptr<T, D> object) noexcept
1336 {
1337  if (init() != 0)
1338  return status::UNKNOWN_ERROR;
1339 
1341 
1342  try {
1343  wrapper = new internal::unique_ptr_wrapper<T, D>(std::move(object));
1344  } catch (std::bad_alloc &e) {
1345  return status::OUT_OF_MEMORY;
1346  } catch (...) {
1347  return status::UNKNOWN_ERROR;
1348  }
1349 
1350  return static_cast<status>(pmemkv_config_put_object_cb(
1351  this->config_.get(), key.data(), (void *)wrapper, internal::call_up_get,
1352  internal::call_up_destructor));
1353 }
1354 
1374 template <typename Comparator>
1375 inline status config::put_comparator(Comparator &&comparator)
1376 {
1377  static_assert(
1378  std::is_same<decltype(std::declval<Comparator>().compare(
1379  std::declval<string_view>(),
1380  std::declval<string_view>())),
1381  int>::value,
1382  "Comparator should implement `int compare(pmem::kv::string_view, pmem::kv::string_view)` method");
1383  static_assert(std::is_convertible<decltype(std::declval<Comparator>().name()),
1384  std::string>::value,
1385  "Comparator should implement `std::string name()` method");
1386 
1387  std::unique_ptr<internal::comparator_base> wrapper;
1388 
1389  try {
1390  wrapper = std::unique_ptr<internal::comparator_base>(
1392  std::forward<Comparator>(comparator)));
1393  } catch (std::bad_alloc &e) {
1394  return status::OUT_OF_MEMORY;
1395  } catch (...) {
1396  return status::UNKNOWN_ERROR;
1397  }
1398 
1399  auto cmp =
1400  std::unique_ptr<pmemkv_comparator, decltype(pmemkv_comparator_delete) *>(
1401  pmemkv_comparator_new(&internal::call_comparator_function,
1402  std::string(comparator.name()).c_str(),
1403  wrapper.get()),
1404  &pmemkv_comparator_delete);
1405  if (cmp == nullptr)
1406  return status::UNKNOWN_ERROR;
1407 
1409 
1410  try {
1411  entry = new internal::comparator_config_entry(std::move(wrapper),
1412  std::move(cmp));
1413  } catch (std::bad_alloc &e) {
1414  return status::OUT_OF_MEMORY;
1415  } catch (...) {
1416  return status::UNKNOWN_ERROR;
1417  }
1418 
1419  return static_cast<status>(pmemkv_config_put_object_cb(
1420  this->config_.get(), "comparator", (void *)entry, internal::call_up_get,
1421  internal::call_up_destructor));
1422 }
1423 
1432 inline status config::put_uint64(const std::string &key, std::uint64_t value) noexcept
1433 {
1434  if (init() != 0)
1435  return status::UNKNOWN_ERROR;
1436 
1437  return static_cast<status>(
1438  pmemkv_config_put_uint64(this->config_.get(), key.data(), value));
1439 }
1440 
1449 inline status config::put_int64(const std::string &key, std::int64_t value) noexcept
1450 {
1451  if (init() != 0)
1452  return status::UNKNOWN_ERROR;
1453 
1454  return static_cast<status>(
1455  pmemkv_config_put_int64(this->config_.get(), key.data(), value));
1456 }
1457 
1466 inline status config::put_string(const std::string &key,
1467  const std::string &value) noexcept
1468 {
1469  if (init() != 0)
1470  return status::UNKNOWN_ERROR;
1471 
1472  return static_cast<status>(
1473  pmemkv_config_put_string(this->config_.get(), key.data(), value.data()));
1474 }
1475 
1483 inline status config::put_size(std::uint64_t size) noexcept
1484 {
1485  return put_uint64("size", size);
1486 }
1487 
1496 inline status config::put_path(const std::string &path) noexcept
1497 {
1498  return put_string("path", path);
1499 }
1500 
1508 inline status config::put_force_create(bool value) noexcept
1509 {
1510  return put_uint64("force_create", value ? 1 : 0);
1511 }
1512 
1522 inline status config::put_oid(PMEMoid *oid) noexcept
1523 {
1524  if (init() != 0)
1525  return status::UNKNOWN_ERROR;
1526 
1527  return static_cast<status>(pmemkv_config_put_oid(this->config_.get(), oid));
1528 }
1529 
1540 template <typename T>
1541 inline status config::get_data(const std::string &key, T *&value,
1542  std::size_t &count) const noexcept
1543 {
1544  if (this->config_.get() == nullptr)
1545  return status::NOT_FOUND;
1546 
1547  std::size_t size;
1548  auto s = static_cast<status>(pmemkv_config_get_data(
1549  this->config_.get(), key.data(), (const void **)&value, &size));
1550 
1551  if (s != status::OK)
1552  return s;
1553 
1554  count = size / sizeof(T);
1555 
1556  return status::OK;
1557 }
1558 
1568 template <typename T>
1569 inline status config::get_object(const std::string &key, T *&value) const noexcept
1570 {
1571  if (this->config_.get() == nullptr)
1572  return status::NOT_FOUND;
1573 
1574  auto s = static_cast<status>(pmemkv_config_get_object(
1575  this->config_.get(), key.data(), (void **)&value));
1576 
1577  return s;
1578 }
1579 
1588 inline status config::get_uint64(const std::string &key, std::uint64_t &value) const
1589  noexcept
1590 {
1591  if (this->config_.get() == nullptr)
1592  return status::NOT_FOUND;
1593 
1594  return static_cast<status>(
1595  pmemkv_config_get_uint64(this->config_.get(), key.data(), &value));
1596 }
1597 
1606 inline status config::get_int64(const std::string &key, std::int64_t &value) const
1607  noexcept
1608 {
1609  if (this->config_.get() == nullptr)
1610  return status::NOT_FOUND;
1611 
1612  return static_cast<status>(
1613  pmemkv_config_get_int64(this->config_.get(), key.data(), &value));
1614 }
1615 
1624 inline status config::get_string(const std::string &key, std::string &value) const
1625  noexcept
1626 {
1627  if (this->config_.get() == nullptr)
1628  return status::NOT_FOUND;
1629 
1630  const char *data;
1631 
1632  auto s = static_cast<status>(
1633  pmemkv_config_get_string(this->config_.get(), key.data(), &data));
1634 
1635  if (s != status::OK)
1636  return s;
1637 
1638  value = data;
1639 
1640  return status::OK;
1641 }
1642 
1649 inline pmemkv_config *config::release() noexcept
1650 {
1651  return this->config_.release();
1652 }
1653 
1657 inline tx::tx(pmemkv_tx *tx_) noexcept : tx_(tx_, &pmemkv_tx_end)
1658 {
1659 }
1660 
1670 inline status tx::remove(string_view key) noexcept
1671 {
1672  return static_cast<status>(pmemkv_tx_remove(tx_.get(), key.data(), key.size()));
1673 }
1674 
1684 inline status tx::put(string_view key, string_view value) noexcept
1685 {
1686  return static_cast<status>(pmemkv_tx_put(tx_.get(), key.data(), key.size(),
1687  value.data(), value.size()));
1688 }
1689 
1697 inline status tx::commit() noexcept
1698 {
1699  return static_cast<status>(pmemkv_tx_commit(tx_.get()));
1700 }
1701 
1706 inline void tx::abort() noexcept
1707 {
1708  pmemkv_tx_abort(tx_.get());
1709 }
1710 
1711 /*
1712  * All functions which will be called by C code must be declared as extern "C"
1713  * to ensure they have C linkage. It is needed because it is possible that
1714  * C and C++ functions use different calling conventions.
1715  */
1716 extern "C" {
1717 static inline int call_get_kv_function(const char *key, size_t keybytes,
1718  const char *value, size_t valuebytes, void *arg)
1719 {
1720  return (*reinterpret_cast<std::function<get_kv_function> *>(arg))(
1721  string_view(key, keybytes), string_view(value, valuebytes));
1722 }
1723 
1724 static inline void call_get_v_function(const char *value, size_t valuebytes, void *arg)
1725 {
1726  (*reinterpret_cast<std::function<get_v_function> *>(arg))(
1727  string_view(value, valuebytes));
1728 }
1729 
1730 static inline void call_get_copy(const char *v, size_t vb, void *arg)
1731 {
1732  auto c = reinterpret_cast<std::string *>(arg);
1733  c->assign(v, vb);
1734 }
1735 }
1736 
1740 inline db::db() noexcept : db_(nullptr, &pmemkv_close)
1741 {
1742 }
1743 
1752 inline status db::open(const std::string &engine_name, config &&cfg) noexcept
1753 {
1754  pmemkv_db *db;
1755  auto s =
1756  static_cast<status>(pmemkv_open(engine_name.c_str(), cfg.release(), &db));
1757  if (s == pmem::kv::status::OK)
1758  this->db_.reset(db);
1759  return s;
1760 }
1761 
1765 inline void db::close() noexcept
1766 {
1767  this->db_.reset(nullptr);
1768 }
1769 
1777 inline status db::count_all(std::size_t &cnt) noexcept
1778 {
1779  return static_cast<status>(pmemkv_count_all(this->db_.get(), &cnt));
1780 }
1781 
1792 inline status db::count_above(string_view key, std::size_t &cnt) noexcept
1793 {
1794  return static_cast<status>(
1795  pmemkv_count_above(this->db_.get(), key.data(), key.size(), &cnt));
1796 }
1797 
1808 inline status db::count_equal_above(string_view key, std::size_t &cnt) noexcept
1809 {
1810  return static_cast<status>(
1811  pmemkv_count_equal_above(this->db_.get(), key.data(), key.size(), &cnt));
1812 }
1813 
1824 inline status db::count_equal_below(string_view key, std::size_t &cnt) noexcept
1825 {
1826  return static_cast<status>(
1827  pmemkv_count_equal_below(this->db_.get(), key.data(), key.size(), &cnt));
1828 }
1829 
1840 inline status db::count_below(string_view key, std::size_t &cnt) noexcept
1841 {
1842  return static_cast<status>(
1843  pmemkv_count_below(this->db_.get(), key.data(), key.size(), &cnt));
1844 }
1845 
1858  std::size_t &cnt) noexcept
1859 {
1860  return static_cast<status>(pmemkv_count_between(this->db_.get(), key1.data(),
1861  key1.size(), key2.data(),
1862  key2.size(), &cnt));
1863 }
1864 
1877 inline status db::get_all(get_kv_callback *callback, void *arg) noexcept
1878 {
1879  return static_cast<status>(pmemkv_get_all(this->db_.get(), callback, arg));
1880 }
1881 
1892 inline status db::get_all(std::function<get_kv_function> f) noexcept
1893 {
1894  return static_cast<status>(
1895  pmemkv_get_all(this->db_.get(), call_get_kv_function, &f));
1896 }
1897 
1915  void *arg) noexcept
1916 {
1917  return static_cast<status>(
1918  pmemkv_get_above(this->db_.get(), key.data(), key.size(), callback, arg));
1919 }
1920 
1935 inline status db::get_above(string_view key, std::function<get_kv_function> f) noexcept
1936 {
1937  return static_cast<status>(pmemkv_get_above(
1938  this->db_.get(), key.data(), key.size(), call_get_kv_function, &f));
1939 }
1940 
1959  void *arg) noexcept
1960 {
1961  return static_cast<status>(pmemkv_get_equal_above(this->db_.get(), key.data(),
1962  key.size(), callback, arg));
1963 }
1964 
1981  std::function<get_kv_function> f) noexcept
1982 {
1983  return static_cast<status>(pmemkv_get_equal_above(
1984  this->db_.get(), key.data(), key.size(), call_get_kv_function, &f));
1985 }
1986 
2005  void *arg) noexcept
2006 {
2007  return static_cast<status>(pmemkv_get_equal_below(this->db_.get(), key.data(),
2008  key.size(), callback, arg));
2009 }
2010 
2027  std::function<get_kv_function> f) noexcept
2028 {
2029  return static_cast<status>(pmemkv_get_equal_below(
2030  this->db_.get(), key.data(), key.size(), call_get_kv_function, &f));
2031 }
2032 
2050  void *arg) noexcept
2051 {
2052  return static_cast<status>(
2053  pmemkv_get_below(this->db_.get(), key.data(), key.size(), callback, arg));
2054 }
2055 
2070 inline status db::get_below(string_view key, std::function<get_kv_function> f) noexcept
2071 {
2072  return static_cast<status>(pmemkv_get_below(
2073  this->db_.get(), key.data(), key.size(), call_get_kv_function, &f));
2074 }
2075 
2094  get_kv_callback *callback, void *arg) noexcept
2095 {
2096  return static_cast<status>(pmemkv_get_between(this->db_.get(), key1.data(),
2097  key1.size(), key2.data(),
2098  key2.size(), callback, arg));
2099 }
2116  std::function<get_kv_function> f) noexcept
2117 {
2118  return static_cast<status>(
2119  pmemkv_get_between(this->db_.get(), key1.data(), key1.size(), key2.data(),
2120  key2.size(), call_get_kv_function, &f));
2121 }
2122 
2132 inline status db::exists(string_view key) noexcept
2133 {
2134  return static_cast<status>(
2135  pmemkv_exists(this->db_.get(), key.data(), key.size()));
2136 }
2137 
2153 inline status db::get(string_view key, get_v_callback *callback, void *arg) noexcept
2154 {
2155  return static_cast<status>(
2156  pmemkv_get(this->db_.get(), key.data(), key.size(), callback, arg));
2157 }
2158 
2170 inline status db::get(string_view key, std::function<get_v_function> f) noexcept
2171 {
2172  return static_cast<status>(pmemkv_get(this->db_.get(), key.data(), key.size(),
2173  call_get_v_function, &f));
2174 }
2175 
2186 inline status db::get(string_view key, std::string *value) noexcept
2187 {
2188  return static_cast<status>(pmemkv_get(this->db_.get(), key.data(), key.size(),
2189  call_get_copy, value));
2190 }
2191 
2201 inline status db::put(string_view key, string_view value) noexcept
2202 {
2203  return static_cast<status>(pmemkv_put(this->db_.get(), key.data(), key.size(),
2204  value.data(), value.size()));
2205 }
2206 
2215 inline status db::remove(string_view key) noexcept
2216 {
2217  return static_cast<status>(
2218  pmemkv_remove(this->db_.get(), key.data(), key.size()));
2219 }
2220 
2230 inline status db::defrag(double start_percent, double amount_percent)
2231 {
2232  return static_cast<status>(
2233  pmemkv_defrag(this->db_.get(), start_percent, amount_percent));
2234 }
2235 
2242 {
2243  pmemkv_write_iterator *tmp;
2244  auto ret = static_cast<status>(pmemkv_write_iterator_new(db_.get(), &tmp));
2245  if (static_cast<status>(ret) == status::OK)
2246  return {db::iterator<false>{tmp}};
2247  else
2248  return {ret};
2249 }
2250 
2257 {
2258  pmemkv_iterator *tmp;
2259  auto ret = static_cast<status>(pmemkv_iterator_new(db_.get(), &tmp));
2260  if (ret == status::OK)
2261  return {db::iterator<true>{tmp}};
2262  else
2263  return {ret};
2264 }
2265 
2273 inline std::string db::errormsg()
2274 {
2275  return std::string(pmemkv_errormsg());
2276 }
2277 
2283 static inline std::string errormsg()
2284 {
2285  return std::string(pmemkv_errormsg());
2286 }
2287 
2293 inline result<tx> db::tx_begin() noexcept
2294 {
2295  pmemkv_tx *tx_;
2296  auto s = static_cast<status>(pmemkv_tx_begin(db_.get(), &tx_));
2297 
2298  if (s == status::OK)
2299  return result<tx>(tx(tx_));
2300  else
2301  return result<tx>(s);
2302 }
2303 
2304 } /* namespace kv */
2305 } /* namespace pmem */
2306 
2307 #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:1466
pmem::kv::db::iterator::seek_to_last
status seek_to_last() noexcept
Changes iterator position to the last record.
Definition: libpmemkv.hpp:953
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:1315
pmem::kv::db::iterator::write_range
std::enable_if<!IC, result< pmem::obj::slice< OutputIterator< char > > > >::type write_range(size_t pos=0, size_t n=std::numeric_limits< size_t >::max()) noexcept
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:1624
pmem::kv::internal::comparator_wrapper::comparator_wrapper
comparator_wrapper(const Comparator &cmp)
Definition: libpmemkv.hpp:1189
pmem::kv::db::db
db() noexcept
Default constructor with uninitialized database.
Definition: libpmemkv.hpp:1740
pmem::kv::internal::comparator_config_entry::ptr
std::unique_ptr< comparator_base > ptr
Definition: libpmemkv.hpp:1219
pmem::kv::db::tx_begin
result< tx > tx_begin() noexcept
Starts a pmemkv transaction.
Definition: libpmemkv.hpp:2293
pmem::kv::config
Holds configuration parameters for engines.
Definition: libpmemkv.hpp:445
pmem::kv::result::get_status
status get_status() const noexcept
Returns status from the result.
Definition: libpmemkv.hpp:397
pmem::kv::tx::commit
status commit() noexcept
Commits the transaction.
Definition: libpmemkv.hpp:1697
pmem::kv::operator!=
bool operator!=(const status &lhs, const result< T > &rhs)
Definition: libpmemkv.hpp:421
pmem::kv::result::operator=
result & operator=(const result &other) noexcept(noexcept(std::declval< T >().~T()) &&noexcept(T(std::declval< T >())))
Default copy assignment operator.
Definition: libpmemkv.hpp:273
pmem
Persistent memory namespace.
pmem::kv::operator==
bool operator==(const result< T > &lhs, const status &rhs)
Definition: libpmemkv.hpp:403
pmem::kv::db::iterator::it_
std::unique_ptr< iterator_type, typename std::conditional< IsConst, decltype(&pmemkv_iterator_delete), decltype(&pmemkv_write_iterator_delete)>::type > it_
Definition: libpmemkv.hpp:670
pmem::kv::db::new_read_iterator
result< read_iterator > new_read_iterator()
Returns new read iterator in pmem::kv::result.
Definition: libpmemkv.hpp:2256
pmem::kv::result
Stores result of an operation. It always contains status and optionally can contain value.
Definition: libpmemkv.hpp:175
pmem::kv::db::iterator::OutputIterator::ao
assign_only ao
Definition: libpmemkv.hpp:719
pmem::kv::status::OK
@ OK
no error
pmem::kv::result::~result
~result()
Explicit destructor.
Definition: libpmemkv.hpp:260
pmem::kv::db::iterator
Iterator provides methods to iterate over records in db.
Definition: libpmemkv.hpp:626
pmem::kv::db::iterator::key
result< string_view > key() noexcept
Returns record's key (pmem::kv::string_view), in pmem::kv::result<pmem::kv::string_view>.
Definition: libpmemkv.hpp:1022
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:2153
pmem::kv::db::iterator::OutputIterator::assign_only::c
T * c
Definition: libpmemkv.hpp:716
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:1508
pmem::kv::db::close
void close() noexcept
Closes pmemkv database.
Definition: libpmemkv.hpp:1765
pmem::kv::db::iterator::next
status next() noexcept
Changes iterator position to the next record.
Definition: libpmemkv.hpp:988
pmem::kv::tx::tx
tx(pmemkv_tx *tx_) noexcept
Constructs C++ tx object from a C pmemkv_tx pointer.
Definition: libpmemkv.hpp:1657
pmem::kv::internal::unique_ptr_wrapper::unique_ptr_wrapper
unique_ptr_wrapper(std::unique_ptr< T, D > ptr)
Definition: libpmemkv.hpp:1167
pmem::kv::status
status
Status returned by most of pmemkv functions.
Definition: libpmemkv.hpp:84
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:1606
pmem::kv::db::iterator::commit
std::enable_if<!IC, status >::type commit() noexcept
pmem::kv::config::put_size
status put_size(std::uint64_t size) noexcept
Puts size to a config.
Definition: libpmemkv.hpp:1483
pmem::kv::db::iterator::OutputIterator::assign_only
Definition: libpmemkv.hpp:708
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:1649
pmem::kv::operator<<
std::ostream & operator<<(std::ostream &os, const status &s)
Provides string representation of a status, along with its number as specified by enum.
Definition: libpmemkv.hpp:124
pmem::kv::db::iterator::iterator_type
typename std::conditional< IsConst, pmemkv_iterator, pmemkv_write_iterator >::type iterator_type
Definition: libpmemkv.hpp:628
pmem::kv::result::result
result(const T &val) noexcept(noexcept(T(std::declval< T >())))
Creates result with value (status is automatically initialized to status::OK).
Definition: libpmemkv.hpp:213
pmem::kv::config::put_oid
status put_oid(PMEMoid *oid) noexcept
Puts PMEMoid object to a config.
Definition: libpmemkv.hpp:1522
pmem::kv::internal::comparator_config_entry
Definition: libpmemkv.hpp:1205
pmem::kv::string_view
obj::string_view string_view
Partial string_view implemenetation, defined in pmem::obj namespace in libpmemobj-cpp library (see: h...
Definition: libpmemkv.hpp:47
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:55
pmem::kv::db::iterator::seek_lower
status seek_lower(string_view key) noexcept
Changes iterator position to the record with key lower than given key.
Definition: libpmemkv.hpp:858
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:1449
pmem::kv::internal::comparator_base
Definition: libpmemkv.hpp:1179
pmem::kv::db::iterator::seek
status seek(string_view key) noexcept
Changes iterator position to the record with given key.
Definition: libpmemkv.hpp:838
pmem::kv::internal::unique_ptr_wrapper_base
Definition: libpmemkv.hpp:1157
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:1877
pmem::kv::db::iterator::OutputIterator
OutputIterator provides iteration through elements without a possibility of reading them....
Definition: libpmemkv.hpp:681
pmem::kv::tx::abort
void abort() noexcept
Aborts the transaction.
Definition: libpmemkv.hpp:1706
pmem::kv::internal::unique_ptr_wrapper::get
void * get() override
Definition: libpmemkv.hpp:1171
pmem::kv::internal::comparator_wrapper
Definition: libpmemkv.hpp:1188
pmem::kv::db::iterator::seek_higher
status seek_higher(string_view key) noexcept
Changes iterator position to the record with key higher than given key.
Definition: libpmemkv.hpp:898
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:1808
pmem::kv::db
Main pmemkv class, it provides functions to operate on data in database.
Definition: libpmemkv.hpp:537
pmem::kv::tx::remove
status remove(string_view key) noexcept
Removes from database record with given key.
Definition: libpmemkv.hpp:1670
pmem::kv::operator!=
bool operator!=(const result< T > &lhs, const status &rhs)
Definition: libpmemkv.hpp:415
pmem::kv::db::db_
std::unique_ptr< pmemkv_db, decltype(&pmemkv_close)> db_
Definition: libpmemkv.hpp:601
pmem::kv::result::is_ok
bool is_ok() const noexcept
Checks if the result contains value (status == status::OK).
Definition: libpmemkv.hpp:328
pmem::kv::db::iterator::prev
status prev() noexcept
Changes iterator position to the previous record.
Definition: libpmemkv.hpp:1007
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:1206
pmem::kv::config::put_comparator
status put_comparator(Comparator &&comparator)
Puts comparator object to a config.
Definition: libpmemkv.hpp:1375
pmem::kv::db::iterator::OutputIterator::pointer
void pointer
Definition: libpmemkv.hpp:686
pmem::kv::db::new_write_iterator
result< write_iterator > new_write_iterator()
Returns new write iterator in pmem::kv::result.
Definition: libpmemkv.hpp:2241
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:2004
pmem::kv::db::iterator::abort
std::enable_if<!IC >::type abort() noexcept
pmem::kv::db::iterator::get_raw_it
pmemkv_iterator * get_raw_it()
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:2093
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:2230
pmem::kv::db::iterator::seek_higher_eq
status seek_higher_eq(string_view key) noexcept
Changes iterator position to the record with key equal or higher than given key.
Definition: libpmemkv.hpp:918
pmem::kv::db::iterator::is_next
status is_next() noexcept
Checks if there is a next record available.
Definition: libpmemkv.hpp:969
pmem::kv::config::config_
std::unique_ptr< pmemkv_config, decltype(&pmemkv_config_delete)> config_
Definition: libpmemkv.hpp:485
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:1914
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:62
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:1840
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:1541
pmem::kv::config::init
int init() noexcept
Initialization function for config.
Definition: libpmemkv.hpp:1271
pmem::kv::db::iterator::seek_lower_eq
status seek_lower_eq(string_view key) noexcept
Changes iterator position to the record with key equal or lower than given key.
Definition: libpmemkv.hpp:878
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:1294
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:1777
pmem::kv::db::iterator::iterator
iterator(iterator_type *it)
pmem::kv::tx::tx_
std::unique_ptr< pmemkv_tx, decltype(&pmemkv_tx_end)> tx_
Definition: libpmemkv.hpp:513
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:1588
pmem::kv::internal::comparator_wrapper::comparator_wrapper
comparator_wrapper(Comparator &&cmp)
Definition: libpmemkv.hpp:1193
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:1958
pmem::kv::db::iterator::read_range
result< string_view > read_range(size_t pos=0, size_t n=std::numeric_limits< size_t >::max()) noexcept
Returns value's range (pmem::kv::string_view) to read, in pmem::kv::result.
Definition: libpmemkv.hpp:1051
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:2049
pmem::kv::db::iterator::OutputIterator::value_type
void value_type
Definition: libpmemkv.hpp:688
pmem::kv::tx::put
status put(string_view key, string_view value) noexcept
Inserts a key-value pair into pmemkv database.
Definition: libpmemkv.hpp:1684
pmem::kv::tx
Pmemkv transaction handle.
Definition: libpmemkv.hpp:503
pmem::kv::internal::unique_ptr_wrapper_base::~unique_ptr_wrapper_base
virtual ~unique_ptr_wrapper_base()
Definition: libpmemkv.hpp:1158
pmem::kv::db::remove
status remove(string_view key) noexcept
Removes from database record with given key.
Definition: libpmemkv.hpp:2215
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:67
pmem::kv::db::errormsg
std::string errormsg()
Returns a human readable string describing the last error.
Definition: libpmemkv.hpp:2273
pmem::kv::internal::comparator_config_entry::c_cmp
std::unique_ptr< pmemkv_comparator, decltype(pmemkv_comparator_delete) * > c_cmp
Definition: libpmemkv.hpp:1220
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:1824
pmem::kv::db::iterator::OutputIterator::iterator_category
std::output_iterator_tag iterator_category
Definition: libpmemkv.hpp:689
pmem::kv::internal::unique_ptr_wrapper::ptr
std::unique_ptr< T, D > ptr
Definition: libpmemkv.hpp:1176
pmem::kv::bad_result_access
Defines a type of object to be thrown by result::get_value() when result doesn't contain value.
Definition: libpmemkv.hpp:150
pmem::kv::get_v_callback
pmemkv_get_v_callback get_v_callback
Value-only callback, C-style.
Definition: libpmemkv.hpp:71
pmem::kv::internal::comparator_config_entry::get
void * get() override
Definition: libpmemkv.hpp:1214
pmem::kv::internal::unique_ptr_wrapper_base::get
virtual void * get()=0
pmem::kv::db::open
status open(const std::string &engine_name, config &&cfg=config{}) noexcept
Opens the pmemkv database with specified config.
Definition: libpmemkv.hpp:1752
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:1792
pmem::kv::internal::unique_ptr_wrapper
Definition: libpmemkv.hpp:1166
pmem::kv::result::get_value
const T & get_value() const &
Returns const reference to value from the result.
Definition: libpmemkv.hpp:343
pmem::kv::result::s
status s
Definition: libpmemkv.hpp:180
pmem::kv::bad_result_access::bad_result_access
bad_result_access(const char *what_arg)
Definition: libpmemkv.hpp:152
pmem::kv::config::config
config() noexcept
Default constructor with uninitialized config.
Definition: libpmemkv.hpp:1253
pmem::kv::db::exists
status exists(string_view key) noexcept
Checks existence of record with given key.
Definition: libpmemkv.hpp:2132
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:1432
pmem::kv::db::iterator::seek_to_first
status seek_to_first() noexcept
Changes iterator position to the first record.
Definition: libpmemkv.hpp:936
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:1569
pmem::kv::db::iterator::OutputIterator::difference_type
std::ptrdiff_t difference_type
Definition: libpmemkv.hpp:687
pmem::kv::config::put_path
status put_path(const std::string &path) noexcept
Puts path to a config.
Definition: libpmemkv.hpp:1496
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:1857
pmem::kv::db::put
status put(string_view key, string_view value) noexcept
Inserts a key-value pair into pmemkv database.
Definition: libpmemkv.hpp:2201
pmem::kv::internal::comparator_wrapper::cmp
Comparator cmp
Definition: libpmemkv.hpp:1202
pmem::kv::internal::comparator_wrapper::compare
int compare(string_view key1, string_view key2) override
Definition: libpmemkv.hpp:1197
pmem::kv::result::value
T value
Definition: libpmemkv.hpp:177
pmem::kv::bad_result_access::what
const char * what() const noexcept final
Definition: libpmemkv.hpp:156
pmem::kv::internal::comparator_base::~comparator_base
virtual ~comparator_base()
Definition: libpmemkv.hpp:1181