PMDK C++ bindings  1.9.1
This is the C++ bindings documentation for PMDK's libpmemobj.
persistent_ptr_base.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2020, 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 LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP
39 #define LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP
40 
41 #include <cstdint>
42 #include <type_traits>
43 
46 #include <libpmemobj/base.h>
47 
48 /* Windows has a max macro which collides with std::numeric_limits::max */
49 #if defined(max) && defined(_WIN32)
50 #undef max
51 #endif
52 
53 namespace pmem
54 {
55 
56 namespace obj
57 {
58 
72 public:
76  persistent_ptr_base() noexcept : oid(OID_NULL)
77  {
78  }
79 
80  /*
81  * Curly braces initialization is not used because the
82  * PMEMoid is a plain C (POD) type and we can't add a default
83  * constructor in there.
84  */
85 
93  persistent_ptr_base(PMEMoid oid) noexcept : oid(oid)
94  {
95  }
96 
97  /*
98  * Copy constructor.
99  *
100  * @param r Persistent pointer to the same type.
101  */
102  persistent_ptr_base(persistent_ptr_base const &r) noexcept : oid(r.oid)
103  {
104  }
105 
110  : oid(std::move(r.oid))
111  {
112  }
113 
119  {
120  detail::conditional_add_to_tx(this);
121  this->oid = std::move(r.oid);
122 
123  return *this;
124  }
125 
138  {
139  detail::conditional_add_to_tx(this);
140  this->oid = r.oid;
141 
142  return *this;
143  }
144 
152  operator=(std::nullptr_t &&)
153  {
154  detail::conditional_add_to_tx(this);
155  this->oid = {0, 0};
156  return *this;
157  }
158 
164  void
166  {
167  detail::conditional_add_to_tx(this);
168  detail::conditional_add_to_tx(&other);
169  std::swap(this->oid, other.oid);
170  }
171 
179  const PMEMoid &
180  raw() const noexcept
181  {
182  return this->oid;
183  }
184 
192  PMEMoid *
193  raw_ptr() noexcept
194  {
195  return &(this->oid);
196  }
197 
198 protected:
199  /* The underlying PMEMoid of the held object. */
200  PMEMoid oid;
201 };
202 
203 } /* namespace obj */
204 
205 } /* namespace pmem */
206 
207 #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:137
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:44
pmem::obj::persistent_ptr_base::raw_ptr
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:193
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:180
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:165
pmem::obj::swap
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:913
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:118
pmem::obj::persistent_ptr_base
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:71
pmem::obj::persistent_ptr_base::operator=
persistent_ptr_base & operator=(std::nullptr_t &&)
Nullptr move assignment operator.
Definition: persistent_ptr_base.hpp:152
pmem::obj::persistent_ptr_base::persistent_ptr_base
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:76