PMDK C++ bindings  1.11.1
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-2020, 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 {
34 template <typename T>
35 class p {
36  typedef p<T> this_type;
37 
38 public:
46  p(const T &_val) noexcept : val{_val}
47  {
48  }
49 
53  p() = default;
54 
65  p &
66  operator=(const p &rhs)
67  {
68  this_type(rhs).swap(*this);
69 
70  return *this;
71  }
72 
83  template <typename Y,
84  typename = typename std::enable_if<
85  std::is_convertible<Y, T>::value>::type>
86  p &
87  operator=(const p<Y> &rhs)
88  {
89  this_type(rhs).swap(*this);
90 
91  return *this;
92  }
93 
97  operator T() const noexcept
98  {
99  return this->val;
100  }
101 
112  T &
114  {
115  detail::conditional_add_to_tx(this);
116 
117  return this->val;
118  }
119 
127  const T &
128  get_ro() const noexcept
129  {
130  return this->val;
131  }
132 
139  void
140  swap(p &other)
141  {
142  detail::conditional_add_to_tx(this);
143  detail::conditional_add_to_tx(&other);
144  std::swap(this->val, other.val);
145  }
146 
147 private:
148  T val;
149 };
150 
157 template <class T>
158 inline void
159 swap(p<T> &a, p<T> &b)
160 {
161  a.swap(b);
162 }
163 
164 } /* namespace obj */
165 
166 } /* namespace pmem */
167 
168 #endif /* LIBPMEMOBJ_CPP_P_HPP */
pmem::obj::p::get_ro
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:128
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
pmem::obj::swap
void swap(p< T > &a, p< T > &b)
Swaps two p objects of the same type.
Definition: p.hpp:159
pmem::obj::p::swap
void swap(p &other)
Swaps two p objects of the same type.
Definition: p.hpp:140
common.hpp
Commonly used functionality.
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:35
pmem::obj::p::operator=
p & operator=(const p< Y > &rhs)
Converting assignment operator from a different p<>.
Definition: p.hpp:87
pmem::obj::swap
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:880
specialization.hpp
Helper template for persistent ptr specialization.
pmem::obj::p::p
p()=default
Defaulted constructor.
pmem::obj::p::get_rw
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:113
pmem::obj::p::p
p(const T &_val) noexcept
Value constructor.
Definition: p.hpp:46
pmem::obj::p::operator=
p & operator=(const p &rhs)
Assignment operator.
Definition: p.hpp:66