PMDK C++ bindings
1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Persistent pointer class. More...
#include <libpmemobj++/persistent_ptr.hpp>
Public Types | |
typedef persistent_ptr< T > | this_type |
typedef pmem::detail::sp_element< T >::type | element_type |
Type of the actual object with all qualifiers removed, used for easy underlying type access. | |
template<class U > | |
using | rebind = pmem::obj::persistent_ptr< U > |
Rebind to a different type of pointer. | |
using | persistency_type = p< T > |
The persistency type to be used with this pointer. | |
using | bool_type = bool |
The used bool_type. | |
using | iterator_category = std::random_access_iterator_tag |
Random access iterator requirements (members) More... | |
using | difference_type = std::ptrdiff_t |
The persistent_ptr difference type. | |
using | value_type = T |
The type of the value pointed to by the persistent_ptr. | |
using | reference = T & |
The reference type of the value pointed to by the persistent_ptr. | |
using | pointer = persistent_ptr< T > |
The pointer type. | |
Public Member Functions | |
persistent_ptr (persistent_ptr< void > const &rhs) noexcept | |
Explicit void specialization of the converting constructor. | |
persistent_ptr (persistent_ptr< const void > const &rhs) noexcept | |
Explicit const void specialization of the converting constructor. | |
persistent_ptr (element_type *ptr) | |
Volatile pointer constructor. More... | |
template<typename U , typename = typename std::enable_if< !std::is_same<T, U>::value && std::is_same<typename std::remove_cv<T>::type, U>::value>::type> | |
persistent_ptr (persistent_ptr< U > const &r) noexcept | |
Copy constructor from a different persistent_ptr<>. More... | |
template<typename U , typename Dummy = void, typename = typename std::enable_if< !std::is_same< typename std::remove_cv<T>::type, typename std::remove_cv<U>::type>::value && !std::is_void<U>::value, decltype(static_cast<T *>(std::declval<U *>()))>::type> | |
persistent_ptr (persistent_ptr< U > const &r) noexcept | |
Copy constructor from a different persistent_ptr<>. More... | |
operator persistent_ptr< void > () const noexcept | |
Persistent pointer to void conversion operator. | |
pmem::detail::sp_dereference< T >::type | operator* () const noexcept |
Dereference operator. | |
pmem::detail::sp_member_access< T >::type | operator-> () const noexcept |
Member access operator. | |
template<typename = typename std::enable_if<!std::is_void<T>::value>> | |
pmem::detail::sp_array_access< T >::type | operator[] (std::ptrdiff_t i) const noexcept |
Array access operator. More... | |
persistent_ptr< T > & | operator++ () |
Prefix increment operator. | |
persistent_ptr< T > | operator++ (int) |
Postfix increment operator. | |
persistent_ptr< T > & | operator-- () |
Prefix decrement operator. | |
persistent_ptr< T > | operator-- (int) |
Postfix decrement operator. | |
persistent_ptr< T > & | operator+= (std::ptrdiff_t s) |
Addition assignment operator. | |
persistent_ptr< T > & | operator-= (std::ptrdiff_t s) |
Subtraction assignment operator. | |
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type> | |
persistent_ptr< T > & | operator= (persistent_ptr< Y > const &r) |
Converting assignment operator from a different persistent_ptr<>. More... | |
operator bool () const noexcept | |
Bool conversion operator. | |
void | persist (pool_base &pop) |
Persists the content of the underlying object. More... | |
void | persist (void) |
Persists what the persistent pointer points to. More... | |
void | flush (pool_base &pop) |
Flushes what the persistent pointer points to. More... | |
void | flush (void) |
Flushes what the persistent pointer points to. More... | |
element_type * | get () const noexcept |
Get the direct pointer. More... | |
persistent_ptr_base () noexcept | |
Default constructor, zeroes the PMEMoid. | |
persistent_ptr_base (PMEMoid oid) noexcept | |
PMEMoid constructor. More... | |
persistent_ptr_base (persistent_ptr_base const &r) noexcept | |
persistent_ptr_base (persistent_ptr_base &&r) noexcept | |
Move constructor. | |
void | swap (persistent_ptr_base &other) |
Swaps two persistent_ptr objects of the same type. More... | |
const PMEMoid & | raw () const noexcept |
Get PMEMoid encapsulated by this object. More... | |
PMEMoid * | raw_ptr () noexcept |
Get pointer to PMEMoid encapsulated by this object. More... | |
Static Public Member Functions | |
static persistent_ptr< T > | pointer_to (T &ref) |
Create a persistent pointer from a given reference. More... | |
Protected Member Functions | |
void | verify_type () |
Verify if element_type is not polymorphic. | |
persistent_ptr (element_type *vptr, int) | |
Private constructor enabling persistent_ptrs to volatile objects. More... | |
template<typename U > | |
ptrdiff_t | calculate_offset () const |
Calculate in-object offset for structures with inheritance. More... | |
Protected Attributes | |
PMEMoid | oid |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
void | swap (persistent_ptr< T > &a, persistent_ptr< T > &b) |
Swaps two persistent_ptr objects of the same type. More... | |
template<typename T , typename Y > | |
bool | operator== (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) noexcept |
Equality operator. More... | |
template<typename T , typename Y > | |
bool | operator!= (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) noexcept |
Inequality operator. | |
template<typename T > | |
bool | operator== (persistent_ptr< T > const &lhs, std::nullptr_t) noexcept |
Equality operator with nullptr. | |
template<typename T > | |
bool | operator== (std::nullptr_t, persistent_ptr< T > const &lhs) noexcept |
Equality operator with nullptr. | |
template<typename T > | |
bool | operator!= (persistent_ptr< T > const &lhs, std::nullptr_t) noexcept |
Inequality operator with nullptr. | |
template<typename T > | |
bool | operator!= (std::nullptr_t, persistent_ptr< T > const &lhs) noexcept |
Inequality operator with nullptr. | |
template<typename T , typename Y > | |
bool | operator< (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) noexcept |
Less than operator. More... | |
template<typename T , typename Y > | |
bool | operator<= (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) noexcept |
Less or equal than operator. More... | |
template<typename T , typename Y > | |
bool | operator> (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) noexcept |
Greater than operator. More... | |
template<typename T , typename Y > | |
bool | operator>= (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) noexcept |
Greater or equal than operator. More... | |
template<typename T > | |
bool | operator< (persistent_ptr< T > const &lhs, std::nullptr_t) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator< (std::nullptr_t, persistent_ptr< T > const &rhs) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator<= (persistent_ptr< T > const &lhs, std::nullptr_t) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator<= (std::nullptr_t, persistent_ptr< T > const &rhs) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator> (persistent_ptr< T > const &lhs, std::nullptr_t) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator> (std::nullptr_t, persistent_ptr< T > const &rhs) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator>= (persistent_ptr< T > const &lhs, std::nullptr_t) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
bool | operator>= (std::nullptr_t, persistent_ptr< T > const &rhs) noexcept |
Compare a persistent_ptr with a null pointer. | |
template<typename T > | |
persistent_ptr< T > | operator+ (persistent_ptr< T > const &lhs, std::ptrdiff_t s) |
Addition operator for persistent pointers. | |
template<typename T > | |
persistent_ptr< T > | operator- (persistent_ptr< T > const &lhs, std::ptrdiff_t s) |
Subtraction operator for persistent pointers. | |
template<typename T , typename Y , typename = typename std::enable_if< std::is_same<typename std::remove_cv<T>::type, typename std::remove_cv<Y>::type>::value>> | |
ptrdiff_t | operator- (persistent_ptr< T > const &lhs, persistent_ptr< Y > const &rhs) |
Subtraction operator for persistent pointers of identical type. More... | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &os, persistent_ptr< T > const &pptr) |
Ostream operator for the persistent pointer. | |
Persistent pointer class.
persistent_ptr implements a smart ptr. It encapsulates the PMEMoid fat pointer and provides member access, dereference and array access operators.
Template parameter type has following requirements:
This type does NOT manage the life-cycle of the object. The typical usage example would be:
Casting to persistent_ptr_base can be easily done from any persistent_ptr<T> objects, but when casting between convertible objects be advised to use constructors or operator= specified for such conversion, see:
Below you can find an example how to and how NOT to cast persistent_ptr's:
using pmem::obj::persistent_ptr< T >::iterator_category = std::random_access_iterator_tag |
Random access iterator requirements (members)
The persistent_ptr iterator category.
|
inline |
Volatile pointer constructor.
If ptr does not point to an address from a valid pool, the persistent pointer will evaluate to nullptr.
ptr | volatile pointer, pointing to persistent memory. |
|
inlinenoexcept |
Copy constructor from a different persistent_ptr<>.
Available only for convertible types.
|
inlinenoexcept |
Copy constructor from a different persistent_ptr<>.
Available only for convertible, non-void types.
|
inlineprotected |
Private constructor enabling persistent_ptrs to volatile objects.
This is internal implementation needed only for the pointer_traits<persistent_ptr>::pointer_to to be able to create valid pointers. This is used in libstdc++'s std::vector::insert().
|
inlineprotected |
Calculate in-object offset for structures with inheritance.
In case of the given inheritance:
A B \ / C
A pointer to B *ptr = &C should be offset by sizeof(A). This function calculates that offset.
|
inline |
Flushes what the persistent pointer points to.
[in] | pop | Pmemobj pool |
|
inline |
Flushes what the persistent pointer points to.
pool_error | when cannot get pool from persistent pointer |
|
inlinenoexcept |
Get the direct pointer.
Performs a calculations on the underlying C-style pointer.
|
inline |
Converting assignment operator from a different persistent_ptr<>.
Available only for convertible types. Just like regular assignment, also automatically registers itself in a transaction.
pmem::transaction_error | when adding the object to the transaction failed. |
|
inlinenoexcept |
Array access operator.
Contains run-time bounds checking for static arrays.
|
inline |
Persists the content of the underlying object.
[in] | pop | Pmemobj pool |
|
inline |
Persists what the persistent pointer points to.
pool_error | when cannot get pool from persistent pointer |
|
inlinenoexcept |
PMEMoid constructor.
Provided for easy interoperability between C++ and C API's.
oid | C-style persistent pointer |
|
inlinestatic |
Create a persistent pointer from a given reference.
This can create a persistent_ptr to a volatile object, use with extreme caution.
ref | reference to an object. |
|
inlinenoexceptinherited |
Get PMEMoid encapsulated by this object.
For C API compatibility.
|
inlinenoexceptinherited |
Get pointer to PMEMoid encapsulated by this object.
For C API compatibility.
|
inlineinherited |
Swaps two persistent_ptr objects of the same type.
[in,out] | other | the other persistent_ptr to swap. |
|
related |
Subtraction operator for persistent pointers of identical type.
Calculates the offset difference of PMEMoids in terms of represented objects. Calculating the difference of pointers from objects of different pools is not allowed.
|
related |
Less than operator.
|
related |
Less or equal than operator.
See less than operator for comparison rules.
|
related |
Equality operator.
This checks if underlying PMEMoids are equal.
|
related |
Greater than operator.
See less than operator for comparison rules.
|
related |
Greater or equal than operator.
See less than operator for comparison rules.
|
related |
Swaps two persistent_ptr objects of the same type.
Non-member swap function as required by Swappable concept. en.cppreference.com/w/cpp/concept/Swappable