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
45namespace pmem
46{
47
48namespace obj
49{
50
54template <typename T>
55std::ostream &
56operator<<(std::ostream &os, const p<T> &pp)
57{
58 return os << pp.get_ro();
59}
60
64template <typename T>
65std::istream &
66operator>>(std::istream &is, p<T> &pp)
67{
68 is >> pp.get_rw();
69 return is;
70}
71
75template <typename T>
77{
78 ++(pp.get_rw());
79 return pp;
80}
81
85template <typename T>
87{
88 --(pp.get_rw());
89 return pp;
90}
91
95template <typename T>
97{
98 p<T> temp = pp;
99 ++pp;
100 return temp;
101}
102
106template <typename T>
108{
109 p<T> temp = pp;
110 --pp;
111 return temp;
112}
113
117template <typename T, typename Y>
118p<T> &
119operator+=(p<T> &lhs, const p<Y> &rhs)
120{
121 lhs.get_rw() += rhs.get_ro();
122 return lhs;
123}
124
128template <typename T, typename Y>
129p<T> &
130operator+=(p<T> &lhs, const Y &rhs)
131{
132 lhs.get_rw() += rhs;
133 return lhs;
134}
135
139template <typename T, typename Y>
140p<T> &
141operator-=(p<T> &lhs, const p<Y> &rhs)
142{
143 lhs.get_rw() -= rhs.get_ro();
144 return lhs;
145}
146
150template <typename T, typename Y>
151p<T> &
152operator-=(p<T> &lhs, const Y &rhs)
153{
154 lhs.get_rw() -= rhs;
155 return lhs;
156}
157
161template <typename T, typename Y>
162p<T> &
163operator*=(p<T> &lhs, const p<Y> &rhs)
164{
165 lhs.get_rw() *= rhs.get_ro();
166 return lhs;
167}
168
172template <typename T, typename Y>
173p<T> &
174operator*=(p<T> &lhs, const Y &rhs)
175{
176 lhs.get_rw() *= rhs;
177 return lhs;
178}
179
183template <typename T, typename Y>
184p<T> &
185operator/=(p<T> &lhs, const p<Y> &rhs)
186{
187 lhs.get_rw() /= rhs.get_ro();
188 return lhs;
189}
190
194template <typename T, typename Y>
195p<T> &
196operator/=(p<T> &lhs, const Y &rhs)
197{
198 lhs.get_rw() /= rhs;
199 return lhs;
200}
201
205template <typename T, typename Y>
206p<T> &
207operator%=(p<T> &lhs, const p<Y> &rhs)
208{
209 lhs.get_rw() %= rhs.get_ro();
210 return lhs;
211}
212
216template <typename T, typename Y>
217p<T> &
218operator%=(p<T> &lhs, const Y &rhs)
219{
220 lhs.get_rw() %= rhs;
221 return lhs;
222}
223
227template <typename T, typename Y>
228p<T> &
229operator&=(p<T> &lhs, const p<Y> &rhs)
230{
231 lhs.get_rw() &= rhs.get_ro();
232 return lhs;
233}
234
238template <typename T, typename Y>
239p<T> &
240operator&=(p<T> &lhs, const Y &rhs)
241{
242 lhs.get_rw() &= rhs;
243 return lhs;
244}
245
249template <typename T, typename Y>
250p<T> &
251operator|=(p<T> &lhs, const p<Y> &rhs)
252{
253 lhs.get_rw() |= rhs.get_ro();
254 return lhs;
255}
256
260template <typename T, typename Y>
261p<T> &
262operator|=(p<T> &lhs, const Y &rhs)
263{
264 lhs.get_rw() |= rhs;
265 return lhs;
266}
267
271template <typename T, typename Y>
272p<T> &
273operator^=(p<T> &lhs, const p<Y> &rhs)
274{
275 lhs.get_rw() ^= rhs.get_ro();
276 return lhs;
277}
278
282template <typename T, typename Y>
283p<T> &
284operator^=(p<T> &lhs, const Y &rhs)
285{
286 lhs.get_rw() ^= rhs;
287 return lhs;
288}
289
293template <typename T, typename Y>
294p<T> &
295operator<<=(p<T> &lhs, const p<Y> &rhs)
296{
297 lhs.get_rw() = lhs.get_ro() << rhs.get_ro();
298 return lhs;
299}
300
304template <typename T, typename Y>
305p<T> &
306operator<<=(p<T> &lhs, const Y &rhs)
307{
308 lhs.get_rw() = lhs.get_ro() << rhs;
309 return lhs;
310}
311
315template <typename T, typename Y>
316p<T> &
317operator>>=(p<T> &lhs, const p<Y> &rhs)
318{
319 lhs.get_rw() = lhs.get_ro() >> rhs.get_ro();
320 return lhs;
321}
322
326template <typename T, typename Y>
327p<T> &
328operator>>=(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
338namespace std
339{
340
341template <typename T>
342struct 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 */
Resides on pmem class.
Definition: p.hpp:64
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:141
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:156
Resides on pmem property template.
std::ostream & operator<<(std::ostream &os, persistent_ptr< T > const &pptr)
Ostream operator for the persistent pointer.
Definition: persistent_ptr.hpp:618
p< T > & operator--(p< T > &pp)
Prefix decrement operator overload.
Definition: pext.hpp:86
p< T > & operator|=(p< T > &lhs, const p< Y > &rhs)
Bitwise OR assignment operator overload.
Definition: pext.hpp:251
p< T > & operator%=(p< T > &lhs, const p< Y > &rhs)
Modulo assignment operator overload.
Definition: pext.hpp:207
p< T > & operator-=(p< T > &lhs, const p< Y > &rhs)
Subtraction assignment operator overload.
Definition: pext.hpp:141
p< T > & operator/=(p< T > &lhs, const p< Y > &rhs)
Division assignment operator overload.
Definition: pext.hpp:185
p< T > & operator^=(p< T > &lhs, const p< Y > &rhs)
Bitwise XOR assignment operator overload.
Definition: pext.hpp:273
std::istream & operator>>(std::istream &is, p< T > &pp)
Istream operator overload.
Definition: pext.hpp:66
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 AND assignment operator overload.
Definition: pext.hpp:229
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:76
p< T > & operator+=(p< T > &lhs, const p< Y > &rhs)
Addition assignment operator overload.
Definition: pext.hpp:119
p< T > & operator*=(p< T > &lhs, const p< Y > &rhs)
Multiplication assignment operator overload.
Definition: pext.hpp:163