|
constexpr | self_relative_ptr () noexcept=default |
| Default constructor, equal the nullptr.
|
|
constexpr | self_relative_ptr (std::nullptr_t) noexcept |
| Nullptr constructor.
|
|
| self_relative_ptr (element_type *ptr) noexcept |
| Volatile pointer constructor. More...
|
|
| self_relative_ptr (persistent_ptr< T > ptr) noexcept |
| Constructor from persistent_ptr<T>
|
|
| self_relative_ptr (PMEMoid oid) noexcept |
| PMEMoid constructor. More...
|
|
| self_relative_ptr (const self_relative_ptr &ptr) noexcept |
| Copy constructor.
|
|
template<typename U , 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> |
| self_relative_ptr (self_relative_ptr< U > const &r) noexcept |
| Copy constructor from a different self_relative_ptr<>. More...
|
|
element_type * | get () const noexcept |
| Get the direct pointer. More...
|
|
persistent_ptr< T > | to_persistent_ptr () const |
| Conversion to persitent ptr.
|
|
| operator bool () const noexcept |
| Bool conversion operator.
|
|
| operator persistent_ptr< T > () const |
| Conversion operator to persistent_ptr.
|
|
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[] (difference_type i) const noexcept |
| Array access operator. More...
|
|
self_relative_ptr & | operator= (const self_relative_ptr &r) |
| Assignment operator. More...
|
|
template<typename Y , typename = typename std::enable_if< std::is_convertible<Y *, T *>::value>::type> |
self_relative_ptr< T > & | operator= (self_relative_ptr< Y > const &r) |
| Converting assignment operator from a different self_relative_ptr<>. More...
|
|
self_relative_ptr & | operator= (std::nullptr_t) |
| Nullptr move assignment operator. More...
|
|
self_relative_ptr< T > & | operator++ () |
| Prefix increment operator.
|
|
self_relative_ptr< T > | operator++ (int) |
| Postfix increment operator.
|
|
self_relative_ptr< T > & | operator-- () |
| Prefix decrement operator.
|
|
self_relative_ptr< T > | operator-- (int) |
| Postfix decrement operator.
|
|
self_relative_ptr< T > & | operator+= (std::ptrdiff_t s) |
| Addition assignment operator.
|
|
self_relative_ptr< T > & | operator-= (std::ptrdiff_t s) |
| Subtraction assignment operator.
|
|
constexpr | self_relative_ptr_base_impl () noexcept |
| Default constructor, equal the nullptr.
|
|
constexpr | self_relative_ptr_base_impl (std::nullptr_t) noexcept |
| Nullptr constructor.
|
|
| self_relative_ptr_base_impl (void *ptr) noexcept |
| Volatile pointer constructor. More...
|
|
| self_relative_ptr_base_impl (self_relative_ptr_base_impl const &r) noexcept |
| Copy constructor. More...
|
|
self_relative_ptr_base_impl & | operator= (self_relative_ptr_base_impl const &r) |
| Assignment operator. More...
|
|
self_relative_ptr_base_impl & | operator= (std::nullptr_t &&) |
| Nullptr move assignment operator. More...
|
|
void | swap (self_relative_ptr_base_impl &other) |
| Swaps two self_relative_ptr_base objects of the same type. More...
|
|
byte_ptr_type | to_byte_pointer () const noexcept |
| Conversion to byte pointer.
|
|
void * | to_void_pointer () const noexcept |
| Conversion to void*.
|
|
| operator void * () const noexcept |
| Explicit conversion operator to void*.
|
|
| operator byte_ptr_type () const noexcept |
| Explicit conversion operator to byte pointer.
|
|
bool | is_null () const noexcept |
| Fast null checking without conversion to void*.
|
|
template<typename T>
class pmem::obj::experimental::self_relative_ptr< T >
Persistent self-relative pointer class.
self_relative_ptr implements a smart ptr. It encapsulates the self offsetted pointer and provides member access, dereference and array access operators.
Template parameter type has following requirements:
Even if all of the above requirements are met, type representation may vary depending on ABI and compiler optimizations (as stated in [class.mem]: "the
order of allocation of non-static data members with different access control
is unspecified"). To enforce the same layout for all ABIs and optimization levels type should satisfy StandardLayoutType requirement.If pointer is used with array type, additional requirement is:
- Element type must be default constructible
The pointer 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 pointer will also yield undefined behavior.C++ standard states that lifetime of an object is a runtime property [basic.lifetime]. Conditions which must be fulfilled for object's lifetime to begin, imply that using any non-trivially constructible object with pointer is undefined behaviour. This is being partially addressed by the following proposal:
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/bk8esqk-QooAnother caveat is that snapshotting elements in a transaction and performing rollback uses memcpy internally. Using memcpy on an object in C++ is allowed by the standard only if the type satisfies TriviallyCopyable requirement.
Casting to self_relative_ptr_base can be easily done from any self_relative_ptr<T> objects, but when casting between convertible objects be advised to use constructors or operator= specified for such conversion, see:
The current version uses an approach where we store offset=real_offset-1 and zero offset (or real_offset equal one) is a null pointer. This is needed to support zero initialization.
- real_offset = pointer - this;
- pointer = real_offset + this;
- or pointer = offset + this + 1;