PMDK C++ bindings  1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
pext.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2018, 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 LIBPMEMOBJ_CPP_PEXT_HPP
39 #define LIBPMEMOBJ_CPP_PEXT_HPP
40 
41 #include <iostream>
42 #include <libpmemobj++/p.hpp>
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>
76 p<T> &
78 {
79  ++(pp.get_rw());
80  return pp;
81 }
82 
86 template <typename T>
87 p<T> &
89 {
90  --(pp.get_rw());
91  return pp;
92 }
93 
97 template <typename T>
98 p<T>
99 operator++(p<T> &pp, int)
100 {
101  p<T> temp = pp;
102  ++pp;
103  return temp;
104 }
105 
109 template <typename T>
110 p<T>
111 operator--(p<T> &pp, int)
112 {
113  p<T> temp = pp;
114  --pp;
115  return temp;
116 }
117 
121 template <typename T, typename Y>
122 p<T> &
123 operator+=(p<T> &lhs, const p<Y> &rhs)
124 {
125  lhs.get_rw() += rhs.get_ro();
126  return lhs;
127 }
128 
132 template <typename T, typename Y>
133 p<T> &
134 operator+=(p<T> &lhs, const Y &rhs)
135 {
136  lhs.get_rw() += rhs;
137  return lhs;
138 }
139 
143 template <typename T, typename Y>
144 p<T> &
145 operator-=(p<T> &lhs, const p<Y> &rhs)
146 {
147  lhs.get_rw() -= rhs.get_ro();
148  return lhs;
149 }
150 
154 template <typename T, typename Y>
155 p<T> &
156 operator-=(p<T> &lhs, const Y &rhs)
157 {
158  lhs.get_rw() -= rhs;
159  return lhs;
160 }
161 
165 template <typename T, typename Y>
166 p<T> &
167 operator*=(p<T> &lhs, const p<Y> &rhs)
168 {
169  lhs.get_rw() *= rhs.get_ro();
170  return lhs;
171 }
172 
176 template <typename T, typename Y>
177 p<T> &
178 operator*=(p<T> &lhs, const Y &rhs)
179 {
180  lhs.get_rw() *= rhs;
181  return lhs;
182 }
183 
187 template <typename T, typename Y>
188 p<T> &
189 operator/=(p<T> &lhs, const p<Y> &rhs)
190 {
191  lhs.get_rw() /= rhs.get_ro();
192  return lhs;
193 }
194 
198 template <typename T, typename Y>
199 p<T> &
200 operator/=(p<T> &lhs, const Y &rhs)
201 {
202  lhs.get_rw() /= rhs;
203  return lhs;
204 }
205 
209 template <typename T, typename Y>
210 p<T> &
211 operator%=(p<T> &lhs, const p<Y> &rhs)
212 {
213  lhs.get_rw() %= rhs.get_ro();
214  return lhs;
215 }
216 
220 template <typename T, typename Y>
221 p<T> &
222 operator%=(p<T> &lhs, const Y &rhs)
223 {
224  lhs.get_rw() %= rhs;
225  return lhs;
226 }
227 
231 template <typename T, typename Y>
232 p<T> &
233 operator&=(p<T> &lhs, const p<Y> &rhs)
234 {
235  lhs.get_rw() &= rhs.get_ro();
236  return lhs;
237 }
238 
242 template <typename T, typename Y>
243 p<T> &
244 operator&=(p<T> &lhs, const Y &rhs)
245 {
246  lhs.get_rw() &= rhs;
247  return lhs;
248 }
249 
253 template <typename T, typename Y>
254 p<T> &
255 operator|=(p<T> &lhs, const p<Y> &rhs)
256 {
257  lhs.get_rw() |= rhs.get_ro();
258  return lhs;
259 }
260 
264 template <typename T, typename Y>
265 p<T> &
266 operator|=(p<T> &lhs, const Y &rhs)
267 {
268  lhs.get_rw() |= rhs;
269  return lhs;
270 }
271 
275 template <typename T, typename Y>
276 p<T> &
277 operator^=(p<T> &lhs, const p<Y> &rhs)
278 {
279  lhs.get_rw() ^= rhs.get_ro();
280  return lhs;
281 }
282 
286 template <typename T, typename Y>
287 p<T> &
288 operator^=(p<T> &lhs, const Y &rhs)
289 {
290  lhs.get_rw() ^= rhs;
291  return lhs;
292 }
293 
297 template <typename T, typename Y>
298 p<T> &
299 operator<<=(p<T> &lhs, const p<Y> &rhs)
300 {
301  lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
302  return lhs;
303 }
304 
308 template <typename T, typename Y>
309 p<T> &
310 operator<<=(p<T> &lhs, const Y &rhs)
311 {
312  lhs.get_rw() = lhs.get_ro() << rhs;
313  return lhs;
314 }
315 
319 template <typename T, typename Y>
320 p<T> &
321 operator>>=(p<T> &lhs, const p<Y> &rhs)
322 {
323  lhs.get_rw() = lhs.get_ro() >> rhs.get_ro();
324  return lhs;
325 }
326 
330 template <typename T, typename Y>
331 p<T> &
332 operator>>=(p<T> &lhs, const Y &rhs)
333 {
334  lhs.get_rw() = lhs.get_ro() >> rhs;
335  return lhs;
336 }
337 
338 } /* namespace obj */
339 
340 } /* namespace pmem */
341 
342 namespace std
343 {
344 
345 template <typename T>
346 struct numeric_limits<pmem::obj::p<T>> : public numeric_limits<T> {
347 
348  static constexpr bool is_specialized = true;
349 };
350 
351 } /* namespace std */
352 
353 #endif /* LIBPMEMOBJ_CPP_PEXT_HPP */
pmem::obj::operator>>
std::istream & operator>>(std::istream &is, p< T > &pp)
Istream operator overload.
Definition: pext.hpp:66
pmem::obj::p::get_ro
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:157
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:44
pmem::obj::operator&=
p< T > & operator&=(p< T > &lhs, const p< Y > &rhs)
Bitwise AND assignment operator overload.
Definition: pext.hpp:233
pmem::obj::operator++
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:77
pmem::obj::operator|=
p< T > & operator|=(p< T > &lhs, const p< Y > &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:255
pmem::obj::operator%=
p< T > & operator%=(p< T > &lhs, const p< Y > &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:211
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
pmem::obj::operator<<
std::ostream & operator<<(std::ostream &os, persistent_ptr< T > const &pptr)
Ostream operator for the persistent pointer.
Definition: persistent_ptr.hpp:916
pmem::obj::operator+=
p< T > & operator+=(p< T > &lhs, const p< Y > &rhs)
Addition assignment operator overload.
Definition: pext.hpp:123
pmem::obj::operator-=
p< T > & operator-=(p< T > &lhs, const p< Y > &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:145
pmem::obj::operator*=
p< T > & operator*=(p< T > &lhs, const p< Y > &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:167
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:142
pmem::obj::operator/=
p< T > & operator/=(p< T > &lhs, const p< Y > &rhs)
Division assignment operator overload.
Definition: pext.hpp:189
pmem::obj::operator<<=
p< T > & operator<<=(p< T > &lhs, const p< Y > &rhs)
Bitwise left shift assignment operator overload.
Definition: pext.hpp:299
pmem::obj::operator>>=
p< T > & operator>>=(p< T > &lhs, const p< Y > &rhs)
Bitwise right shift assignment operator overload.
Definition: pext.hpp:321
pmem::obj::operator--
p< T > & operator--(p< T > &pp)
Prefix decrement operator overload.
Definition: pext.hpp:88
pmem::obj::operator^=
p< T > & operator^=(p< T > &lhs, const p< Y > &rhs)
Bitwise XOR assignment operator overload.
Definition: pext.hpp:277