PMEMKV  1.1.1-git1.gb02004c
This is the C++ documentation for PMEMKV.
libpmemkv.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2020, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef LIBPMEMKV_HPP
34 #define LIBPMEMKV_HPP
35 
36 #include <functional>
37 #include <stdexcept>
38 #include <string>
39 #include <utility>
40 
41 #if __cpp_lib_string_view
42 #include <string_view>
43 #endif
44 
45 #include "libpmemkv.h"
46 
60 namespace pmem
61 {
68 namespace kv
69 {
70 
71 #if __cpp_lib_string_view
72 using string_view = std::string_view;
73 #else
74 
80 class string_view {
81 public:
82  string_view() noexcept;
83  string_view(const char *data, size_t size);
84  string_view(const std::string &s);
85  string_view(const char *data);
86 
87  string_view(const string_view &rhs) noexcept = default;
88  string_view &operator=(const string_view &rhs) noexcept = default;
89 
90  const char *data() const noexcept;
91  std::size_t size() const noexcept;
92 
93  int compare(const string_view &other) noexcept;
94 
95 private:
96  const char *_data;
97  std::size_t _size;
98 };
99 #endif
100 
107 typedef int get_kv_function(string_view key, string_view value);
114 typedef void get_v_function(string_view value);
115 
119 using get_kv_callback = pmemkv_get_kv_callback;
123 using get_v_callback = pmemkv_get_v_callback;
124 
131 enum class status {
132  OK = PMEMKV_STATUS_OK,
133  UNKNOWN_ERROR = PMEMKV_STATUS_UNKNOWN_ERROR,
134  NOT_FOUND = PMEMKV_STATUS_NOT_FOUND,
135  NOT_SUPPORTED = PMEMKV_STATUS_NOT_SUPPORTED,
137  INVALID_ARGUMENT = PMEMKV_STATUS_INVALID_ARGUMENT,
139  CONFIG_PARSING_ERROR =
140  PMEMKV_STATUS_CONFIG_PARSING_ERROR,
141  CONFIG_TYPE_ERROR =
142  PMEMKV_STATUS_CONFIG_TYPE_ERROR,
144  STOPPED_BY_CB = PMEMKV_STATUS_STOPPED_BY_CB,
146  OUT_OF_MEMORY =
147  PMEMKV_STATUS_OUT_OF_MEMORY,
149  WRONG_ENGINE_NAME =
150  PMEMKV_STATUS_WRONG_ENGINE_NAME,
152  TRANSACTION_SCOPE_ERROR =
153  PMEMKV_STATUS_TRANSACTION_SCOPE_ERROR,
155  DEFRAG_ERROR = PMEMKV_STATUS_DEFRAG_ERROR,
157 };
158 
178 class config {
179 public:
180  config() noexcept;
181  explicit config(pmemkv_config *cfg) noexcept;
182 
183  ~config();
184 
185  config(const config &other) = delete;
186  config(config &&other) noexcept;
187 
188  config &operator=(const config &other) = delete;
189  config &operator=(config &&other) noexcept;
190 
191  template <typename T>
192  status put_data(const std::string &key, const T *value,
193  const std::size_t number = 1) noexcept;
194  template <typename T>
195  status put_object(
196  const std::string &key, T *value,
197  void (*deleter)(void *) = [](T *value) { delete value; }) noexcept;
198  status put_uint64(const std::string &key, std::uint64_t value) noexcept;
199  status put_int64(const std::string &key, std::int64_t value) noexcept;
200  status put_string(const std::string &key, const std::string &value) noexcept;
201 
202  template <typename T>
203  status get_data(const std::string &key, T *&value, std::size_t &number) const
204  noexcept;
205  template <typename T>
206  status get_object(const std::string &key, T *&value) const noexcept;
207 
208  status get_uint64(const std::string &key, std::uint64_t &value) const noexcept;
209  status get_int64(const std::string &key, std::int64_t &value) const noexcept;
210  status get_string(const std::string &key, std::string &value) const noexcept;
211 
212  pmemkv_config *release() noexcept;
213 
214 private:
215  int init() noexcept;
216 
217  pmemkv_config *_config;
218 };
219 
232 class db {
233 public:
234  db() noexcept;
235  ~db();
236 
237  db(const db &other) = delete;
238  db(db &&other) noexcept;
239 
240  db &operator=(const db &other) = delete;
241  db &operator=(db &&other) noexcept;
242 
243  status open(const std::string &engine_name) noexcept;
244  status open(const std::string &engine_name, config &&cfg) noexcept;
245 
246  void close() noexcept;
247 
248  status count_all(std::size_t &cnt) noexcept;
249  status count_above(string_view key, std::size_t &cnt) noexcept;
250  status count_equal_above(string_view key, std::size_t &cnt) noexcept;
251  status count_equal_below(string_view key, std::size_t &cnt) noexcept;
252  status count_below(string_view key, std::size_t &cnt) noexcept;
253  status count_between(string_view key1, string_view key2,
254  std::size_t &cnt) noexcept;
255 
256  status get_all(get_kv_callback *callback, void *arg) noexcept;
257  status get_all(std::function<get_kv_function> f) noexcept;
258 
259  status get_above(string_view key, get_kv_callback *callback, void *arg) noexcept;
260  status get_above(string_view key, std::function<get_kv_function> f) noexcept;
261 
262  status get_equal_above(string_view key, get_kv_callback *callback,
263  void *arg) noexcept;
264  status get_equal_above(string_view key,
265  std::function<get_kv_function> f) noexcept;
266 
267  status get_equal_below(string_view key, get_kv_callback *callback,
268  void *arg) noexcept;
269  status get_equal_below(string_view key,
270  std::function<get_kv_function> f) noexcept;
271 
272  status get_below(string_view key, get_kv_callback *callback, void *arg) noexcept;
273  status get_below(string_view key, std::function<get_kv_function> f) noexcept;
274 
275  status get_between(string_view key1, string_view key2, get_kv_callback *callback,
276  void *arg) noexcept;
277  status get_between(string_view key1, string_view key2,
278  std::function<get_kv_function> f) noexcept;
279 
280  status exists(string_view key) noexcept;
281 
282  status get(string_view key, get_v_callback *callback, void *arg) noexcept;
283  status get(string_view key, std::function<get_v_function> f) noexcept;
284  status get(string_view key, std::string *value) noexcept;
285 
286  status put(string_view key, string_view value) noexcept;
287  status remove(string_view key) noexcept;
288  status defrag(double start_percent = 0, double amount_percent = 100);
289 
290  std::string errormsg();
291 
292 private:
293  pmemkv_db *_db;
294 };
295 
299 inline config::config() noexcept
300 {
301  this->_config = nullptr;
302 }
303 
308 inline config::config(config &&other) noexcept
309 {
310  this->_config = other._config;
311  other._config = nullptr;
312 }
313 
318 inline config &config::operator=(config &&other) noexcept
319 {
320  if (this == &other)
321  return *this;
322 
323  if (this->_config)
324  pmemkv_config_delete(this->_config);
325 
326  this->_config = other._config;
327  other._config = nullptr;
328 
329  return *this;
330 }
331 
336 inline config::config(pmemkv_config *cfg) noexcept
337 {
338  this->_config = cfg;
339 }
340 
345 {
346  if (this->_config)
347  pmemkv_config_delete(this->_config);
348 }
349 
356 inline int config::init() noexcept
357 {
358  if (this->_config == nullptr) {
359  this->_config = pmemkv_config_new();
360 
361  if (this->_config == nullptr)
362  return 1;
363  }
364 
365  return 0;
366 }
367 
378 template <typename T>
379 inline status config::put_data(const std::string &key, const T *value,
380  const std::size_t count) noexcept
381 {
382  if (init() != 0)
383  return status::UNKNOWN_ERROR;
384 
385  return static_cast<status>(pmemkv_config_put_data(
386  this->_config, key.data(), (void *)value, count * sizeof(T)));
387 }
388 
399 template <typename T>
400 inline status config::put_object(const std::string &key, T *value,
401  void (*deleter)(void *)) noexcept
402 {
403  if (init() != 0)
404  return status::UNKNOWN_ERROR;
405 
406  return static_cast<status>(pmemkv_config_put_object(this->_config, key.data(),
407  (void *)value, deleter));
408 }
409 
418 inline status config::put_uint64(const std::string &key, std::uint64_t value) noexcept
419 {
420  if (init() != 0)
421  return status::UNKNOWN_ERROR;
422 
423  return static_cast<status>(
424  pmemkv_config_put_uint64(this->_config, key.data(), value));
425 }
426 
435 inline status config::put_int64(const std::string &key, std::int64_t value) noexcept
436 {
437  if (init() != 0)
438  return status::UNKNOWN_ERROR;
439 
440  return static_cast<status>(
441  pmemkv_config_put_int64(this->_config, key.data(), value));
442 }
443 
452 inline status config::put_string(const std::string &key,
453  const std::string &value) noexcept
454 {
455  if (init() != 0)
456  return status::UNKNOWN_ERROR;
457 
458  return static_cast<status>(
459  pmemkv_config_put_string(this->_config, key.data(), value.data()));
460 }
461 
472 template <typename T>
473 inline status config::get_data(const std::string &key, T *&value,
474  std::size_t &count) const noexcept
475 {
476  if (this->_config == nullptr)
477  return status::NOT_FOUND;
478 
479  std::size_t size;
480  auto s = static_cast<status>(pmemkv_config_get_data(
481  this->_config, key.data(), (const void **)&value, &size));
482 
483  if (s != status::OK)
484  return s;
485 
486  count = size / sizeof(T);
487 
488  return status::OK;
489 }
490 
500 template <typename T>
501 inline status config::get_object(const std::string &key, T *&value) const noexcept
502 {
503  if (this->_config == nullptr)
504  return status::NOT_FOUND;
505 
506  auto s = static_cast<status>(
507  pmemkv_config_get_object(this->_config, key.data(), (void **)&value));
508 
509  return s;
510 }
511 
520 inline status config::get_uint64(const std::string &key, std::uint64_t &value) const
521  noexcept
522 {
523  if (this->_config == nullptr)
524  return status::NOT_FOUND;
525 
526  return static_cast<status>(
527  pmemkv_config_get_uint64(this->_config, key.data(), &value));
528 }
529 
538 inline status config::get_int64(const std::string &key, std::int64_t &value) const
539  noexcept
540 {
541  if (this->_config == nullptr)
542  return status::NOT_FOUND;
543 
544  return static_cast<status>(
545  pmemkv_config_get_int64(this->_config, key.data(), &value));
546 }
547 
556 inline status config::get_string(const std::string &key, std::string &value) const
557  noexcept
558 {
559  if (this->_config == nullptr)
560  return status::NOT_FOUND;
561 
562  const char *data;
563 
564  auto s = static_cast<status>(
565  pmemkv_config_get_string(this->_config, key.data(), &data));
566 
567  if (s != status::OK)
568  return s;
569 
570  value = data;
571 
572  return status::OK;
573 }
574 
581 inline pmemkv_config *config::release() noexcept
582 {
583  auto c = this->_config;
584  this->_config = nullptr;
585  return c;
586 }
587 
588 #if !__cpp_lib_string_view
589 
592 inline string_view::string_view() noexcept : _data(""), _size(0)
593 {
594 }
595 
603 inline string_view::string_view(const char *data, size_t size) : _data(data), _size(size)
604 {
605 }
606 
612 inline string_view::string_view(const std::string &s) : _data(s.c_str()), _size(s.size())
613 {
614 }
615 
623 inline string_view::string_view(const char *data)
624  : _data(data), _size(std::char_traits<char>::length(data))
625 {
626 }
627 
634 inline const char *string_view::data() const noexcept
635 {
636  return _data;
637 }
638 
644 inline std::size_t string_view::size() const noexcept
645 {
646  return _size;
647 }
648 
657 inline int string_view::compare(const string_view &other) noexcept
658 {
659  int ret = std::char_traits<char>::compare(data(), other.data(),
660  std::min(size(), other.size()));
661  if (ret != 0)
662  return ret;
663  if (size() < other.size())
664  return -1;
665  if (size() > other.size())
666  return 1;
667  return 0;
668 }
669 #endif
670 
671 /*
672  * All functions which will be called by C code must be declared as extern "C"
673  * to ensure they have C linkage. It is needed because it is possible that
674  * C and C++ functions use different calling conventions.
675  */
676 extern "C" {
677 static inline int call_get_kv_function(const char *key, size_t keybytes,
678  const char *value, size_t valuebytes, void *arg)
679 {
680  return (*reinterpret_cast<std::function<get_kv_function> *>(arg))(
681  string_view(key, keybytes), string_view(value, valuebytes));
682 }
683 
684 static inline void call_get_v_function(const char *value, size_t valuebytes, void *arg)
685 {
686  (*reinterpret_cast<std::function<get_v_function> *>(arg))(
687  string_view(value, valuebytes));
688 }
689 
690 static inline void call_get_copy(const char *v, size_t vb, void *arg)
691 {
692  auto c = reinterpret_cast<std::string *>(arg);
693  c->assign(v, vb);
694 }
695 }
696 
700 inline db::db() noexcept
701 {
702  this->_db = nullptr;
703 }
704 
711 inline db::db(db &&other) noexcept
712 {
713  this->_db = other._db;
714  other._db = nullptr;
715 }
716 
724 inline db &db::operator=(db &&other) noexcept
725 {
726  if (this == &other)
727  return *this;
728 
729  close();
730 
731  std::swap(this->_db, other._db);
732 
733  return *this;
734 }
735 
743 inline status db::open(const std::string &engine_name) noexcept
744 {
745  return static_cast<status>(
746  pmemkv_open(engine_name.c_str(), nullptr, &(this->_db)));
747 }
748 
757 inline status db::open(const std::string &engine_name, config &&cfg) noexcept
758 {
759  return static_cast<status>(
760  pmemkv_open(engine_name.c_str(), cfg.release(), &(this->_db)));
761 }
762 
766 inline void db::close() noexcept
767 {
768  if (this->_db != nullptr)
769  pmemkv_close(this->_db);
770 
771  this->_db = nullptr;
772 }
773 
777 inline db::~db()
778 {
779  close();
780 }
781 
789 inline status db::count_all(std::size_t &cnt) noexcept
790 {
791  return static_cast<status>(pmemkv_count_all(this->_db, &cnt));
792 }
793 
804 inline status db::count_above(string_view key, std::size_t &cnt) noexcept
805 {
806  return static_cast<status>(
807  pmemkv_count_above(this->_db, key.data(), key.size(), &cnt));
808 }
809 
820 inline status db::count_equal_above(string_view key, std::size_t &cnt) noexcept
821 {
822  return static_cast<status>(
823  pmemkv_count_equal_above(this->_db, key.data(), key.size(), &cnt));
824 }
825 
836 inline status db::count_equal_below(string_view key, std::size_t &cnt) noexcept
837 {
838  return static_cast<status>(
839  pmemkv_count_equal_below(this->_db, key.data(), key.size(), &cnt));
840 }
841 
852 inline status db::count_below(string_view key, std::size_t &cnt) noexcept
853 {
854  return static_cast<status>(
855  pmemkv_count_below(this->_db, key.data(), key.size(), &cnt));
856 }
857 
870  std::size_t &cnt) noexcept
871 {
872  return static_cast<status>(pmemkv_count_between(
873  this->_db, key1.data(), key1.size(), key2.data(), key2.size(), &cnt));
874 }
875 
888 inline status db::get_all(get_kv_callback *callback, void *arg) noexcept
889 {
890  return static_cast<status>(pmemkv_get_all(this->_db, callback, arg));
891 }
892 
903 inline status db::get_all(std::function<get_kv_function> f) noexcept
904 {
905  return static_cast<status>(pmemkv_get_all(this->_db, call_get_kv_function, &f));
906 }
907 
925  void *arg) noexcept
926 {
927  return static_cast<status>(
928  pmemkv_get_above(this->_db, key.data(), key.size(), callback, arg));
929 }
930 
945 inline status db::get_above(string_view key, std::function<get_kv_function> f) noexcept
946 {
947  return static_cast<status>(pmemkv_get_above(this->_db, key.data(), key.size(),
948  call_get_kv_function, &f));
949 }
950 
969  void *arg) noexcept
970 {
971  return static_cast<status>(
972  pmemkv_get_equal_above(this->_db, key.data(), key.size(), callback, arg));
973 }
974 
991  std::function<get_kv_function> f) noexcept
992 {
993  return static_cast<status>(pmemkv_get_equal_above(
994  this->_db, key.data(), key.size(), call_get_kv_function, &f));
995 }
996 
1015  void *arg) noexcept
1016 {
1017  return static_cast<status>(
1018  pmemkv_get_equal_below(this->_db, key.data(), key.size(), callback, arg));
1019 }
1020 
1037  std::function<get_kv_function> f) noexcept
1038 {
1039  return static_cast<status>(pmemkv_get_equal_below(
1040  this->_db, key.data(), key.size(), call_get_kv_function, &f));
1041 }
1042 
1060  void *arg) noexcept
1061 {
1062  return static_cast<status>(
1063  pmemkv_get_below(this->_db, key.data(), key.size(), callback, arg));
1064 }
1065 
1080 inline status db::get_below(string_view key, std::function<get_kv_function> f) noexcept
1081 {
1082  return static_cast<status>(pmemkv_get_below(this->_db, key.data(), key.size(),
1083  call_get_kv_function, &f));
1084 }
1085 
1104  get_kv_callback *callback, void *arg) noexcept
1105 {
1106  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
1107  key2.data(), key2.size(), callback,
1108  arg));
1109 }
1126  std::function<get_kv_function> f) noexcept
1127 {
1128  return static_cast<status>(pmemkv_get_between(this->_db, key1.data(), key1.size(),
1129  key2.data(), key2.size(),
1130  call_get_kv_function, &f));
1131 }
1132 
1142 inline status db::exists(string_view key) noexcept
1143 {
1144  return static_cast<status>(pmemkv_exists(this->_db, key.data(), key.size()));
1145 }
1146 
1162 inline status db::get(string_view key, get_v_callback *callback, void *arg) noexcept
1163 {
1164  return static_cast<status>(
1165  pmemkv_get(this->_db, key.data(), key.size(), callback, arg));
1166 }
1167 
1179 inline status db::get(string_view key, std::function<get_v_function> f) noexcept
1180 {
1181  return static_cast<status>(
1182  pmemkv_get(this->_db, key.data(), key.size(), call_get_v_function, &f));
1183 }
1184 
1195 inline status db::get(string_view key, std::string *value) noexcept
1196 {
1197  return static_cast<status>(
1198  pmemkv_get(this->_db, key.data(), key.size(), call_get_copy, value));
1199 }
1200 
1210 inline status db::put(string_view key, string_view value) noexcept
1211 {
1212  return static_cast<status>(pmemkv_put(this->_db, key.data(), key.size(),
1213  value.data(), value.size()));
1214 }
1215 
1224 inline status db::remove(string_view key) noexcept
1225 {
1226  return static_cast<status>(pmemkv_remove(this->_db, key.data(), key.size()));
1227 }
1228 
1238 inline status db::defrag(double start_percent, double amount_percent)
1239 
1240 {
1241  return static_cast<status>(
1242  pmemkv_defrag(this->_db, start_percent, amount_percent));
1243 }
1244 
1252 inline std::string db::errormsg()
1253 {
1254  return std::string(pmemkv_errormsg());
1255 }
1256 
1262 static inline std::string errormsg()
1263 {
1264  return std::string(pmemkv_errormsg());
1265 }
1266 
1267 } /* namespace kv */
1268 } /* namespace pmem */
1269 
1270 #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:452
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:556
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:644
pmem::kv::db::db
db() noexcept
Default constructor with uninitialized database.
Definition: libpmemkv.hpp:700
pmem::kv::db::~db
~db()
Default destructor.
Definition: libpmemkv.hpp:777
pmem::kv::config
Holds configuration parameters for engines.
Definition: libpmemkv.hpp:178
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:1162
pmem::kv::db::close
void close() noexcept
Closes pmemkv database.
Definition: libpmemkv.hpp:766
pmem::kv::status
status
Status returned by pmemkv functions.
Definition: libpmemkv.hpp:131
pmem::kv::config::get_int64
status get_int64(const std::string &key, std::int64_t &value) const noexcept
Gets std::int64_t value from a config item with key name.
Definition: libpmemkv.hpp:538
pmem::kv::config::put_object
status put_object(const std::string &key, T *value, void(*deleter)(void *)=[](T *value) { delete value;}) noexcept
Puts object pointed by value, of type T, with given destructor to a config.
Definition: libpmemkv.hpp:400
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:581
pmem::kv::db::open
status open(const std::string &engine_name) noexcept
Opens the pmemkv database without any configuration parameters.
Definition: libpmemkv.hpp:743
pmem::kv::string_view::compare
int compare(const string_view &other) noexcept
Compares this string_view with other.
Definition: libpmemkv.hpp:657
pmem::kv::get_kv_function
int get_kv_function(string_view key, string_view value)
The C++ idiomatic function type to use for callback using key-value pair.
Definition: libpmemkv.hpp:107
pmem::kv::config::put_int64
status put_int64(const std::string &key, std::int64_t value) noexcept
Puts std::int64_t value to a config.
Definition: libpmemkv.hpp:435
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:888
pmem::kv::string_view::_data
const char * _data
Definition: libpmemkv.hpp:96
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:820
pmem::kv::db
Main pmemkv class, it provides functions to operate on data in database.
Definition: libpmemkv.hpp:232
pmem::kv::db::db
db(const db &other)=delete
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:1014
pmem::kv::string_view::string_view
string_view() noexcept
Default constructor with empty data.
Definition: libpmemkv.hpp:592
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:1103
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:1238
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:924
pmem::kv::get_v_function
void get_v_function(string_view value)
The C++ idiomatic function type to use for callback using only the value.
Definition: libpmemkv.hpp:114
pmem::kv::db::count_below
status count_below(string_view key, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are less than the given ke...
Definition: libpmemkv.hpp:852
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:473
pmem::kv::config::init
int init() noexcept
Initialization function for config.
Definition: libpmemkv.hpp:356
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:379
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:789
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:520
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:968
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:1059
pmem::kv::db::remove
status remove(string_view key) noexcept
Removes from database record with given key.
Definition: libpmemkv.hpp:1224
pmem::kv::get_kv_callback
pmemkv_get_kv_callback get_kv_callback
Key-value pair callback, C-style.
Definition: libpmemkv.hpp:119
pmem::kv::string_view
Our brief std::string_view implementation.
Definition: libpmemkv.hpp:80
pmem::kv::db::_db
pmemkv_db * _db
Definition: libpmemkv.hpp:293
pmem::kv::db::errormsg
std::string errormsg()
Returns a human readable string describing the last error.
Definition: libpmemkv.hpp:1252
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:836
pmem::kv::get_v_callback
pmemkv_get_v_callback get_v_callback
Value-only callback, C-style.
Definition: libpmemkv.hpp:123
pmem::kv::string_view::data
const char * data() const noexcept
Returns pointer to data stored in this pmem::kv::string_view.
Definition: libpmemkv.hpp:634
pmem::kv::config::operator=
config & operator=(const config &other)=delete
pmem::kv::db::count_above
status count_above(string_view key, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are greater than the given...
Definition: libpmemkv.hpp:804
pmem::kv::config::~config
~config()
Default destructor.
Definition: libpmemkv.hpp:344
pmem::kv::config::config
config() noexcept
Default constructor with uninitialized config.
Definition: libpmemkv.hpp:299
pmem::kv::db::exists
status exists(string_view key) noexcept
Checks existence of record with given key.
Definition: libpmemkv.hpp:1142
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:418
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:501
pmem::kv::config::config
config(const config &other)=delete
pmem::kv::string_view::_size
std::size_t _size
Definition: libpmemkv.hpp:97
pmem::kv::db::count_between
status count_between(string_view key1, string_view key2, std::size_t &cnt) noexcept
It returns number of currently stored elements in pmem::kv::db, whose keys are greater than the key1 ...
Definition: libpmemkv.hpp:869
pmem::kv::db::put
status put(string_view key, string_view value) noexcept
Inserts a key-value pair into pmemkv database.
Definition: libpmemkv.hpp:1210
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