PMDK C++ bindings
1.10
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_PERSISTENT_PTR_HPP
10 #define LIBPMEMOBJ_CPP_PERSISTENT_PTR_HPP
21 #include <libpmemobj/base.h>
56 if (this->oid.pool_uuid_lo ==
57 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
58 return reinterpret_cast<element_type *
>(oid.off);
60 return static_cast<element_type *
>(
61 pmemobj_direct(this->oid));
65 typename =
typename std::enable_if<
66 std::is_convertible<Y *, void *>::value>::type>
75 explicit operator bool()
const noexcept
77 return get() !=
nullptr;
102 if (this->oid.pool_uuid_lo ==
103 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
104 return reinterpret_cast<element_type *
>(oid.off);
106 return static_cast<element_type *
>(
107 pmemobj_direct(this->oid));
110 template <
typename Y,
111 typename =
typename std::enable_if<
112 std::is_convertible<Y *, const void *>::value>::type>
121 explicit operator bool()
const noexcept
123 return get() !=
nullptr;
182 template <
typename T>
187 template <
typename U>
238 template <
typename U,
239 typename =
typename std::enable_if<
240 !std::is_same<T, U>::value &&
241 std::is_same<typename std::remove_cv<T>::type,
247 static_cast<std::uint64_t
>(calculate_offset<U>());
257 typename U,
typename Dummy = void,
258 typename =
typename std::enable_if<
260 typename std::remove_cv<T>::type,
261 typename std::remove_cv<U>::type>::value &&
262 !std::is_void<U>::value,
263 decltype(
static_cast<T *
>(std::declval<U *>()))>::type>
268 static_cast<std::uint64_t
>(calculate_offset<U>());
287 typename pmem::detail::sp_dereference<T>::type
operator*() const
296 typename pmem::detail::sp_member_access<T>::type
operator->() const
307 template <typename = typename std::enable_if<!std::is_void<T>::value>>
308 typename pmem::detail::sp_array_access<T>::type
312 (i < pmem::detail::sp_extent<T>::value ||
313 pmem::detail::sp_extent<T>::value == 0) &&
314 "persistent array index out of bounds");
316 return this->
get()[i];
325 detail::conditional_add_to_tx(
this);
326 this->oid.off +=
sizeof(T);
337 PMEMoid noid = this->oid;
349 detail::conditional_add_to_tx(
this);
350 this->oid.off -=
sizeof(T);
361 PMEMoid noid = this->oid;
373 detail::conditional_add_to_tx(
this);
374 this->oid.off +=
static_cast<std::uint64_t
>(s) *
sizeof(T);
385 detail::conditional_add_to_tx(
this);
386 this->oid.off -=
static_cast<std::uint64_t
>(s) *
sizeof(T);
402 template <
typename Y,
403 typename =
typename std::enable_if<
404 std::is_convertible<Y *, T *>::value>::type>
416 explicit operator bool() const noexcept
418 return get() !=
nullptr;
445 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
449 "Cannot get pool from persistent pointer");
451 pmemobj_persist(pop, this->
get(),
sizeof(T));
474 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
478 "Cannot get pool from persistent pointer");
480 pmemobj_flush(pop, this->
get(),
sizeof(T));
511 if (this->oid.pool_uuid_lo ==
512 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
516 pmemobj_direct(this->oid));
571 static_assert(!std::is_polymorphic<element_type>::value,
572 "Polymorphic types are not supported");
584 if (OID_IS_NULL(oid)) {
585 oid.pool_uuid_lo = std::numeric_limits<decltype(
586 oid.pool_uuid_lo)>::max();
587 oid.off =
reinterpret_cast<decltype(oid.off)
>(vptr);
606 template <
typename U>
610 static const ptrdiff_t ptr_offset_magic = 0xDEADBEEF;
612 U *tmp{
reinterpret_cast<U *
>(ptr_offset_magic)};
613 T *diff =
static_cast<T *
>(tmp);
614 return reinterpret_cast<ptrdiff_t
>(diff) -
615 reinterpret_cast<ptrdiff_t
>(tmp);
637 template <
typename T,
typename Y>
641 return OID_EQUALS(lhs.raw(), rhs.raw());
647 template <
typename T,
typename Y>
651 return !(lhs == rhs);
657 template <
typename T>
661 return lhs.get() ==
nullptr;
667 template <
typename T>
671 return lhs.get() ==
nullptr;
677 template <
typename T>
681 return lhs.get() !=
nullptr;
687 template <
typename T>
691 return lhs.get() !=
nullptr;
701 template <
typename T,
typename Y>
705 if (lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo)
706 return lhs.raw().off < rhs.raw().off;
708 return lhs.raw().pool_uuid_lo < rhs.raw().pool_uuid_lo;
716 template <
typename T,
typename Y>
728 template <
typename T,
typename Y>
740 template <
typename T,
typename Y>
752 template <
typename T>
756 return std::less<typename persistent_ptr<T>::element_type *>()(
763 template <
typename T>
767 return std::less<typename persistent_ptr<T>::element_type *>()(
774 template <
typename T>
778 return !(
nullptr < lhs);
784 template <
typename T>
788 return !(rhs <
nullptr);
794 template <
typename T>
798 return nullptr < lhs;
804 template <
typename T>
808 return rhs <
nullptr;
814 template <
typename T>
818 return !(lhs <
nullptr);
824 template <
typename T>
828 return !(
nullptr < rhs);
834 template <
typename T>
835 inline persistent_ptr<T>
839 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
840 noid.off = lhs.raw().off +
static_cast<std::uint64_t
>(s) *
sizeof(T);
848 template <
typename T>
849 inline persistent_ptr<T>
853 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
854 noid.off = lhs.raw().off -
static_cast<std::uint64_t
>(s) *
sizeof(T);
866 template <
typename T,
typename Y,
867 typename =
typename std::enable_if<
868 std::is_same<typename std::remove_cv<T>::type,
869 typename std::remove_cv<Y>::type>::value>>
873 assert(lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo);
874 auto d =
static_cast<std::ptrdiff_t
>(lhs.raw().off - rhs.raw().off);
876 return d /
static_cast<std::ptrdiff_t
>(
sizeof(T));
882 template <
typename T>
886 PMEMoid raw_oid = pptr.raw();
887 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:547
persistent_ptr< T > operator+(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Addition operator for persistent pointers.
Definition: persistent_ptr.hpp:836
element_type * get() const noexcept
Get the direct pointer.
Definition: persistent_ptr.hpp:509
T & reference
The reference type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:557
ptrdiff_t calculate_offset() const
Calculate in-object offset for structures with inheritance.
Definition: persistent_ptr.hpp:608
persistent_ptr(persistent_ptr< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:243
Custom pool error class.
Definition: pexceptions.hpp:45
void flush(void)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:472
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:283
Persistent memory namespace.
Definition: allocation_flag.hpp:15
persistent_ptr const void specialization.
Definition: persistent_ptr.hpp:88
T value_type
The type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:552
std::random_access_iterator_tag iterator_category
Random access iterator requirements (members)
Definition: persistent_ptr.hpp:542
Commonly used functionality.
persistent_ptr< T > & operator--()
Prefix decrement operator.
Definition: persistent_ptr.hpp:347
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:734
persistent_ptr< T > operator++(int)
Postfix increment operator.
Definition: persistent_ptr.hpp:335
void persist(void)
Persists what the persistent pointer points to.
Definition: persistent_ptr.hpp:443
static persistent_ptr< T > pointer_to(T &ref)
Create a persistent pointer from a given reference.
Definition: persistent_ptr.hpp:496
persistent_ptr< T > operator--(int)
Postfix decrement operator.
Definition: persistent_ptr.hpp:359
void swap(persistent_ptr_base &other)
Swaps two persistent_ptr objects of the same type.
Definition: persistent_ptr_base.hpp:136
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:744
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:406
pmem::detail::sp_member_access< T >::type operator->() const noexcept
Member access operator.
Definition: persistent_ptr.hpp:296
persistent_ptr(persistent_ptr< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:264
Resides on pmem class.
Definition: p.hpp:35
std::ostream & operator<<(std::ostream &os, persistent_ptr< T > const &pptr)
Ostream operator for the persistent pointer.
Definition: persistent_ptr.hpp:884
persistent_ptr(persistent_ptr< void > const &rhs) noexcept
Explicit void specialization of the converting constructor.
Definition: persistent_ptr.hpp:206
persistent_ptr< T > & operator-=(std::ptrdiff_t s)
Subtraction assignment operator.
Definition: persistent_ptr.hpp:383
pmem::detail::sp_dereference< T >::type operator*() const noexcept
Dereference operator.
Definition: persistent_ptr.hpp:287
persistent_ptr< T > & operator++()
Prefix increment operator.
Definition: persistent_ptr.hpp:323
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:47
persistent_ptr void specialization.
Definition: persistent_ptr.hpp:42
persistent_ptr< T > operator-(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Subtraction operator for persistent pointers.
Definition: persistent_ptr.hpp:850
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:884
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:522
void persist(pool_base &pop)
Persists the content of the underlying object.
Definition: persistent_ptr.hpp:431
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:194
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:320
bool bool_type
The used bool_type.
Definition: persistent_ptr.hpp:533
Persistent pointer class.
Definition: persistent_ptr.hpp:183
void flush(pool_base &pop)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:460
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:723
persistent_ptr< T > & operator+=(std::ptrdiff_t s)
Addition assignment operator.
Definition: persistent_ptr.hpp:371
void verify_type()
Verify if element_type is not polymorphic.
Definition: persistent_ptr.hpp:569
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:754
persistent_ptr(element_type *vptr, int)
Private constructor enabling persistent_ptrs to volatile objects.
Definition: persistent_ptr.hpp:582
persistent_ptr(persistent_ptr< const void > const &rhs) noexcept
Explicit const void specialization of the converting constructor.
Definition: persistent_ptr.hpp:214
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
persistent_ptr(element_type *ptr)
Volatile pointer constructor.
Definition: persistent_ptr.hpp:227
Base class for persistent_ptr.
The non-template pool base class.
Definition: pool.hpp:46
persistent_ptr< T > & operator=(persistent_ptr< Y > const &r)
Converting assignment operator from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:406
persistent_ptr_base() noexcept
Default constructor, zeroes the PMEMoid.
Definition: persistent_ptr_base.hpp:47
pmem::detail::sp_array_access< T >::type operator[](std::ptrdiff_t i) const noexcept
Array access operator.
Definition: persistent_ptr.hpp:309