PMDK C++ bindings
1.7
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP
39 #define LIBPMEMOBJ_CPP_PERSISTENT_PTR_BASE_HPP
42 #include <type_traits>
46 #include <libpmemobj.h>
49 #if defined(max) && defined(_WIN32)
125 template <
typename U,
126 typename =
typename std::enable_if<
127 !std::is_same<T, U>::value &&
128 std::is_same<typename std::remove_cv<T>::type,
134 static_cast<std::uint64_t
>(calculate_offset<U>());
144 typename U,
typename Dummy = void,
145 typename =
typename std::enable_if<
147 typename std::remove_cv<T>::type,
148 typename std::remove_cv<U>::type>::value &&
149 !std::is_void<U>::value,
150 decltype(
static_cast<T *
>(std::declval<U *>()))>::type>
155 static_cast<std::uint64_t
>(calculate_offset<U>());
166 typename =
typename std::enable_if<
168 typename std::remove_cv<T>::type,
169 typename std::remove_cv<Y>::type>::value &&
170 !std::is_void<Y>::value,
171 decltype(
static_cast<T *
>(std::declval<Y *>()))>::type>
194 : oid(std::move(r.oid))
205 detail::conditional_add_to_tx(
this);
206 this->oid = std::move(r.oid);
238 detail::conditional_add_to_tx(
this);
254 template <
typename Y,
255 typename =
typename std::enable_if<
256 std::is_convertible<Y *, T *>::value>::type>
273 detail::conditional_add_to_tx(
this);
274 detail::conditional_add_to_tx(&other);
275 std::swap(this->oid, other.oid);
288 if (this->oid.pool_uuid_lo ==
289 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
293 pmemobj_direct(this->oid));
325 explicit operator bool() const noexcept
327 return get() !=
nullptr;
337 static_assert(!std::is_polymorphic<element_type>::value,
338 "Polymorphic types are not supported");
350 if (OID_IS_NULL(oid)) {
351 oid.pool_uuid_lo = std::numeric_limits<decltype(
352 oid.pool_uuid_lo)>::max();
353 oid.off =
reinterpret_cast<decltype(oid.off)
>(vptr);
371 template <
typename U>
375 static const ptrdiff_t ptr_offset_magic = 0xF00000000000000;
377 static_assert(ptr_offset_magic %
alignof(U) == 0,
"");
378 static_assert(ptr_offset_magic %
alignof(T) == 0,
"");
380 U *tmp{
reinterpret_cast<U *
>(ptr_offset_magic)};
381 T *diff =
static_cast<T *
>(tmp);
382 return reinterpret_cast<ptrdiff_t
>(diff) -
383 reinterpret_cast<ptrdiff_t
>(tmp);
Persistent_ptr base class.
Definition: persistent_ptr_base.hpp:68
element_type * get() const noexcept
Get a direct pointer.
Definition: persistent_ptr_base.hpp:286
persistent_ptr_base(persistent_ptr_base< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr_base.hpp:151
const PMEMoid & raw() const noexcept
Get PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:304
Commonly used functionality.
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:79
persistent_ptr_base(persistent_ptr_base< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr_base.hpp:130
persistent_ptr_base & operator=(std::nullptr_t &&)
Nullptr move assignment operator.
Definition: persistent_ptr_base.hpp:236
persistent_ptr_base(persistent_ptr_base &&r) noexcept
Defaulted move constructor.
Definition: persistent_ptr_base.hpp:193
persistent_ptr_base & operator=(persistent_ptr_base const &r)
Assignment operator.
Definition: persistent_ptr_base.hpp:222
persistent_ptr_base & operator=(persistent_ptr_base< Y > const &r)
Converting assignment operator from a different persistent_ptr<>.
Definition: persistent_ptr_base.hpp:258
Helper template for persistent ptr specialization.
PMEMoid * raw_ptr() noexcept
Get pointer to PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:317
persistent_ptr_base(PMEMoid oid) noexcept
PMEMoid constructor.
Definition: persistent_ptr_base.hpp:102
persistent_ptr_base()
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:84
void swap(persistent_ptr_base &other)
Swaps two persistent_ptr objects of the same type.
Definition: persistent_ptr_base.hpp:271
persistent_ptr_base(element_type *vptr, int)
Private constructor enabling persistent_ptrs to volatile objects.
Definition: persistent_ptr_base.hpp:348
persistent_ptr_base & operator=(persistent_ptr_base &&r)
Defaulted move assignment operator.
Definition: persistent_ptr_base.hpp:203
persistent_ptr_base(element_type *ptr)
Volatile pointer constructor.
Definition: persistent_ptr_base.hpp:115
ptrdiff_t calculate_offset() const
Calculate in-object offset for structures with inheritance.
Definition: persistent_ptr_base.hpp:373