NVML C++ bindings  0.1 experimental
This is the C++ bindings documentation for NVML's libpmemobj.
Public Types | Public Member Functions | List of all members
nvml::obj::persistent_ptr< T > Class Template Reference

Persistent pointer class. More...

#include <libpmemobj++/persistent_ptr.hpp>

Public Types

typedef nvml::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 ()
 Default constructor, zeroes the PMEMoid.
 
 persistent_ptr (std::nullptr_t) noexcept
 Default null constructor, zeroes the PMEMoid.
 
 persistent_ptr (PMEMoid oid) noexcept
 PMEMoid constructor. More...
 
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type>
 persistent_ptr (const persistent_ptr< Y > &r) noexcept
 Copy constructor from a different persistent_ptr<>. More...
 
 persistent_ptr (persistent_ptr &&r) noexcept
 Defaulted move constructor.
 
persistent_ptroperator= (persistent_ptr &&r)
 Defaulted move assignment operator.
 
persistent_ptroperator= (const persistent_ptr &r)
 Assignment operator. More...
 
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type>
persistent_ptroperator= (const persistent_ptr< Y > &r)
 Converting assignment operator from a different persistent_ptr<>. More...
 
nvml::detail::sp_dereference< T >::type operator* () const noexcept
 Dereference operator.
 
nvml::detail::sp_member_access< T >::type operator-> () const noexcept
 Member access operator.
 
nvml::detail::sp_array_access< T >::type operator[] (std::ptrdiff_t i) const noexcept
 Array access operator. More...
 
element_typeget () const noexcept
 Get a direct pointer. More...
 
void swap (persistent_ptr &other) noexcept
 Swaps two persistent_ptr objects of the same type.
 
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...
 
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.
 
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...
 

Detailed Description

template<typename T>
class nvml::obj::persistent_ptr< T >

Persistent pointer class.

persistent_ptr implements a smart ptr. It encapsulates the PMEMoid fat pointer and provides member access, dereference and array access operators. The persistent_ptr is not designed to work with polymorphic types, as they have runtime RTTI info embedded, which is implementation specific and thus not consistently rebuildable. Such constructs as polymorphic members or members of a union defined within a class held in a persistent_ptr will also yield undefined behavior. This type does NOT manage the life-cycle of the object. The typical usage example would be:

#include <fcntl.h>
using namespace nvml::obj;
void
persistent_ptr_example()
{
struct compound_type {
void
set_some_variable(int val)
{
some_variable = val;
}
int some_variable;
double some_other_variable;
};
// pool root structure
struct root {
} proot;
// create a pmemobj pool
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
// typical usage schemes
proot.comp = make_persistent<compound_type>(); // allocation
proot.comp->set_some_variable(12); // call function
proot.comp->some_other_variable = 2.3; // set variable
});
// reading from the persistent_ptr
compound_type tmp = *proot.comp;
(void)tmp;
// Changing a persistent_ptr<> variable outside of a transaction is a
// volatile modification. No way to ensure persistence in case of power
// failure.
proot.comp->some_variable = 12;
}

Constructor & Destructor Documentation

template<typename T>
nvml::obj::persistent_ptr< T >::persistent_ptr ( PMEMoid  oid)
inlinenoexcept

PMEMoid constructor.

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

Parameters
oidC-style persistent pointer
template<typename T>
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type>
nvml::obj::persistent_ptr< T >::persistent_ptr ( const persistent_ptr< Y > &  r)
inlinenoexcept

Copy constructor from a different persistent_ptr<>.

Available only for convertible types.

Member Function Documentation

template<typename T>
void nvml::obj::persistent_ptr< T >::flush ( pool_base pop)
inline

Flushes what the persistent pointer points to.

Parameters
[in]popPmemobj pool
template<typename T>
void nvml::obj::persistent_ptr< T >::flush ( void  )
inline

Flushes what the persistent pointer points to.

Exceptions
pool_errorwhen cannot get pool from persistent pointer
template<typename T>
element_type* nvml::obj::persistent_ptr< T >::get ( ) const
inlinenoexcept

Get a direct pointer.

Performs a calculations on the underlying C-style pointer.

Returns
a direct pointer to the object.
template<typename T>
persistent_ptr& nvml::obj::persistent_ptr< T >::operator= ( const persistent_ptr< T > &  r)
inline

Assignment operator.

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

Exceptions
nvml::transaction_errorwhen adding the object to the transaction failed.
template<typename T>
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type>
persistent_ptr& nvml::obj::persistent_ptr< T >::operator= ( const persistent_ptr< Y > &  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
nvml::transaction_errorwhen adding the object to the transaction failed.
template<typename T>
nvml::detail::sp_array_access<T>::type nvml::obj::persistent_ptr< T >::operator[] ( std::ptrdiff_t  i) const
inlinenoexcept

Array access operator.

Contains run-time bounds checking for static arrays.

template<typename T>
void nvml::obj::persistent_ptr< T >::persist ( pool_base pop)
inline

Persists the content of the underlying object.

Parameters
[in]popPmemobj pool
template<typename T>
void nvml::obj::persistent_ptr< T >::persist ( void  )
inline

Persists what the persistent pointer points to.

Exceptions
pool_errorwhen cannot get pool from persistent pointer
template<typename T>
const PMEMoid& nvml::obj::persistent_ptr< T >::raw ( ) const
inlinenoexcept

Get PMEMoid encapsulated by this object.

For C API compatibility.

Returns
const reference to the PMEMoid
template<typename T>
PMEMoid* nvml::obj::persistent_ptr< T >::raw_ptr ( )
inlinenoexcept

Get pointer to PMEMoid encapsulated by this object.

For C API compatibility.

Returns
pointer to the PMEMoid

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