PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
pext.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2016-2021, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_PEXT_HPP
10 #define LIBPMEMOBJ_CPP_PEXT_HPP
11 
12 #include <iostream>
13 #include <libpmemobj++/p.hpp>
14 #include <limits>
15 
16 namespace pmem
17 {
18 
19 namespace obj
20 {
21 
26 template <typename T>
27 std::ostream &
28 operator<<(std::ostream &os, const p<T> &pp)
29 {
30  return os << pp.get_ro();
31 }
32 
37 template <typename T>
38 std::istream &
39 operator>>(std::istream &is, p<T> &pp)
40 {
41  is >> pp.get_rw();
42  return is;
43 }
44 
49 template <typename T>
50 p<T> &
52 {
53  ++(pp.get_rw());
54  return pp;
55 }
56 
61 template <typename T>
62 p<T> &
64 {
65  --(pp.get_rw());
66  return pp;
67 }
68 
73 template <typename T>
74 p<T>
75 operator++(p<T> &pp, int)
76 {
77  p<T> temp = pp;
78  ++pp;
79  return temp;
80 }
81 
86 template <typename T>
87 p<T>
88 operator--(p<T> &pp, int)
89 {
90  p<T> temp = pp;
91  --pp;
92  return temp;
93 }
94 
99 template <typename T, typename Y>
100 p<T> &
101 operator+=(p<T> &lhs, const p<Y> &rhs)
102 {
103  lhs.get_rw() += rhs.get_ro();
104  return lhs;
105 }
106 
111 template <typename T, typename Y>
112 p<T> &
113 operator+=(p<T> &lhs, const Y &rhs)
114 {
115  lhs.get_rw() += rhs;
116  return lhs;
117 }
118 
123 template <typename T, typename Y>
124 p<T> &
125 operator-=(p<T> &lhs, const p<Y> &rhs)
126 {
127  lhs.get_rw() -= rhs.get_ro();
128  return lhs;
129 }
130 
135 template <typename T, typename Y>
136 p<T> &
137 operator-=(p<T> &lhs, const Y &rhs)
138 {
139  lhs.get_rw() -= rhs;
140  return lhs;
141 }
142 
147 template <typename T, typename Y>
148 p<T> &
149 operator*=(p<T> &lhs, const p<Y> &rhs)
150 {
151  lhs.get_rw() *= rhs.get_ro();
152  return lhs;
153 }
154 
159 template <typename T, typename Y>
160 p<T> &
161 operator*=(p<T> &lhs, const Y &rhs)
162 {
163  lhs.get_rw() *= rhs;
164  return lhs;
165 }
166 
171 template <typename T, typename Y>
172 p<T> &
173 operator/=(p<T> &lhs, const p<Y> &rhs)
174 {
175  lhs.get_rw() /= rhs.get_ro();
176  return lhs;
177 }
178 
183 template <typename T, typename Y>
184 p<T> &
185 operator/=(p<T> &lhs, const Y &rhs)
186 {
187  lhs.get_rw() /= rhs;
188  return lhs;
189 }
190 
195 template <typename T, typename Y>
196 p<T> &
197 operator%=(p<T> &lhs, const p<Y> &rhs)
198 {
199  lhs.get_rw() %= rhs.get_ro();
200  return lhs;
201 }
202 
207 template <typename T, typename Y>
208 p<T> &
209 operator%=(p<T> &lhs, const Y &rhs)
210 {
211  lhs.get_rw() %= rhs;
212  return lhs;
213 }
214 
219 template <typename T, typename Y>
220 p<T> &
221 operator&=(p<T> &lhs, const p<Y> &rhs)
222 {
223  lhs.get_rw() &= rhs.get_ro();
224  return lhs;
225 }
226 
231 template <typename T, typename Y>
232 p<T> &
233 operator&=(p<T> &lhs, const Y &rhs)
234 {
235  lhs.get_rw() &= rhs;
236  return lhs;
237 }
238 
243 template <typename T, typename Y>
244 p<T> &
245 operator|=(p<T> &lhs, const p<Y> &rhs)
246 {
247  lhs.get_rw() |= rhs.get_ro();
248  return lhs;
249 }
250 
255 template <typename T, typename Y>
256 p<T> &
257 operator|=(p<T> &lhs, const Y &rhs)
258 {
259  lhs.get_rw() |= rhs;
260  return lhs;
261 }
262 
267 template <typename T, typename Y>
268 p<T> &
269 operator^=(p<T> &lhs, const p<Y> &rhs)
270 {
271  lhs.get_rw() ^= rhs.get_ro();
272  return lhs;
273 }
274 
279 template <typename T, typename Y>
280 p<T> &
281 operator^=(p<T> &lhs, const Y &rhs)
282 {
283  lhs.get_rw() ^= rhs;
284  return lhs;
285 }
286 
291 template <typename T, typename Y>
292 p<T> &
293 operator<<=(p<T> &lhs, const p<Y> &rhs)
294 {
295  lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
296  return lhs;
297 }
298 
303 template <typename T, typename Y>
304 p<T> &
305 operator<<=(p<T> &lhs, const Y &rhs)
306 {
307  lhs.get_rw() = lhs.get_ro() << rhs;
308  return lhs;
309 }
310 
315 template <typename T, typename Y>
316 p<T> &
317 operator>>=(p<T> &lhs, const p<Y> &rhs)
318 {
319  lhs.get_rw() = lhs.get_ro() >> rhs.get_ro();
320  return lhs;
321 }
322 
327 template <typename T, typename Y>
328 p<T> &
329 operator>>=(p<T> &lhs, const Y &rhs)
330 {
331  lhs.get_rw() = lhs.get_ro() >> rhs;
332  return lhs;
333 }
334 
335 } /* namespace obj */
336 
337 } /* namespace pmem */
338 
339 namespace std
340 {
344 template <typename T>
345 struct numeric_limits<pmem::obj::p<T>> : public numeric_limits<T> {
346 
347  static constexpr bool is_specialized = true;
348 };
349 
353 template <typename T>
354 struct less<pmem::obj::p<T>> {
355  size_t
356  operator()(const pmem::obj::p<T> &lhs, const pmem::obj::p<T> &rhs) const
357  {
358  return lhs.get_ro() < rhs.get_ro();
359  }
360 };
361 
362 } /* namespace std */
363 
364 #endif /* LIBPMEMOBJ_CPP_PEXT_HPP */
Resides on pmem class.
Definition: p.hpp:36
std::istream & operator>>(std::istream &is, p< T > &pp)
Istream operator overload.
Definition: pext.hpp:39
p< T > & operator|=(p< T > &lhs, const Y &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:257
p< T > & operator*=(p< T > &lhs, const Y &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:161
p< T > & operator-=(p< T > &lhs, const Y &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:137
p< T > & operator>>=(p< T > &lhs, const p< Y > &rhs)
Bitwise right shift assignment operator overload.
Definition: pext.hpp:317
p< T > & operator%=(p< T > &lhs, const p< Y > &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:197
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:51
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:114
p< T > & operator*=(p< T > &lhs, const p< Y > &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:149
p< T > operator++(p< T > &pp, int)
Postfix increment operator overload.
Definition: pext.hpp:75
p< T > & operator&=(p< T > &lhs, const Y &rhs)
Bitwise AND assignment operator overload.
Definition: pext.hpp:233
p< T > & operator/=(p< T > &lhs, const p< Y > &rhs)
Division assignment operator overload.
Definition: pext.hpp:173
p< T > & operator/=(p< T > &lhs, const Y &rhs)
Division assignment operator overload.
Definition: pext.hpp:185
p< T > & operator%=(p< T > &lhs, const Y &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:209
p< T > & operator>>=(p< T > &lhs, const Y &rhs)
Bitwise right shift assignment operator overload.
Definition: pext.hpp:329
p< T > & operator|=(p< T > &lhs, const p< Y > &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:245
p< T > & operator+=(p< T > &lhs, const p< Y > &rhs)
Addition assignment operator overload.
Definition: pext.hpp:101
p< T > & operator+=(p< T > &lhs, const Y &rhs)
Addition assignment operator overload.
Definition: pext.hpp:113
p< T > & operator&=(p< T > &lhs, const p< Y > &rhs)
Bitwise AND assignment operator overload.
Definition: pext.hpp:221
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:129
p< T > operator--(p< T > &pp, int)
Postfix decrement operator overload.
Definition: pext.hpp:88
p< T > & operator--(p< T > &pp)
Prefix decrement operator overload.
Definition: pext.hpp:63
p< T > & operator^=(p< T > &lhs, const p< Y > &rhs)
Bitwise XOR assignment operator overload.
Definition: pext.hpp:269
p< T > & operator-=(p< T > &lhs, const p< Y > &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:125
std::ostream & operator<<(std::ostream &os, const radix_tree< K, V, BV, MtMode > &tree)
Prints tree in DOT format.
Definition: radix_tree.hpp:2843
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Resides on pmem property template.