PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
ctl.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2019-2021, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_CTL_HPP
10 #define LIBPMEMOBJ_CPP_CTL_HPP
11 
12 #include <libpmemobj/ctl.h>
13 #include <string>
14 
15 #include <cerrno>
16 #include <cstring>
17 
19 
20 namespace pmem
21 {
22 
23 namespace obj
24 {
25 
26 template <typename T>
27 T
28 ctl_get_detail(PMEMobjpool *pool, const std::string &name)
29 {
30  T tmp;
31 
32 #ifdef _WIN32
33  int ret = pmemobj_ctl_getU(pool, name.c_str(), &tmp);
34 #else
35  int ret = pmemobj_ctl_get(pool, name.c_str(), &tmp);
36 #endif
37  if (ret)
38  throw detail::exception_with_errormsg<pmem::ctl_error>(
39  "ctl_get failed");
40 
41  return tmp;
42 }
43 
44 template <typename T>
45 T
46 ctl_set_detail(PMEMobjpool *pool, const std::string &name, T arg)
47 {
48 #ifdef _WIN32
49  int ret = pmemobj_ctl_setU(pool, name.c_str(), &arg);
50 #else
51  int ret = pmemobj_ctl_set(pool, name.c_str(), &arg);
52 #endif
53  if (ret)
54  throw detail::exception_with_errormsg<pmem::ctl_error>(
55  "ctl_set failed");
56 
57  return arg;
58 }
59 
60 template <typename T>
61 T
62 ctl_exec_detail(PMEMobjpool *pool, const std::string &name, T arg)
63 {
64 #ifdef _WIN32
65  int ret = pmemobj_ctl_execU(pool, name.c_str(), &arg);
66 #else
67  int ret = pmemobj_ctl_exec(pool, name.c_str(), &arg);
68 #endif
69  if (ret)
70  throw detail::exception_with_errormsg<pmem::ctl_error>(
71  "ctl_exec failed");
72  return arg;
73 }
74 
75 #ifdef _WIN32
76 template <typename T>
77 T
78 ctl_get_detail(PMEMobjpool *pool, const std::wstring &name)
79 {
80  T tmp;
81 
82  int ret = pmemobj_ctl_getW(pool, name.c_str(), &tmp);
83  if (ret)
84  throw detail::exception_with_errormsg<pmem::ctl_error>(
85  "ctl_get failed");
86 
87  return tmp;
88 }
89 
90 template <typename T>
91 T
92 ctl_set_detail(PMEMobjpool *pool, const std::wstring &name, T arg)
93 {
94  int ret = pmemobj_ctl_setW(pool, name.c_str(), &arg);
95  if (ret)
96  throw detail::exception_with_errormsg<pmem::ctl_error>(
97  "ctl_set failed");
98 
99  return arg;
100 }
101 
102 template <typename T>
103 T
104 ctl_exec_detail(PMEMobjpool *pool, const std::wstring &name, T arg)
105 {
106  int ret = pmemobj_ctl_execW(pool, name.c_str(), &arg);
107  if (ret)
108  throw detail::exception_with_errormsg<pmem::ctl_error>(
109  "ctl_exec failed");
110  return arg;
111 }
112 #endif
113 
114 } /* namespace obj */
115 
116 } /* namespace pmem */
117 
118 #endif /* LIBPMEMOBJ_CPP_CTL_HPP */
basic_string< char > string
The most typical string usage - the char specialization.
Definition: string.hpp:24
basic_string< wchar_t > wstring
The wide char specialization.
Definition: string.hpp:30
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Custom pmem exceptions.