33 #ifndef PMEMOBJ_PERSISTENT_PTR_BASE_HPP 34 #define PMEMOBJ_PERSISTENT_PTR_BASE_HPP 36 #include <type_traits> 40 #include "libpmemobj.h" 43 #if defined(max) && defined(_WIN32) 119 template <
typename U,
120 typename =
typename std::enable_if<
121 !std::is_same<T, U>::value &&
122 std::is_same<typename std::remove_cv<T>::type,
127 this->oid.off += calculate_offset<U>();
137 typename U,
typename Dummy = void,
138 typename =
typename std::enable_if<
140 typename std::remove_cv<T>::type,
141 typename std::remove_cv<U>::type>::value &&
142 !std::is_void<U>::value,
143 decltype(static_cast<T *>(std::declval<U *>()))>::type>
147 this->oid.off += calculate_offset<U>();
158 typename =
typename std::enable_if<
160 typename std::remove_cv<T>::type,
161 typename std::remove_cv<Y>::type>::value &&
162 !std::is_void<Y>::value,
163 decltype(static_cast<T *>(std::declval<Y *>()))>::type>
186 : oid(std::move(r.oid))
197 detail::conditional_add_to_tx(
this);
198 this->oid = std::move(r.oid);
230 detail::conditional_add_to_tx(
this);
246 template <
typename Y,
247 typename =
typename std::enable_if<
248 std::is_convertible<Y *, T *>::value>::type>
265 detail::conditional_add_to_tx(
this);
266 detail::conditional_add_to_tx(&other);
267 std::swap(this->oid, other.oid);
280 if (this->oid.pool_uuid_lo ==
281 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
282 return reinterpret_cast<element_type *>(oid.off);
285 pmemobj_direct(this->oid));
317 explicit operator bool() const noexcept
319 return get() !=
nullptr;
335 static_assert(!std::is_polymorphic<element_type>::value,
336 "Polymorphic types are not supported");
348 if (OID_IS_NULL(oid)) {
349 oid.pool_uuid_lo = std::numeric_limits<decltype(
350 oid.pool_uuid_lo)>::max();
351 oid.off =
reinterpret_cast<decltype(oid.off)
>(vptr);
369 template <
typename U>
373 static const ptrdiff_t ptr_offset_magic = 0xDEADBEEF;
375 U *tmp{
reinterpret_cast<U *
>(ptr_offset_magic)};
376 T *diff =
static_cast<T *
>(tmp);
377 return reinterpret_cast<ptrdiff_t
>(diff) -
378 reinterpret_cast<ptrdiff_t>(tmp);
Persistent_ptr base class.
Definition: persistent_ptr_base.hpp:62
persistent_ptr_base & operator=(persistent_ptr_base &&r)
Defaulted move assignment operator.
Definition: persistent_ptr_base.hpp:195
Helper template for persistent ptr specialization.
persistent_ptr_base(persistent_ptr_base< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr_base.hpp:124
persistent_ptr_base & operator=(persistent_ptr_base< Y > const &r)
Converting assignment operator from a different persistent_ptr<>.
Definition: persistent_ptr_base.hpp:250
pmem::detail::sp_element< T >::type element_type
Type of an actual object with all qualifier removed, used for easy underlying type access...
Definition: persistent_ptr_base.hpp:73
void swap(persistent_ptr_base &other)
Swaps two persistent_ptr objects of the same type.
Definition: persistent_ptr_base.hpp:263
persistent_ptr_base & operator=(std::nullptr_t &&)
Nullptr move assignment operator.
Definition: persistent_ptr_base.hpp:228
persistent_ptr_base(persistent_ptr_base &&r) noexcept
Defaulted move constructor.
Definition: persistent_ptr_base.hpp:185
persistent_ptr_base(persistent_ptr_base< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr_base.hpp:144
Commonly used functionality.
persistent_ptr_base(element_type *ptr)
Volatile pointer constructor.
Definition: persistent_ptr_base.hpp:109
persistent_ptr_base()
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:78
ptrdiff_t calculate_offset() const
Calculate in-object offset for structures with inheritance.
Definition: persistent_ptr_base.hpp:371
persistent_ptr_base & operator=(persistent_ptr_base const &r)
Assignment operator.
Definition: persistent_ptr_base.hpp:214
persistent_ptr_base(element_type *vptr, int)
Private constructor enabling persistent_ptrs to volatile objects.
Definition: persistent_ptr_base.hpp:346
const PMEMoid & raw() const noexcept
Get PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:296
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:309
persistent_ptr_base(PMEMoid oid) noexcept
PMEMoid constructor.
Definition: persistent_ptr_base.hpp:96
Definition: allocator.hpp:48