PMDK C++ bindings
1.10.1
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 = 0xF00000000000000;
612 static_assert(ptr_offset_magic %
alignof(U) == 0,
"");
613 static_assert(ptr_offset_magic %
alignof(T) == 0,
"");
615 U *tmp{
reinterpret_cast<U *
>(ptr_offset_magic)};
616 T *diff =
static_cast<T *
>(tmp);
617 return reinterpret_cast<ptrdiff_t
>(diff) -
618 reinterpret_cast<ptrdiff_t
>(tmp);
640 template <
typename T,
typename Y>
644 return OID_EQUALS(lhs.raw(), rhs.raw());
650 template <
typename T,
typename Y>
654 return !(lhs == rhs);
660 template <
typename T>
664 return lhs.get() ==
nullptr;
670 template <
typename T>
674 return lhs.get() ==
nullptr;
680 template <
typename T>
684 return lhs.get() !=
nullptr;
690 template <
typename T>
694 return lhs.get() !=
nullptr;
704 template <
typename T,
typename Y>
708 if (lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo)
709 return lhs.raw().off < rhs.raw().off;
711 return lhs.raw().pool_uuid_lo < rhs.raw().pool_uuid_lo;
719 template <
typename T,
typename Y>
731 template <
typename T,
typename Y>
743 template <
typename T,
typename Y>
755 template <
typename T>
759 return std::less<typename persistent_ptr<T>::element_type *>()(
766 template <
typename T>
770 return std::less<typename persistent_ptr<T>::element_type *>()(
777 template <
typename T>
781 return !(
nullptr < lhs);
787 template <
typename T>
791 return !(rhs <
nullptr);
797 template <
typename T>
801 return nullptr < lhs;
807 template <
typename T>
811 return rhs <
nullptr;
817 template <
typename T>
821 return !(lhs <
nullptr);
827 template <
typename T>
831 return !(
nullptr < rhs);
837 template <
typename T>
838 inline persistent_ptr<T>
842 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
843 noid.off = lhs.raw().off +
static_cast<std::uint64_t
>(s) *
sizeof(T);
851 template <
typename T>
852 inline persistent_ptr<T>
856 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
857 noid.off = lhs.raw().off -
static_cast<std::uint64_t
>(s) *
sizeof(T);
869 template <
typename T,
typename Y,
870 typename =
typename std::enable_if<
871 std::is_same<typename std::remove_cv<T>::type,
872 typename std::remove_cv<Y>::type>::value>>
876 assert(lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo);
877 auto d =
static_cast<std::ptrdiff_t
>(lhs.raw().off - rhs.raw().off);
879 return d /
static_cast<std::ptrdiff_t
>(
sizeof(T));
885 template <
typename T>
889 PMEMoid raw_oid = pptr.raw();
890 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:839
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:47
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:887
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:853
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