PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
p.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2015-2021, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_P_HPP
10 #define LIBPMEMOBJ_CPP_P_HPP
11 
12 #include <memory>
13 
16 
17 namespace pmem
18 {
19 
20 namespace obj
21 {
35 template <typename T>
36 class p {
37  typedef p<T> this_type;
38 
39 public:
47  p(const T &_val) noexcept : val{_val}
48  {
49  }
50 
54  p() = default;
55 
66  p &
67  operator=(const p &rhs)
68  {
69  this_type(rhs).swap(*this);
70 
71  return *this;
72  }
73 
84  template <typename Y,
85  typename = typename std::enable_if<
86  std::is_convertible<Y, T>::value>::type>
87  p &
88  operator=(const p<Y> &rhs)
89  {
90  this_type(rhs).swap(*this);
91 
92  return *this;
93  }
94 
98  operator T() const noexcept
99  {
100  return this->val;
101  }
102 
113  T &
115  {
117 
118  return this->val;
119  }
120 
128  const T &
129  get_ro() const noexcept
130  {
131  return this->val;
132  }
133 
140  void
141  swap(p &other)
142  {
145  std::swap(this->val, other.val);
146  }
147 
148 private:
149  T val;
150 };
151 
159 template <class T>
160 inline void
161 swap(p<T> &a, p<T> &b)
162 {
163  a.swap(b);
164 }
165 
166 } /* namespace obj */
167 
168 } /* namespace pmem */
169 
170 #endif /* LIBPMEMOBJ_CPP_P_HPP */
Resides on pmem class.
Definition: p.hpp:36
p & operator=(const p< Y > &rhs)
Converting assignment operator from a different p<>.
Definition: p.hpp:88
p(const T &_val) noexcept
Value constructor.
Definition: p.hpp:47
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:114
void swap(p &other)
Swaps two p objects of the same type.
Definition: p.hpp:141
p()=default
Defaulted constructor.
void swap(p< T > &a, p< T > &b)
Swaps two p objects of the same type.
Definition: p.hpp:161
p & operator=(const p &rhs)
Assignment operator.
Definition: p.hpp:67
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:129
Commonly used functionality.
void conditional_add_to_tx(const T *that, std::size_t count=1, uint64_t flags=0)
Conditionally add 'count' objects to a transaction.
Definition: common.hpp:176
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Helper template for persistent ptr specialization.