PMDK C++ bindings
1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_PERSISTENT_PTR_HPP
39 #define LIBPMEMOBJ_CPP_PERSISTENT_PTR_HPP
50 #include <libpmemobj/base.h>
85 if (this->oid.pool_uuid_lo ==
86 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
87 return reinterpret_cast<element_type *
>(oid.off);
89 return static_cast<element_type *
>(
90 pmemobj_direct(this->oid));
94 typename =
typename std::enable_if<
95 std::is_convertible<Y *, void *>::value>::type>
104 explicit operator bool()
const noexcept
106 return get() !=
nullptr;
131 if (this->oid.pool_uuid_lo ==
132 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
133 return reinterpret_cast<element_type *
>(oid.off);
135 return static_cast<element_type *
>(
136 pmemobj_direct(this->oid));
139 template <
typename Y,
140 typename =
typename std::enable_if<
141 std::is_convertible<Y *, const void *>::value>::type>
150 explicit operator bool()
const noexcept
152 return get() !=
nullptr;
211 template <
typename T>
216 template <
typename U>
267 template <
typename U,
268 typename =
typename std::enable_if<
269 !std::is_same<T, U>::value &&
270 std::is_same<typename std::remove_cv<T>::type,
276 static_cast<std::uint64_t
>(calculate_offset<U>());
286 typename U,
typename Dummy = void,
287 typename =
typename std::enable_if<
289 typename std::remove_cv<T>::type,
290 typename std::remove_cv<U>::type>::value &&
291 !std::is_void<U>::value,
292 decltype(
static_cast<T *
>(std::declval<U *>()))>::type>
297 static_cast<std::uint64_t
>(calculate_offset<U>());
316 typename pmem::detail::sp_dereference<T>::type
operator*() const
325 typename pmem::detail::sp_member_access<T>::type
operator->() const
336 template <typename = typename std::enable_if<!std::is_void<T>::value>>
337 typename pmem::detail::sp_array_access<T>::type
341 (i < pmem::detail::sp_extent<T>::value ||
342 pmem::detail::sp_extent<T>::value == 0) &&
343 "persistent array index out of bounds");
345 return this->
get()[i];
354 detail::conditional_add_to_tx(
this);
355 this->oid.off +=
sizeof(T);
366 PMEMoid noid = this->oid;
378 detail::conditional_add_to_tx(
this);
379 this->oid.off -=
sizeof(T);
390 PMEMoid noid = this->oid;
402 detail::conditional_add_to_tx(
this);
403 this->oid.off +=
static_cast<std::uint64_t
>(s) *
sizeof(T);
414 detail::conditional_add_to_tx(
this);
415 this->oid.off -=
static_cast<std::uint64_t
>(s) *
sizeof(T);
431 template <
typename Y,
432 typename =
typename std::enable_if<
433 std::is_convertible<Y *, T *>::value>::type>
445 explicit operator bool() const noexcept
447 return get() !=
nullptr;
474 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
478 "Cannot get pool from persistent pointer");
480 pmemobj_persist(pop, this->
get(),
sizeof(T));
503 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
507 "Cannot get pool from persistent pointer");
509 pmemobj_flush(pop, this->
get(),
sizeof(T));
540 if (this->oid.pool_uuid_lo ==
541 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
545 pmemobj_direct(this->oid));
600 static_assert(!std::is_polymorphic<element_type>::value,
601 "Polymorphic types are not supported");
613 if (OID_IS_NULL(oid)) {
614 oid.pool_uuid_lo = std::numeric_limits<decltype(
615 oid.pool_uuid_lo)>::max();
616 oid.off =
reinterpret_cast<decltype(oid.off)
>(vptr);
635 template <
typename U>
639 static const ptrdiff_t ptr_offset_magic = 0xF00000000000000;
641 static_assert(ptr_offset_magic %
alignof(U) == 0,
"");
642 static_assert(ptr_offset_magic %
alignof(T) == 0,
"");
644 U *tmp{
reinterpret_cast<U *
>(ptr_offset_magic)};
645 T *diff =
static_cast<T *
>(tmp);
646 return reinterpret_cast<ptrdiff_t
>(diff) -
647 reinterpret_cast<ptrdiff_t
>(tmp);
669 template <
typename T,
typename Y>
673 return OID_EQUALS(lhs.raw(), rhs.raw());
679 template <
typename T,
typename Y>
683 return !(lhs == rhs);
689 template <
typename T>
693 return lhs.get() ==
nullptr;
699 template <
typename T>
703 return lhs.get() ==
nullptr;
709 template <
typename T>
713 return lhs.get() !=
nullptr;
719 template <
typename T>
723 return lhs.get() !=
nullptr;
733 template <
typename T,
typename Y>
737 if (lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo)
738 return lhs.raw().off < rhs.raw().off;
740 return lhs.raw().pool_uuid_lo < rhs.raw().pool_uuid_lo;
748 template <
typename T,
typename Y>
760 template <
typename T,
typename Y>
772 template <
typename T,
typename Y>
784 template <
typename T>
788 return std::less<typename persistent_ptr<T>::element_type *>()(
795 template <
typename T>
799 return std::less<typename persistent_ptr<T>::element_type *>()(
806 template <
typename T>
810 return !(
nullptr < lhs);
816 template <
typename T>
820 return !(rhs <
nullptr);
826 template <
typename T>
830 return nullptr < lhs;
836 template <
typename T>
840 return rhs <
nullptr;
846 template <
typename T>
850 return !(lhs <
nullptr);
856 template <
typename T>
860 return !(
nullptr < rhs);
866 template <
typename T>
867 inline persistent_ptr<T>
871 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
872 noid.off = lhs.raw().off +
static_cast<std::uint64_t
>(s) *
sizeof(T);
880 template <
typename T>
881 inline persistent_ptr<T>
885 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
886 noid.off = lhs.raw().off -
static_cast<std::uint64_t
>(s) *
sizeof(T);
898 template <
typename T,
typename Y,
899 typename =
typename std::enable_if<
900 std::is_same<typename std::remove_cv<T>::type,
901 typename std::remove_cv<Y>::type>::value>>
905 assert(lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo);
906 auto d =
static_cast<std::ptrdiff_t
>(lhs.raw().off - rhs.raw().off);
908 return d /
static_cast<std::ptrdiff_t
>(
sizeof(T));
914 template <
typename T>
918 PMEMoid raw_oid = pptr.raw();
919 os << std::hex <<
"0x" << raw_oid.pool_uuid_lo <<
", 0x" << raw_oid.off
std::ptrdiff_t difference_type
The persistent_ptr difference type.
Definition: persistent_ptr.hpp:576
persistent_ptr< T > operator+(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Addition operator for persistent pointers.
Definition: persistent_ptr.hpp:868
element_type * get() const noexcept
Get the direct pointer.
Definition: persistent_ptr.hpp:538
T & reference
The reference type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:586
ptrdiff_t calculate_offset() const
Calculate in-object offset for structures with inheritance.
Definition: persistent_ptr.hpp:637
persistent_ptr(persistent_ptr< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:272
Custom pool error class.
Definition: pexceptions.hpp:74
void flush(void)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:501
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:312
Persistent memory namespace.
Definition: allocation_flag.hpp:44
persistent_ptr const void specialization.
Definition: persistent_ptr.hpp:117
T value_type
The type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:581
std::random_access_iterator_tag iterator_category
Random access iterator requirements (members)
Definition: persistent_ptr.hpp:571
Commonly used functionality.
persistent_ptr< T > & operator--()
Prefix decrement operator.
Definition: persistent_ptr.hpp:376
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:763
persistent_ptr< T > operator++(int)
Postfix increment operator.
Definition: persistent_ptr.hpp:364
void persist(void)
Persists what the persistent pointer points to.
Definition: persistent_ptr.hpp:472
static persistent_ptr< T > pointer_to(T &ref)
Create a persistent pointer from a given reference.
Definition: persistent_ptr.hpp:525
persistent_ptr< T > operator--(int)
Postfix decrement operator.
Definition: persistent_ptr.hpp:388
void swap(persistent_ptr_base &other)
Swaps two persistent_ptr objects of the same type.
Definition: persistent_ptr_base.hpp:165
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:773
bool operator==(standard_alloc_policy< T > const &, standard_alloc_policy< T2 > const &)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:402
pmem::detail::sp_member_access< T >::type operator->() const noexcept
Member access operator.
Definition: persistent_ptr.hpp:325
persistent_ptr(persistent_ptr< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:293
Resides on pmem class.
Definition: p.hpp:64
std::ostream & operator<<(std::ostream &os, persistent_ptr< T > const &pptr)
Ostream operator for the persistent pointer.
Definition: persistent_ptr.hpp:916
persistent_ptr(persistent_ptr< void > const &rhs) noexcept
Explicit void specialization of the converting constructor.
Definition: persistent_ptr.hpp:235
persistent_ptr< T > & operator-=(std::ptrdiff_t s)
Subtraction assignment operator.
Definition: persistent_ptr.hpp:412
pmem::detail::sp_dereference< T >::type operator*() const noexcept
Dereference operator.
Definition: persistent_ptr.hpp:316
persistent_ptr< T > & operator++()
Prefix increment operator.
Definition: persistent_ptr.hpp:352
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:76
persistent_ptr void specialization.
Definition: persistent_ptr.hpp:71
persistent_ptr< T > operator-(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Subtraction operator for persistent pointers.
Definition: persistent_ptr.hpp:882
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:913
bool operator!=(const allocator< T, P, Tr > &lhs, const OtherAllocator &rhs)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:518
void persist(pool_base &pop)
Persists the content of the underlying object.
Definition: persistent_ptr.hpp:460
Helper template for persistent ptr specialization.
pmem::detail::sp_element< T >::type element_type
Type of the actual object with all qualifiers removed, used for easy underlying type access.
Definition: persistent_ptr.hpp:223
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:349
bool bool_type
The used bool_type.
Definition: persistent_ptr.hpp:562
Persistent pointer class.
Definition: persistent_ptr.hpp:212
void flush(pool_base &pop)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:489
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:752
persistent_ptr< T > & operator+=(std::ptrdiff_t s)
Addition assignment operator.
Definition: persistent_ptr.hpp:400
void verify_type()
Verify if element_type is not polymorphic.
Definition: persistent_ptr.hpp:598
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:783
persistent_ptr(element_type *vptr, int)
Private constructor enabling persistent_ptrs to volatile objects.
Definition: persistent_ptr.hpp:611
persistent_ptr(persistent_ptr< const void > const &rhs) noexcept
Explicit const void specialization of the converting constructor.
Definition: persistent_ptr.hpp:243
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:71
persistent_ptr(element_type *ptr)
Volatile pointer constructor.
Definition: persistent_ptr.hpp:256
Base class for persistent_ptr.
The non-template pool base class.
Definition: pool.hpp:75
persistent_ptr< T > & operator=(persistent_ptr< Y > const &r)
Converting assignment operator from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:435
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:76
pmem::detail::sp_array_access< T >::type operator[](std::ptrdiff_t i) const noexcept
Array access operator.
Definition: persistent_ptr.hpp:338