PMDK C++ bindings  1.8.2
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

pmem::obj::experimental::v - volatile resides 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 >

pmem::obj::experimental::v - volatile resides 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.

#include <fcntl.h>
using namespace pmem::obj;
using namespace pmem::obj::experimental;
void
v_property_example()
{
struct foo {
foo() : counter(10)
{
}
int counter;
};
// pool root structure
struct root {
v<foo> f;
};
// create a pmemobj pool
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
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: