PMDK C++ bindings  1.2.0
This is the C++ bindings documentation for PMDK's libpmemobj.
pext.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2017, 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 
38 #ifndef PMEMOBJ_PEXT_HPP
39 #define PMEMOBJ_PEXT_HPP
40 
41 #include "libpmemobj++/p.hpp"
42 #include <iostream>
43 #include <limits>
44 
45 namespace pmem
46 {
47 
48 namespace obj
49 {
50 
54 template <typename T>
55 std::ostream &
56 operator<<(std::ostream &os, const p<T> &pp)
57 {
58  return os << pp.get_ro();
59 }
60 
64 template <typename T>
65 std::istream &
66 operator>>(std::istream &is, p<T> &pp)
67 {
68  is >> pp.get_rw();
69  return is;
70 }
71 
75 template <typename T>
77 {
78  ++(pp.get_rw());
79  return pp;
80 }
81 
85 template <typename T>
87 {
88  --(pp.get_rw());
89  return pp;
90 }
91 
95 template <typename T>
96 p<T> operator++(p<T> &pp, int)
97 {
98  p<T> temp = pp;
99  ++pp;
100  return temp;
101 }
102 
106 template <typename T>
108 {
109  p<T> temp = pp;
110  --pp;
111  return temp;
112 }
113 
117 template <typename T, typename Y>
118 p<T> &
119 operator+=(p<T> &lhs, const p<Y> &rhs)
120 {
121  lhs.get_rw() += rhs.get_ro();
122  return lhs;
123 }
124 
128 template <typename T, typename Y>
129 p<T> &
130 operator+=(p<T> &lhs, const Y &rhs)
131 {
132  lhs.get_rw() += rhs;
133  return lhs;
134 }
135 
139 template <typename T, typename Y>
140 p<T> &
141 operator-=(p<T> &lhs, const p<Y> &rhs)
142 {
143  lhs.get_rw() -= rhs.get_ro();
144  return lhs;
145 }
146 
150 template <typename T, typename Y>
151 p<T> &
152 operator-=(p<T> &lhs, const Y &rhs)
153 {
154  lhs.get_rw() -= rhs;
155  return lhs;
156 }
157 
161 template <typename T, typename Y>
162 p<T> &
163 operator*=(p<T> &lhs, const p<Y> &rhs)
164 {
165  lhs.get_rw() *= rhs.get_ro();
166  return lhs;
167 }
168 
172 template <typename T, typename Y>
173 p<T> &
174 operator*=(p<T> &lhs, const Y &rhs)
175 {
176  lhs.get_rw() *= rhs;
177  return lhs;
178 }
179 
183 template <typename T, typename Y>
184 p<T> &
185 operator/=(p<T> &lhs, const p<Y> &rhs)
186 {
187  lhs.get_rw() /= rhs.get_ro();
188  return lhs;
189 }
190 
194 template <typename T, typename Y>
195 p<T> &
196 operator/=(p<T> &lhs, const Y &rhs)
197 {
198  lhs.get_rw() /= rhs;
199  return lhs;
200 }
201 
205 template <typename T, typename Y>
206 p<T> &
207 operator%=(p<T> &lhs, const p<Y> &rhs)
208 {
209  lhs.get_rw() %= rhs.get_ro();
210  return lhs;
211 }
212 
216 template <typename T, typename Y>
217 p<T> &
218 operator%=(p<T> &lhs, const Y &rhs)
219 {
220  lhs.get_rw() %= rhs;
221  return lhs;
222 }
223 
227 template <typename T, typename Y>
228 p<T> &
229 operator&=(p<T> &lhs, const p<Y> &rhs)
230 {
231  lhs.get_rw() &= rhs.get_ro();
232  return lhs;
233 }
234 
238 template <typename T, typename Y>
239 p<T> &
240 operator&=(p<T> &lhs, const Y &rhs)
241 {
242  lhs.get_rw() &= rhs;
243  return lhs;
244 }
245 
249 template <typename T, typename Y>
250 p<T> &
251 operator|=(p<T> &lhs, const p<Y> &rhs)
252 {
253  lhs.get_rw() |= rhs.get_ro();
254  return lhs;
255 }
256 
260 template <typename T, typename Y>
261 p<T> &
262 operator|=(p<T> &lhs, const Y &rhs)
263 {
264  lhs.get_rw() |= rhs;
265  return lhs;
266 }
267 
271 template <typename T, typename Y>
272 p<T> &
273 operator^=(p<T> &lhs, const p<Y> &rhs)
274 {
275  lhs.get_rw() ^= rhs.get_ro();
276  return lhs;
277 }
278 
282 template <typename T, typename Y>
283 p<T> &
284 operator^=(p<T> &lhs, const Y &rhs)
285 {
286  lhs.get_rw() ^= rhs;
287  return lhs;
288 }
289 
293 template <typename T, typename Y>
294 p<T> &
295 operator<<=(p<T> &lhs, const p<Y> &rhs)
296 {
297  lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
298  return lhs;
299 }
300 
304 template <typename T, typename Y>
305 p<T> &
306 operator<<=(p<T> &lhs, const Y &rhs)
307 {
308  lhs.get_rw() = lhs.get_ro() << rhs;
309  return lhs;
310 }
311 
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 
326 template <typename T, typename Y>
327 p<T> &
328 operator>>=(p<T> &lhs, const Y &rhs)
329 {
330  lhs.get_rw() = lhs.get_ro() >> rhs;
331  return lhs;
332 }
333 
334 } /* namespace obj */
335 
336 } /* namespace pmem */
337 
338 namespace std
339 {
340 
341 template <typename T>
342 struct numeric_limits<pmem::obj::p<T>> : public numeric_limits<T> {
343 
344  static constexpr bool is_specialized = true;
345 };
346 
347 } /* namespace std */
348 
349 #endif /* PMEMOBJ_PEXT_HPP */
p< T > & operator+=(p< T > &lhs, const p< Y > &rhs)
Addition assignment operator overload.
Definition: pext.hpp:119
p< T > & operator--(p< T > &pp)
Prefix decrement operator overload.
Definition: pext.hpp:86
p< T > & operator/=(p< T > &lhs, const p< Y > &rhs)
Division assignment operator overload.
Definition: pext.hpp:185
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:141
Definition: pext.hpp:338
Resides on pmem property template.
p< T > & operator|=(p< T > &lhs, const p< Y > &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:251
std::istream & operator>>(std::istream &is, p< T > &pp)
Istream operator overload.
Definition: pext.hpp:66
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:156
p< T > & operator &=(p< T > &lhs, const p< Y > &rhs)
Bitwise AND assignment operator overload.
Definition: pext.hpp:229
p< T > & operator-=(p< T > &lhs, const p< Y > &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:141
Resides on pmem class.
Definition: p.hpp:64
p< T > & operator%=(p< T > &lhs, const p< Y > &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:207
Definition: allocator.hpp:48
p< T > & operator*=(p< T > &lhs, const p< Y > &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:163
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:76
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)
Bitwise XOR assignment operator overload.
Definition: pext.hpp:273