NVML C++ bindings  0.1 experimental
This is the C++ bindings documentation for NVML's libpmemobj.
pext.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016, 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 
44 namespace nvml
45 {
46 
47 namespace obj
48 {
49 
53 template <typename T>
54 std::ostream &
55 operator<<(std::ostream &os, const p<T> &pp)
56 {
57  return os << pp.get_ro();
58 }
59 
63 template <typename T>
64 std::istream &
65 operator>>(std::istream &is, p<T> &pp)
66 {
67  is >> pp.get_rw();
68  return is;
69 }
70 
74 template <typename T>
76 {
77  ++(pp.get_rw());
78  return pp;
79 }
80 
84 template <typename T>
86 {
87  --(pp.get_rw());
88  return pp;
89 }
90 
94 template <typename T>
95 p<T> operator++(p<T> &pp, int)
96 {
97  p<T> temp = pp;
98  ++pp;
99  return temp;
100 }
101 
105 template <typename T>
107 {
108  p<T> temp = pp;
109  --pp;
110  return temp;
111 }
112 
116 template <typename T, typename Y>
117 p<T> &
118 operator+=(p<T> &lhs, const p<Y> &rhs)
119 {
120  lhs.get_rw() += rhs.get_ro();
121  return lhs;
122 }
123 
127 template <typename T, typename Y>
128 p<T> &
129 operator+=(p<T> &lhs, const Y &rhs)
130 {
131  lhs.get_rw() += rhs;
132  return lhs;
133 }
134 
138 template <typename T, typename Y>
139 p<T> &
140 operator-=(p<T> &lhs, const p<Y> &rhs)
141 {
142  lhs.get_rw() -= rhs.get_ro();
143  return lhs;
144 }
145 
149 template <typename T, typename Y>
150 p<T> &
151 operator-=(p<T> &lhs, const Y &rhs)
152 {
153  lhs.get_rw() -= rhs;
154  return lhs;
155 }
156 
160 template <typename T, typename Y>
161 p<T> &
162 operator*=(p<T> &lhs, const p<Y> &rhs)
163 {
164  lhs.get_rw() *= rhs.get_ro();
165  return lhs;
166 }
167 
171 template <typename T, typename Y>
172 p<T> &
173 operator*=(p<T> &lhs, const Y &rhs)
174 {
175  lhs.get_rw() *= rhs;
176  return lhs;
177 }
178 
182 template <typename T, typename Y>
183 p<T> &
184 operator/=(p<T> &lhs, const p<Y> &rhs)
185 {
186  lhs.get_rw() /= rhs.get_ro();
187  return lhs;
188 }
189 
193 template <typename T, typename Y>
194 p<T> &
195 operator/=(p<T> &lhs, const Y &rhs)
196 {
197  lhs.get_rw() /= rhs;
198  return lhs;
199 }
200 
204 template <typename T, typename Y>
205 p<T> &
206 operator%=(p<T> &lhs, const p<Y> &rhs)
207 {
208  lhs.get_rw() %= rhs.get_ro();
209  return lhs;
210 }
211 
215 template <typename T, typename Y>
216 p<T> &
217 operator%=(p<T> &lhs, const Y &rhs)
218 {
219  lhs.get_rw() %= rhs;
220  return lhs;
221 }
222 
226 template <typename T, typename Y>
227 p<T> &
228 operator&=(p<T> &lhs, const p<Y> &rhs)
229 {
230  lhs.get_rw() &= rhs.get_ro();
231  return lhs;
232 }
233 
237 template <typename T, typename Y>
238 p<T> &
239 operator&=(p<T> &lhs, const Y &rhs)
240 {
241  lhs.get_rw() &= rhs;
242  return lhs;
243 }
244 
248 template <typename T, typename Y>
249 p<T> &
250 operator|=(p<T> &lhs, const p<Y> &rhs)
251 {
252  lhs.get_rw() |= rhs.get_ro();
253  return lhs;
254 }
255 
259 template <typename T, typename Y>
260 p<T> &
261 operator|=(p<T> &lhs, const Y &rhs)
262 {
263  lhs.get_rw() |= rhs;
264  return lhs;
265 }
266 
270 template <typename T, typename Y>
271 p<T> &
272 operator^=(p<T> &lhs, const p<Y> &rhs)
273 {
274  lhs.get_rw() ^= rhs.get_ro();
275  return lhs;
276 }
277 
281 template <typename T, typename Y>
282 p<T> &
283 operator^=(p<T> &lhs, const Y &rhs)
284 {
285  lhs.get_rw() ^= rhs;
286  return lhs;
287 }
288 
292 template <typename T, typename Y>
293 p<T> &
294 operator<<=(p<T> &lhs, const p<Y> &rhs)
295 {
296  lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
297  return lhs;
298 }
299 
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 
314 template <typename T, typename Y>
315 p<T> &
316 operator>>=(p<T> &lhs, const p<Y> &rhs)
317 {
318  lhs.get_rw() = lhs.get_ro() >> rhs.get_ro();
319  return lhs;
320 }
321 
325 template <typename T, typename Y>
326 p<T> &
327 operator>>=(p<T> &lhs, const Y &rhs)
328 {
329  lhs.get_rw() = lhs.get_ro() >> rhs;
330  return lhs;
331 }
332 
333 } /* namespace obj */
334 
335 } /* namespace nvml */
336 
337 #endif /* PMEMOBJ_PEXT_HPP */
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:75
std::istream & operator>>(std::istream &is, p< T > &pp)
Istream operator overload.
Definition: pext.hpp:65
p< T > & operator|=(p< T > &lhs, const p< Y > &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:250
p< T > & operator-=(p< T > &lhs, const p< Y > &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:140
p< T > & operator%=(p< T > &lhs, const p< Y > &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:206
Resides on pmem property template.
p< T > & operator>>=(p< T > &lhs, const p< Y > &rhs)
Bitwise right shift assignment operator overload.
Definition: pext.hpp:316
p< T > & operator/=(p< T > &lhs, const p< Y > &rhs)
Division assignment operator overload.
Definition: pext.hpp:184
p< T > & operator&=(p< T > &lhs, const p< Y > &rhs)
Bitwise AND assignment operator overload.
Definition: pext.hpp:228
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:160
p< T > & operator+=(p< T > &lhs, const p< Y > &rhs)
Addition assignment operator overload.
Definition: pext.hpp:118
p< T > & operator^=(p< T > &lhs, const p< Y > &rhs)
Bitwise XOR assignment operator overload.
Definition: pext.hpp:272
p< T > & operator*=(p< T > &lhs, const p< Y > &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:162
Resides on pmem class.
Definition: p.hpp:64
p< T > & operator--(p< T > &pp)
Prefix decrement operator overload.
Definition: pext.hpp:85
Definition: condition_variable.hpp:48
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:145