PMDK C++ bindings  1.7.1
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Types | Public Member Functions | Protected Member Functions | List of all members
pmem::detail::persistent_ptr_base< T > Class Template Reference

Persistent_ptr base class. More...

#include <libpmemobj++/detail/persistent_ptr_base.hpp>

Inheritance diagram for pmem::detail::persistent_ptr_base< T >:
pmem::obj::persistent_ptr< node > pmem::obj::persistent_ptr< T[]> pmem::obj::persistent_ptr< value_type []> pmem::obj::persistent_ptr< T >

Public Types

typedef pmem::detail::sp_element< T >::type element_type
 Type of an actual object with all qualifier removed, used for easy underlying type access.
 

Public Member Functions

 persistent_ptr_base ()
 Default constructor, zeroes the PMEMoid.
 
 persistent_ptr_base (PMEMoid oid) noexcept
 PMEMoid constructor. More...
 
 persistent_ptr_base (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_base (persistent_ptr_base< 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_base (persistent_ptr_base< U > const &r) noexcept
 Copy constructor from a different persistent_ptr<>. More...
 
template<typename Y , typename = typename std::enable_if< !std::is_same< typename std::remove_cv<T>::type, typename std::remove_cv<Y>::type>::value && !std::is_void<Y>::value, decltype(static_cast<T *>(std::declval<Y *>()))>::type>
 operator persistent_ptr_base< Y > () noexcept
 Conversion operator to a different persistent_ptr<>. More...
 
 persistent_ptr_base (persistent_ptr_base &&r) noexcept
 Defaulted move constructor.
 
persistent_ptr_baseoperator= (persistent_ptr_base &&r)
 Defaulted move assignment operator.
 
persistent_ptr_baseoperator= (persistent_ptr_base const &r)
 Assignment operator. More...
 
persistent_ptr_baseoperator= (std::nullptr_t &&)
 Nullptr move assignment operator. More...
 
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type>
persistent_ptr_baseoperator= (persistent_ptr_base< Y > const &r)
 Converting assignment operator from a different persistent_ptr<>. More...
 
void swap (persistent_ptr_base &other)
 Swaps two persistent_ptr objects of the same type. More...
 
element_typeget () const noexcept
 Get a direct pointer. 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...
 

Protected Member Functions

 persistent_ptr_base (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...
 

Detailed Description

template<typename T>
class pmem::detail::persistent_ptr_base< T >

Persistent_ptr base class.

Implements some of the functionality of the persistent_ptr class. It defines all applicable conversions from and to a persistent_ptr_base. This class is an implementation detail and is not to be instantiated. It cannot be declared as virtual due to the problem with rebuilding the vtable.

Constructor & Destructor Documentation

◆ persistent_ptr_base() [1/5]

template<typename T>
pmem::detail::persistent_ptr_base< T >::persistent_ptr_base ( PMEMoid  oid)
inlinenoexcept

PMEMoid constructor.

Provided for easy interoperability between C++ and C API's.

Parameters
oidC-style persistent pointer

◆ persistent_ptr_base() [2/5]

template<typename T>
pmem::detail::persistent_ptr_base< T >::persistent_ptr_base ( element_type ptr)
inline

Volatile pointer constructor.

If ptr does not point to an address from a valid pool, the persistent pointer will evaluate to nullptr.

Parameters
ptrvolatile pointer, pointing to persistent memory.

◆ persistent_ptr_base() [3/5]

template<typename T>
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>
pmem::detail::persistent_ptr_base< T >::persistent_ptr_base ( persistent_ptr_base< U > const &  r)
inlinenoexcept

Copy constructor from a different persistent_ptr<>.

Available only for convertible types.

◆ persistent_ptr_base() [4/5]

template<typename T>
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>
pmem::detail::persistent_ptr_base< T >::persistent_ptr_base ( persistent_ptr_base< U > const &  r)
inlinenoexcept

Copy constructor from a different persistent_ptr<>.

Available only for convertible, non-void types.

◆ persistent_ptr_base() [5/5]

template<typename T>
pmem::detail::persistent_ptr_base< T >::persistent_ptr_base ( element_type vptr,
int   
)
inlineprotected

Private constructor enabling persistent_ptrs to volatile objects.

This is internal implementation only needed for the pointer_traits<persistent_ptr>::pointer_to to be able to create valid pointers. This is used in libstdc++'s std::vector::insert().

Member Function Documentation

◆ calculate_offset()

template<typename T>
template<typename U >
ptrdiff_t pmem::detail::persistent_ptr_base< T >::calculate_offset ( ) const
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.

Returns
offset between to compatible pointer types to the same object

◆ get()

template<typename T>
element_type* pmem::detail::persistent_ptr_base< T >::get ( ) const
inlinenoexcept

Get a direct pointer.

Performs a calculations on the underlying C-style pointer.

Returns
a direct pointer to the object.

◆ operator persistent_ptr_base< Y >()

template<typename T>
template<typename Y , typename = typename std::enable_if< !std::is_same< typename std::remove_cv<T>::type, typename std::remove_cv<Y>::type>::value && !std::is_void<Y>::value, decltype(static_cast<T *>(std::declval<Y *>()))>::type>
pmem::detail::persistent_ptr_base< T >::operator persistent_ptr_base< Y > ( )
inlinenoexcept

Conversion operator to a different persistent_ptr<>.

Available only for convertible, non-void types.

◆ operator=() [1/3]

template<typename T>
persistent_ptr_base& pmem::detail::persistent_ptr_base< T >::operator= ( persistent_ptr_base< T > const &  r)
inline

Assignment operator.

Persistent pointer assignment within a transaction automatically registers this operation so that a rollback is possible.

Exceptions
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ operator=() [2/3]

template<typename T>
persistent_ptr_base& pmem::detail::persistent_ptr_base< T >::operator= ( std::nullptr_t &&  )
inline

Nullptr move assignment operator.

Exceptions
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ operator=() [3/3]

template<typename T>
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type>
persistent_ptr_base& pmem::detail::persistent_ptr_base< T >::operator= ( persistent_ptr_base< Y > const &  r)
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.

Exceptions
pmem::transaction_errorwhen adding the object to the transaction failed.

◆ raw()

template<typename T>
const PMEMoid& pmem::detail::persistent_ptr_base< T >::raw ( ) const
inlinenoexcept

Get PMEMoid encapsulated by this object.

For C API compatibility.

Returns
const reference to the PMEMoid

◆ raw_ptr()

template<typename T>
PMEMoid* pmem::detail::persistent_ptr_base< T >::raw_ptr ( )
inlinenoexcept

Get pointer to PMEMoid encapsulated by this object.

For C API compatibility.

Returns
pointer to the PMEMoid

◆ swap()

template<typename T>
void pmem::detail::persistent_ptr_base< T >::swap ( persistent_ptr_base< T > &  other)
inline

Swaps two persistent_ptr objects of the same type.

Parameters
[in,out]otherthe other persistent_ptr to swap.

The documentation for this class was generated from the following file: