PMDK C++ bindings  1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Member Functions | List of all members
pmem::obj::experimental::v< T > Class Template Reference

Volatile residing on pmem class. More...

#include <libpmemobj++/experimental/v.hpp>

Public Member Functions

 v () noexcept
 Defaulted constructor.
 
 ~v ()
 Destructor.
 
voperator= (const T &rhs)
 Assignment operator.
 
voperator= (v &rhs)
 Assignment operator.
 
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y, T>::value>::type>
voperator= (v< Y > &rhs)
 Converting assignment operator from a different v<>. More...
 
template<typename... Args>
T & get (Args &&... args) noexcept
 Retrieves reference to the object. More...
 
T & unsafe_get ()
 Retrieves reference to the object. More...
 
 operator T& () noexcept
 Conversion operator back to the underlying type.
 
void swap (v &other)
 Swaps two v objects of the same type.
 

Detailed Description

template<typename T>
class pmem::obj::experimental::v< T >

Volatile residing on pmem class.

v class is a property-like template class that has to be used for all volatile variables that reside on persistent memory. This class ensures that the enclosed type is always properly initialized by always calling the class default constructor exactly once per instance of the application.

This class has 8 bytes of storage overhead.

Example usage:

#include <fcntl.h>
using namespace pmem::obj;
using namespace pmem::obj::experimental;
struct foo {
foo() : counter(10){};
int counter;
};
/* pool root structure */
struct root {
v<foo> f;
};
void
v_property_example(pool<root> &pop)
{
auto proot = pop.root();
assert(proot->f.get().counter == 10);
proot->f.get().counter++;
assert(proot->f.get().counter == 11);
}

Member Function Documentation

◆ get()

template<typename T >
template<typename... Args>
T& pmem::obj::experimental::v< T >::get ( Args &&...  args)
inlinenoexcept

Retrieves reference to the object.

Parameters
[in]argsforwarded to objects constructor. If object was constructed earlier during application lifetime (even with different arguments) no constructor is called.
Returns
a reference to the object.

◆ operator=()

template<typename T >
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y, T>::value>::type>
v& pmem::obj::experimental::v< T >::operator= ( v< Y > &  rhs)
inline

Converting assignment operator from a different v<>.

Available only for convertible types.

◆ unsafe_get()

template<typename T >
T& pmem::obj::experimental::v< T >::unsafe_get ( )
inline

Retrieves reference to the object.

If object was not constructed (e.g. using get()) return value is unspecified.

Returns
a reference to the object.

The documentation for this class was generated from the following file:
pmem::obj::pool::root
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:624
pool.hpp
C++ pmemobj pool.
pmem::obj
Main libpmemobj namespace.
Definition: allocation_flag.hpp:18
pmem::obj::pool
PMEMobj pool class.
Definition: pool.hpp:462
pmem::obj::experimental
Experimental implementations.
Definition: common.hpp:107
persistent_ptr.hpp
Persistent smart pointer.
v.hpp
Volatile residing on pmem property template.