PMDK C++ bindings
1.12-git53.g67ba2be4
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;
151 template <
typename T>
156 template <
typename U>
207 template <
typename U,
208 typename =
typename std::enable_if<
209 !std::is_same<T, U>::value &&
210 std::is_same<typename std::remove_cv<T>::type,
216 static_cast<std::uint64_t
>(calculate_offset<U>());
226 typename U,
typename Dummy = void,
227 typename =
typename std::enable_if<
229 typename std::remove_cv<T>::type,
230 typename std::remove_cv<U>::type>::value &&
231 !std::is_void<U>::value,
232 decltype(
static_cast<T *
>(std::declval<U *>()))>::type>
237 static_cast<std::uint64_t
>(calculate_offset<U>());
256 typename pmem::detail::sp_dereference<T>::type
operator*() const
265 typename pmem::detail::sp_member_access<T>::type
operator->() const
276 template <typename = typename std::enable_if<!std::is_void<T>::value>>
277 typename pmem::detail::sp_array_access<T>::type
281 (i < pmem::detail::sp_extent<T>::value ||
282 pmem::detail::sp_extent<T>::value == 0) &&
283 "persistent array index out of bounds");
285 return this->
get()[i];
294 detail::conditional_add_to_tx(
this);
295 this->oid.off +=
sizeof(T);
306 PMEMoid noid = this->oid;
318 detail::conditional_add_to_tx(
this);
319 this->oid.off -=
sizeof(T);
330 PMEMoid noid = this->oid;
342 detail::conditional_add_to_tx(
this);
343 this->oid.off +=
static_cast<std::uint64_t
>(s) *
sizeof(T);
354 detail::conditional_add_to_tx(
this);
355 this->oid.off -=
static_cast<std::uint64_t
>(s) *
sizeof(T);
371 template <
typename Y,
372 typename =
typename std::enable_if<
373 std::is_convertible<Y *, T *>::value>::type>
385 explicit operator bool() const noexcept
387 return get() !=
nullptr;
414 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
418 "Cannot get pool from persistent pointer");
420 pmemobj_persist(pop, this->
get(),
sizeof(T));
443 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
447 "Cannot get pool from persistent pointer");
449 pmemobj_flush(pop, this->
get(),
sizeof(T));
480 if (this->oid.pool_uuid_lo ==
481 std::numeric_limits<decltype(oid.pool_uuid_lo)>::max())
485 pmemobj_direct(this->oid));
540 static_assert(!std::is_polymorphic<element_type>::value,
541 "Polymorphic types are not supported");
553 if (OID_IS_NULL(oid)) {
554 oid.pool_uuid_lo = std::numeric_limits<decltype(
555 oid.pool_uuid_lo)>::max();
556 oid.off =
reinterpret_cast<decltype(oid.off)
>(vptr);
575 template <
typename U>
579 static const ptrdiff_t ptr_offset_magic = 0xDEADBEEF;
581 U *tmp{
reinterpret_cast<U *
>(ptr_offset_magic)};
582 T *diff =
static_cast<T *
>(tmp);
583 return reinterpret_cast<ptrdiff_t
>(diff) -
584 reinterpret_cast<ptrdiff_t
>(tmp);
606 template <
typename T,
typename Y>
610 return OID_EQUALS(lhs.raw(), rhs.raw());
616 template <
typename T,
typename Y>
620 return !(lhs == rhs);
626 template <
typename T>
630 return lhs.get() ==
nullptr;
636 template <
typename T>
640 return lhs.get() ==
nullptr;
646 template <
typename T>
650 return lhs.get() !=
nullptr;
656 template <
typename T>
660 return lhs.get() !=
nullptr;
670 template <
typename T,
typename Y>
674 if (lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo)
675 return lhs.raw().off < rhs.raw().off;
677 return lhs.raw().pool_uuid_lo < rhs.raw().pool_uuid_lo;
685 template <
typename T,
typename Y>
697 template <
typename T,
typename Y>
709 template <
typename T,
typename Y>
721 template <
typename T>
725 return std::less<typename persistent_ptr<T>::element_type *>()(
732 template <
typename T>
736 return std::less<typename persistent_ptr<T>::element_type *>()(
743 template <
typename T>
747 return !(
nullptr < lhs);
753 template <
typename T>
757 return !(rhs <
nullptr);
763 template <
typename T>
767 return nullptr < lhs;
773 template <
typename T>
777 return rhs <
nullptr;
783 template <
typename T>
787 return !(lhs <
nullptr);
793 template <
typename T>
797 return !(
nullptr < rhs);
803 template <
typename T>
804 inline persistent_ptr<T>
808 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
809 noid.off = lhs.raw().off +
static_cast<std::uint64_t
>(s) *
sizeof(T);
817 template <
typename T>
818 inline persistent_ptr<T>
822 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
823 noid.off = lhs.raw().off -
static_cast<std::uint64_t
>(s) *
sizeof(T);
835 template <
typename T,
typename Y,
836 typename =
typename std::enable_if<
837 std::is_same<typename std::remove_cv<T>::type,
838 typename std::remove_cv<Y>::type>::value>>
842 assert(lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo);
843 auto d =
static_cast<std::ptrdiff_t
>(lhs.raw().off - rhs.raw().off);
845 return d /
static_cast<std::ptrdiff_t
>(
sizeof(T));
851 template <
typename T>
855 PMEMoid raw_oid = pptr.raw();
856 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:516
persistent_ptr< T > operator+(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Addition operator for persistent pointers.
Definition: persistent_ptr.hpp:805
element_type * get() const noexcept
Get the direct pointer.
Definition: persistent_ptr.hpp:478
T & reference
The reference type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:526
ptrdiff_t calculate_offset() const
Calculate in-object offset for structures with inheritance.
Definition: persistent_ptr.hpp:577
persistent_ptr(persistent_ptr< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:212
Custom pool error class.
Definition: pexceptions.hpp:45
void flush(void)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:441
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:521
std::random_access_iterator_tag iterator_category
Random access iterator requirements (members)
Definition: persistent_ptr.hpp:511
Commonly used functionality.
persistent_ptr< T > & operator--()
Prefix decrement operator.
Definition: persistent_ptr.hpp:316
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:730
persistent_ptr< T > operator++(int)
Postfix increment operator.
Definition: persistent_ptr.hpp:304
void persist(void)
Persists what the persistent pointer points to.
Definition: persistent_ptr.hpp:412
static persistent_ptr< T > pointer_to(T &ref)
Create a persistent pointer from a given reference.
Definition: persistent_ptr.hpp:465
persistent_ptr< T > operator--(int)
Postfix decrement operator.
Definition: persistent_ptr.hpp:328
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:740
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:420
pmem::detail::sp_member_access< T >::type operator->() const noexcept
Member access operator.
Definition: persistent_ptr.hpp:265
persistent_ptr(persistent_ptr< U > const &r) noexcept
Copy constructor from a different persistent_ptr<>.
Definition: persistent_ptr.hpp:233
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:853
persistent_ptr(persistent_ptr< void > const &rhs) noexcept
Explicit void specialization of the converting constructor.
Definition: persistent_ptr.hpp:175
persistent_ptr< T > & operator-=(std::ptrdiff_t s)
Subtraction assignment operator.
Definition: persistent_ptr.hpp:352
pmem::detail::sp_dereference< T >::type operator*() const noexcept
Dereference operator.
Definition: persistent_ptr.hpp:256
persistent_ptr< T > & operator++()
Prefix increment operator.
Definition: persistent_ptr.hpp:292
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:819
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:880
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:536
void persist(pool_base &pop)
Persists the content of the underlying object.
Definition: persistent_ptr.hpp:400
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:163
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:502
Persistent pointer class.
Definition: persistent_ptr.hpp:152
void flush(pool_base &pop)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:429
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:719
persistent_ptr< T > & operator+=(std::ptrdiff_t s)
Addition assignment operator.
Definition: persistent_ptr.hpp:340
void verify_type()
Verify if element_type is not polymorphic.
Definition: persistent_ptr.hpp:538
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:750
persistent_ptr(element_type *vptr, int)
Private constructor enabling persistent_ptrs to volatile objects.
Definition: persistent_ptr.hpp:551
persistent_ptr(persistent_ptr< const void > const &rhs) noexcept
Explicit const void specialization of the converting constructor.
Definition: persistent_ptr.hpp:183
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
persistent_ptr(element_type *ptr)
Volatile pointer constructor.
Definition: persistent_ptr.hpp:196
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:375
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:278