PMDK C++ bindings
1.8.1
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>
68 class persistent_ptr<void> :
public detail::persistent_ptr_base<void> {
70 persistent_ptr() =
default;
71 using detail::persistent_ptr_base<void>::persistent_ptr_base;
72 using detail::persistent_ptr_base<void>::operator=;
79 class persistent_ptr<const void>
80 :
public detail::persistent_ptr_base<const void> {
82 persistent_ptr() =
default;
83 using detail::persistent_ptr_base<const void>::persistent_ptr_base;
84 using detail::persistent_ptr_base<const void>::operator=;
131 template <
typename T>
164 typename pmem::detail::sp_dereference<T>::type
operator*() const
173 typename pmem::detail::sp_member_access<T>::type
operator->() const
184 template <typename = typename std::enable_if<!std::is_void<T>::value>>
185 typename pmem::detail::sp_array_access<T>::type
189 (i < pmem::detail::sp_extent<T>::value ||
190 pmem::detail::sp_extent<T>::value == 0) &&
191 "persistent array index out of bounds");
193 return this->
get()[i];
202 detail::conditional_add_to_tx(
this);
203 this->oid.off +=
sizeof(T);
214 PMEMoid noid = this->oid;
226 detail::conditional_add_to_tx(
this);
227 this->oid.off -=
sizeof(T);
238 PMEMoid noid = this->oid;
250 detail::conditional_add_to_tx(
this);
251 this->oid.off +=
static_cast<std::uint64_t
>(s) *
sizeof(T);
262 detail::conditional_add_to_tx(
this);
263 this->oid.off -=
static_cast<std::uint64_t
>(s) *
sizeof(T);
288 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
292 "Cannot get pool from persistent pointer");
294 pmemobj_persist(pop, this->
get(),
sizeof(T));
317 pmemobjpool *pop = pmemobj_pool_by_oid(this->raw());
321 "Cannot get pool from persistent pointer");
323 pmemobj_flush(pop, this->
get(),
sizeof(T));
408 template <
typename T,
typename Y>
412 return OID_EQUALS(lhs.raw(), rhs.raw());
418 template <
typename T,
typename Y>
422 return !(lhs == rhs);
428 template <
typename T>
432 return lhs.get() ==
nullptr;
438 template <
typename T>
442 return lhs.get() ==
nullptr;
448 template <
typename T>
452 return lhs.get() !=
nullptr;
458 template <
typename T>
462 return lhs.get() !=
nullptr;
472 template <
typename T,
typename Y>
476 if (lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo)
477 return lhs.raw().off < rhs.raw().off;
479 return lhs.raw().pool_uuid_lo < rhs.raw().pool_uuid_lo;
487 template <
typename T,
typename Y>
499 template <
typename T,
typename Y>
511 template <
typename T,
typename Y>
523 template <
typename T>
527 return std::less<typename persistent_ptr<T>::element_type *>()(
534 template <
typename T>
538 return std::less<typename persistent_ptr<T>::element_type *>()(
545 template <
typename T>
549 return !(
nullptr < lhs);
555 template <
typename T>
559 return !(rhs <
nullptr);
565 template <
typename T>
569 return nullptr < lhs;
575 template <
typename T>
579 return rhs <
nullptr;
585 template <
typename T>
589 return !(lhs <
nullptr);
595 template <
typename T>
599 return !(
nullptr < rhs);
605 template <
typename T>
606 inline persistent_ptr<T>
610 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
611 noid.off = lhs.raw().off +
static_cast<std::uint64_t
>(s) *
sizeof(T);
619 template <
typename T>
620 inline persistent_ptr<T>
624 noid.pool_uuid_lo = lhs.raw().pool_uuid_lo;
625 noid.off = lhs.raw().off -
static_cast<std::uint64_t
>(s) *
sizeof(T);
637 template <
typename T,
typename Y,
638 typename =
typename std::enable_if<
639 std::is_same<typename std::remove_cv<T>::type,
640 typename std::remove_cv<Y>::type>::value>>
644 assert(lhs.raw().pool_uuid_lo == rhs.raw().pool_uuid_lo);
645 auto d =
static_cast<std::ptrdiff_t
>(lhs.raw().off - rhs.raw().off);
647 return d /
static_cast<std::ptrdiff_t
>(
sizeof(T));
653 template <
typename T>
657 PMEMoid raw_oid = pptr.raw();
658 os << std::hex <<
"0x" << raw_oid.pool_uuid_lo <<
", 0x" << raw_oid.off
Persistent_ptr base class.
Definition: persistent_ptr_base.hpp:68
std::ptrdiff_t difference_type
The persistent_ptr difference type.
Definition: persistent_ptr.hpp:372
T & reference
The reference type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:382
T & get(pmem::obj::array< T, N > &a)
Non-member get function.
Definition: array.hpp:923
Custom pool error class.
Definition: pexceptions.hpp:72
void flush(void)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:315
void persist(const void *addr, size_t len) noexcept
Performs persist operation on a given chunk of memory.
Definition: pool.hpp:288
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:752
A persistent version of concurrent hash map implementation Ref: https://arxiv.org/abs/1509....
Definition: allocation_flag.hpp:44
T value_type
The type of the value pointed to by the persistent_ptr.
Definition: persistent_ptr.hpp:377
std::random_access_iterator_tag iterator_category
The persistent_ptr iterator category.
Definition: persistent_ptr.hpp:367
Commonly used functionality.
persistent_ptr< T > & operator--()
Prefix decrement operator.
Definition: persistent_ptr.hpp:224
persistent_ptr< T > operator++(int)
Postfix increment operator.
Definition: persistent_ptr.hpp:212
void swap(pmem::obj::array< T, N > &lhs, pmem::obj::array< T, N > &rhs)
Non-member swap function.
Definition: array.hpp:913
void persist(void)
Persists what the persistent pointer points to.
Definition: persistent_ptr.hpp:286
static persistent_ptr< T > pointer_to(T &ref)
Create a persistent pointer from a given reference.
Definition: persistent_ptr.hpp:339
persistent_ptr< T > operator--(int)
Postfix decrement operator.
Definition: persistent_ptr.hpp:236
pmem::detail::sp_member_access< T >::type operator->() const noexcept
Member access operator.
Definition: persistent_ptr.hpp:173
Resides on pmem class.
Definition: p.hpp:64
persistent_ptr(persistent_ptr< void > const &rhs) noexcept
Explicit void specialization of the converting constructor.
Definition: persistent_ptr.hpp:140
persistent_ptr< T > & operator-=(std::ptrdiff_t s)
Subtraction assignment operator.
Definition: persistent_ptr.hpp:260
pmem::detail::sp_dereference< T >::type operator*() const noexcept
Dereference operator.
Definition: persistent_ptr.hpp:164
persistent_ptr< T > & operator++()
Prefix increment operator.
Definition: persistent_ptr.hpp:200
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
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:783
void persist(pool_base &pop)
Persists the content of the underlying object.
Definition: persistent_ptr.hpp:274
Helper template for persistent ptr specialization.
void flush(const void *addr, size_t len) noexcept
Performs flush operation on a given chunk of memory.
Definition: pool.hpp:325
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:763
bool bool_type
The used bool_type.
Definition: persistent_ptr.hpp:358
Persistent pointer class.
Definition: persistent_ptr.hpp:132
void flush(pool_base &pop)
Flushes what the persistent pointer points to.
Definition: persistent_ptr.hpp:303
persistent_ptr< T > & operator+=(std::ptrdiff_t s)
Addition assignment operator.
Definition: persistent_ptr.hpp:248
std::ostream & operator<<(std::ostream &os, persistent_ptr< T > const &pptr)
Ostream operator for the persistent pointer.
Definition: persistent_ptr.hpp:655
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
persistent_ptr(persistent_ptr< const void > const &rhs) noexcept
Explicit const void specialization of the converting constructor.
Definition: persistent_ptr.hpp:148
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:773
Base class for persistent_ptr.
persistent_ptr< T > operator+(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Addition operator for persistent pointers.
Definition: persistent_ptr.hpp:607
The non-template pool base class.
Definition: pool.hpp:67
persistent_ptr< T > operator-(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Subtraction operator for persistent pointers.
Definition: persistent_ptr.hpp:621
pmem::detail::sp_array_access< T >::type operator[](std::ptrdiff_t i) const noexcept
Array access operator.
Definition: persistent_ptr.hpp:186