PMDK C++ bindings  1.11.1
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-2020, 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 
25 template <typename T>
26 std::ostream &
27 operator<<(std::ostream &os, const p<T> &pp)
28 {
29  return os << pp.get_ro();
30 }
31 
35 template <typename T>
36 std::istream &
37 operator>>(std::istream &is, p<T> &pp)
38 {
39  is >> pp.get_rw();
40  return is;
41 }
42 
46 template <typename T>
47 p<T> &
49 {
50  ++(pp.get_rw());
51  return pp;
52 }
53 
57 template <typename T>
58 p<T> &
60 {
61  --(pp.get_rw());
62  return pp;
63 }
64 
68 template <typename T>
69 p<T>
70 operator++(p<T> &pp, int)
71 {
72  p<T> temp = pp;
73  ++pp;
74  return temp;
75 }
76 
80 template <typename T>
81 p<T>
82 operator--(p<T> &pp, int)
83 {
84  p<T> temp = pp;
85  --pp;
86  return temp;
87 }
88 
92 template <typename T, typename Y>
93 p<T> &
94 operator+=(p<T> &lhs, const p<Y> &rhs)
95 {
96  lhs.get_rw() += rhs.get_ro();
97  return lhs;
98 }
99 
103 template <typename T, typename Y>
104 p<T> &
105 operator+=(p<T> &lhs, const Y &rhs)
106 {
107  lhs.get_rw() += rhs;
108  return lhs;
109 }
110 
114 template <typename T, typename Y>
115 p<T> &
116 operator-=(p<T> &lhs, const p<Y> &rhs)
117 {
118  lhs.get_rw() -= rhs.get_ro();
119  return lhs;
120 }
121 
125 template <typename T, typename Y>
126 p<T> &
127 operator-=(p<T> &lhs, const Y &rhs)
128 {
129  lhs.get_rw() -= rhs;
130  return lhs;
131 }
132 
136 template <typename T, typename Y>
137 p<T> &
138 operator*=(p<T> &lhs, const p<Y> &rhs)
139 {
140  lhs.get_rw() *= rhs.get_ro();
141  return lhs;
142 }
143 
147 template <typename T, typename Y>
148 p<T> &
149 operator*=(p<T> &lhs, const Y &rhs)
150 {
151  lhs.get_rw() *= rhs;
152  return lhs;
153 }
154 
158 template <typename T, typename Y>
159 p<T> &
160 operator/=(p<T> &lhs, const p<Y> &rhs)
161 {
162  lhs.get_rw() /= rhs.get_ro();
163  return lhs;
164 }
165 
169 template <typename T, typename Y>
170 p<T> &
171 operator/=(p<T> &lhs, const Y &rhs)
172 {
173  lhs.get_rw() /= rhs;
174  return lhs;
175 }
176 
180 template <typename T, typename Y>
181 p<T> &
182 operator%=(p<T> &lhs, const p<Y> &rhs)
183 {
184  lhs.get_rw() %= rhs.get_ro();
185  return lhs;
186 }
187 
191 template <typename T, typename Y>
192 p<T> &
193 operator%=(p<T> &lhs, const Y &rhs)
194 {
195  lhs.get_rw() %= rhs;
196  return lhs;
197 }
198 
202 template <typename T, typename Y>
203 p<T> &
204 operator&=(p<T> &lhs, const p<Y> &rhs)
205 {
206  lhs.get_rw() &= rhs.get_ro();
207  return lhs;
208 }
209 
213 template <typename T, typename Y>
214 p<T> &
215 operator&=(p<T> &lhs, const Y &rhs)
216 {
217  lhs.get_rw() &= rhs;
218  return lhs;
219 }
220 
224 template <typename T, typename Y>
225 p<T> &
226 operator|=(p<T> &lhs, const p<Y> &rhs)
227 {
228  lhs.get_rw() |= rhs.get_ro();
229  return lhs;
230 }
231 
235 template <typename T, typename Y>
236 p<T> &
237 operator|=(p<T> &lhs, const Y &rhs)
238 {
239  lhs.get_rw() |= rhs;
240  return lhs;
241 }
242 
246 template <typename T, typename Y>
247 p<T> &
248 operator^=(p<T> &lhs, const p<Y> &rhs)
249 {
250  lhs.get_rw() ^= rhs.get_ro();
251  return lhs;
252 }
253 
257 template <typename T, typename Y>
258 p<T> &
259 operator^=(p<T> &lhs, const Y &rhs)
260 {
261  lhs.get_rw() ^= rhs;
262  return lhs;
263 }
264 
268 template <typename T, typename Y>
269 p<T> &
270 operator<<=(p<T> &lhs, const p<Y> &rhs)
271 {
272  lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
273  return lhs;
274 }
275 
279 template <typename T, typename Y>
280 p<T> &
281 operator<<=(p<T> &lhs, const Y &rhs)
282 {
283  lhs.get_rw() = lhs.get_ro() << rhs;
284  return lhs;
285 }
286 
290 template <typename T, typename Y>
291 p<T> &
292 operator>>=(p<T> &lhs, const p<Y> &rhs)
293 {
294  lhs.get_rw() = lhs.get_ro() >> rhs.get_ro();
295  return lhs;
296 }
297 
301 template <typename T, typename Y>
302 p<T> &
303 operator>>=(p<T> &lhs, const Y &rhs)
304 {
305  lhs.get_rw() = lhs.get_ro() >> rhs;
306  return lhs;
307 }
308 
309 } /* namespace obj */
310 
311 } /* namespace pmem */
312 
313 namespace std
314 {
318 template <typename T>
319 struct numeric_limits<pmem::obj::p<T>> : public numeric_limits<T> {
320 
321  static constexpr bool is_specialized = true;
322 };
323 
327 template <typename T>
328 struct less<pmem::obj::p<T>> {
329  size_t
330  operator()(const pmem::obj::p<T> &lhs, const pmem::obj::p<T> &rhs) const
331  {
332  return lhs.get_ro() < rhs.get_ro();
333  }
334 };
335 
336 } /* namespace std */
337 
338 #endif /* LIBPMEMOBJ_CPP_PEXT_HPP */
pmem::obj::operator>>
std::istream & operator>>(std::istream &is, p< T > &pp)
Istream operator overload.
Definition: pext.hpp:37
pmem::obj::p::get_ro
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:128
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
pmem::obj::operator&=
p< T > & operator&=(p< T > &lhs, const p< Y > &rhs)
Bitwise AND assignment operator overload.
Definition: pext.hpp:204
pmem::obj::operator++
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:48
pmem::obj::operator|=
p< T > & operator|=(p< T > &lhs, const p< Y > &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:226
pmem::obj::operator%=
p< T > & operator%=(p< T > &lhs, const p< Y > &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:182
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:35
pmem::obj::operator<<
std::ostream & operator<<(std::ostream &os, persistent_ptr< T > const &pptr)
Ostream operator for the persistent pointer.
Definition: persistent_ptr.hpp:856
pmem::obj::operator+=
p< T > & operator+=(p< T > &lhs, const p< Y > &rhs)
Addition assignment operator overload.
Definition: pext.hpp:94
pmem::obj::operator-=
p< T > & operator-=(p< T > &lhs, const p< Y > &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:116
pmem::obj::operator*=
p< T > & operator*=(p< T > &lhs, const p< Y > &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:138
p.hpp
Resides on pmem property template.
pmem::obj::p::get_rw
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:113
pmem::obj::operator/=
p< T > & operator/=(p< T > &lhs, const p< Y > &rhs)
Division assignment operator overload.
Definition: pext.hpp:160
pmem::obj::operator<<=
p< T > & operator<<=(p< T > &lhs, const p< Y > &rhs)
Bitwise left shift assignment operator overload.
Definition: pext.hpp:270
pmem::obj::operator>>=
p< T > & operator>>=(p< T > &lhs, const p< Y > &rhs)
Bitwise right shift assignment operator overload.
Definition: pext.hpp:292
pmem::obj::operator--
p< T > & operator--(p< T > &pp)
Prefix decrement operator overload.
Definition: pext.hpp:59
pmem::obj::operator^=
p< T > & operator^=(p< T > &lhs, const p< Y > &rhs)
Bitwise XOR assignment operator overload.
Definition: pext.hpp:248