PMDK C++ bindings  1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
persistent_ptr_base.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2016-2020, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP
10 #define LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP
11 
12 #include <cstdint>
13 #include <type_traits>
14 
17 #include <libpmemobj/base.h>
18 
19 /* Windows has a max macro which collides with std::numeric_limits::max */
20 #if defined(max) && defined(_WIN32)
21 #undef max
22 #endif
23 
24 namespace pmem
25 {
26 
27 namespace obj
28 {
29 
43 public:
47  persistent_ptr_base() noexcept : oid(OID_NULL)
48  {
49  }
50 
51  /*
52  * Curly braces initialization is not used because the
53  * PMEMoid is a plain C (POD) type and we can't add a default
54  * constructor in there.
55  */
56 
64  persistent_ptr_base(PMEMoid oid) noexcept : oid(oid)
65  {
66  }
67 
68  /*
69  * Copy constructor.
70  *
71  * @param r Persistent pointer to the same type.
72  */
73  persistent_ptr_base(persistent_ptr_base const &r) noexcept : oid(r.oid)
74  {
75  }
76 
81  : oid(std::move(r.oid))
82  {
83  }
84 
90  {
91  detail::conditional_add_to_tx(this);
92  this->oid = std::move(r.oid);
93 
94  return *this;
95  }
96 
109  {
110  detail::conditional_add_to_tx(this);
111  this->oid = r.oid;
112 
113  return *this;
114  }
115 
123  operator=(std::nullptr_t &&)
124  {
125  detail::conditional_add_to_tx(this);
126  this->oid = {0, 0};
127  return *this;
128  }
129 
135  void
137  {
138  detail::conditional_add_to_tx(this);
139  detail::conditional_add_to_tx(&other);
140  std::swap(this->oid, other.oid);
141  }
142 
150  const PMEMoid &
151  raw() const noexcept
152  {
153  return this->oid;
154  }
155 
163  PMEMoid *
164  raw_ptr() noexcept
165  {
166  return &(this->oid);
167  }
168 
169 protected:
170  /* The underlying PMEMoid of the held object. */
171  PMEMoid oid;
172 };
173 
174 } /* namespace obj */
175 
176 } /* namespace pmem */
177 
178 #endif /* LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP */
pmem::obj::persistent_ptr_base::operator=
persistent_ptr_base & operator=(persistent_ptr_base const &r)
Assignment operator.
Definition: persistent_ptr_base.hpp:108
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
pmem::obj::persistent_ptr_base::raw_ptr
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:164
common.hpp
Commonly used functionality.
pmem::obj::persistent_ptr_base::raw
const PMEMoid & raw() const noexcept
Get PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:151
pmem::obj::persistent_ptr_base::swap
void swap(persistent_ptr_base &other)
Swaps two persistent_ptr objects of the same type.
Definition: persistent_ptr_base.hpp:136
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::persistent_ptr_base::operator=
persistent_ptr_base & operator=(persistent_ptr_base &&r)
Move assignment operator.
Definition: persistent_ptr_base.hpp:89
pmem::obj::persistent_ptr_base
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
pmem::obj::persistent_ptr_base::operator=
persistent_ptr_base & operator=(std::nullptr_t &&)
Nullptr move assignment operator.
Definition: persistent_ptr_base.hpp:123
pmem::obj::persistent_ptr_base::persistent_ptr_base
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:47