PMDK C++ bindings  1.13.0-git107.g7e59f08f
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  {
92  this->oid = std::move(r.oid);
93 
94  return *this;
95  }
96 
109  {
111  this->oid = r.oid;
112 
113  return *this;
114  }
115 
123  operator=(std::nullptr_t &&)
124  {
126  this->oid = {0, 0};
127  return *this;
128  }
129 
135  void
137  {
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 */
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
persistent_ptr_base & operator=(std::nullptr_t &&)
Nullptr move assignment operator.
Definition: persistent_ptr_base.hpp:123
persistent_ptr_base & operator=(persistent_ptr_base &&r)
Move assignment operator.
Definition: persistent_ptr_base.hpp:89
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:164
void swap(persistent_ptr_base &other)
Swaps two persistent_ptr objects of the same type.
Definition: persistent_ptr_base.hpp:136
persistent_ptr_base & operator=(persistent_ptr_base const &r)
Assignment operator.
Definition: persistent_ptr_base.hpp:108
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:47
persistent_ptr_base(PMEMoid oid) noexcept
PMEMoid constructor.
Definition: persistent_ptr_base.hpp:64
const PMEMoid & raw() const noexcept
Get PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:151
persistent_ptr_base(persistent_ptr_base &&r) noexcept
Move constructor.
Definition: persistent_ptr_base.hpp:80
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.