9 #ifndef LIBPMEMOBJ_CPP_SELF_RELATIVE_PTR_HPP
10 #define LIBPMEMOBJ_CPP_SELF_RELATIVE_PTR_HPP
15 #include <type_traits>
21 namespace experimental
25 class self_relative_ptr;
32 using element_type = void;
49 return static_cast<element_type *
>(
55 self_offset(element_type *ptr)
const noexcept
86 using element_type =
typename pmem::detail::sp_element<T>::type;
100 using difference_type =
typename base_type::difference_type;
156 static_cast<element_type *
>(pmemobj_direct(oid))))
175 typename =
typename std::enable_if<
177 typename std::remove_cv<T>::type,
178 typename std::remove_cv<U>::type>::value &&
179 !std::is_void<U>::value,
180 decltype(
static_cast<T *
>(std::declval<U *>()))>::type>
196 inline element_type *
199 return static_cast<element_type *
>(
219 explicit operator bool() const noexcept
235 typename pmem::detail::sp_dereference<T>::type
operator*() const
238 return *(this->
get());
244 typename pmem::detail::sp_member_access<T>::type
operator->() const
255 template <typename = typename std::enable_if<!std::is_void<T>::value>>
256 typename pmem::detail::sp_array_access<T>::type
260 (i < pmem::detail::sp_extent<T>::value ||
261 pmem::detail::sp_extent<T>::value == 0) &&
262 "persistent array index out of bounds");
264 return this->
get()[i];
295 template <
typename Y,
296 typename =
typename std::enable_if<
297 std::is_convertible<Y *, T *>::value>::type>
314 this->offset = self_offset(
nullptr);
325 this->offset +=
static_cast<difference_type
>(
sizeof(T));
349 this->offset -=
static_cast<difference_type
>(
sizeof(T));
373 this->offset += s *
static_cast<difference_type
>(
sizeof(T));
384 this->offset -= s *
static_cast<difference_type
>(
sizeof(T));
395 static_assert(!std::is_polymorphic<element_type>::value,
396 "Polymorphic types are not supported");
401 self_offset(element_type *ptr)
const noexcept
426 template <
typename T,
typename Y>
431 return lhs.to_byte_pointer() == rhs.to_byte_pointer();
438 template <
typename T,
typename Y>
443 return !(lhs == rhs);
450 template <
typename T>
461 template <
typename T>
472 template <
typename T>
483 template <
typename T>
497 template <
typename T,
typename Y>
502 return lhs.to_byte_pointer() < rhs.to_byte_pointer();
511 template <
typename T,
typename Y>
525 template <
typename T,
typename Y>
539 template <
typename T,
typename Y>
553 template <
typename T>
557 return std::less<typename self_relative_ptr<T>::element_type *>()(
565 template <
typename T>
569 return std::less<typename self_relative_ptr<T>::element_type *>()(
577 template <
typename T>
581 return !(
nullptr < lhs);
588 template <
typename T>
592 return !(rhs <
nullptr);
599 template <
typename T>
603 return nullptr < lhs;
610 template <
typename T>
614 return rhs <
nullptr;
621 template <
typename T>
625 return !(lhs <
nullptr);
632 template <
typename T>
636 return !(
nullptr < rhs);
643 template <
typename T>
656 template <
typename T>
673 template <
typename T,
typename Y,
674 typename =
typename std::enable_if<
675 std::is_same<typename std::remove_cv<T>::type,
676 typename std::remove_cv<Y>::type>::value>>
681 static_cast<ptrdiff_t
>(
sizeof(T));
688 template <
typename T>
692 os << ptr.to_void_pointer();
self_relative_ptr base template class
Definition: self_relative_ptr_base_impl.hpp:39
static difference_type distance_between(const self_relative_ptr_base_impl &first, const self_relative_ptr_base_impl &second)
Byte distance between two relative pointers.
Definition: self_relative_ptr_base_impl.hpp:179
void * to_void_pointer() const noexcept
Conversion to void*.
Definition: self_relative_ptr_base_impl.hpp:154
bool is_null() const noexcept
Fast null checking without conversion to void*.
Definition: self_relative_ptr_base_impl.hpp:189
void swap(self_relative_ptr_base_impl &other)
Swaps two self_relative_ptr_base objects of the same type.
Definition: self_relative_ptr_base_impl.hpp:129
self_relative_ptr_base_impl & operator=(self_relative_ptr_base_impl const &r)
Assignment operator.
Definition: self_relative_ptr_base_impl.hpp:100
difference_type pointer_to_offset(const self_relative_ptr_base_impl &ptr) const noexcept
Conversion self_relative_ptr_base to offset from itself.
Definition: self_relative_ptr_base_impl.hpp:235
Persistent self-relative pointer class.
Definition: self_relative_ptr.hpp:82
bool operator==(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Equality operator.
Definition: self_relative_ptr.hpp:428
self_relative_ptr< T > operator++(int)
Postfix increment operator.
Definition: self_relative_ptr.hpp:334
bool operator>(self_relative_ptr< T > const &lhs, std::nullptr_t) noexcept
Compare a self_relative_ptr with a null pointer.
Definition: self_relative_ptr.hpp:601
self_relative_ptr< T > operator-(self_relative_ptr< T > const &lhs, std::ptrdiff_t s)
Subtraction operator for self-relative pointers.
Definition: self_relative_ptr.hpp:658
self_relative_ptr< T > & operator+=(std::ptrdiff_t s)
Addition assignment operator.
Definition: self_relative_ptr.hpp:370
pmem::detail::sp_dereference< T >::type operator*() const noexcept
Dereference operator.
Definition: self_relative_ptr.hpp:235
self_relative_ptr(element_type *ptr) noexcept
Volatile pointer constructor.
Definition: self_relative_ptr.hpp:134
T & reference
The reference type of the value pointed to by the self_relative_ptr.
Definition: self_relative_ptr.hpp:110
self_relative_ptr & operator=(const self_relative_ptr &r)
Assignment operator.
Definition: self_relative_ptr.hpp:278
bool operator>(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Greater than operator.
Definition: self_relative_ptr.hpp:527
bool operator>=(std::nullptr_t, self_relative_ptr< T > const &rhs) noexcept
Compare a self_relative_ptr with a null pointer.
Definition: self_relative_ptr.hpp:634
T value_type
The type of the value pointed to by the self_relative_ptr.
Definition: self_relative_ptr.hpp:105
self_relative_ptr(persistent_ptr< T > ptr) noexcept
Constructor from persistent_ptr<T>
Definition: self_relative_ptr.hpp:142
self_relative_ptr(PMEMoid oid) noexcept
PMEMoid constructor.
Definition: self_relative_ptr.hpp:154
bool operator!=(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Inequality operator.
Definition: self_relative_ptr.hpp:440
self_relative_ptr< T > & operator--()
Prefix decrement operator.
Definition: self_relative_ptr.hpp:346
self_relative_ptr< T > & operator++()
Prefix increment operator.
Definition: self_relative_ptr.hpp:322
void verify_type()
Verify if element_type is not polymorphic.
Definition: self_relative_ptr.hpp:393
self_relative_ptr< T > & operator=(self_relative_ptr< Y > const &r)
Converting assignment operator from a different self_relative_ptr<>.
Definition: self_relative_ptr.hpp:299
self_relative_ptr< T > & operator-=(std::ptrdiff_t s)
Subtraction assignment operator.
Definition: self_relative_ptr.hpp:381
bool operator>(std::nullptr_t, self_relative_ptr< T > const &rhs) noexcept
Compare a self_relative_ptr with a null pointer.
Definition: self_relative_ptr.hpp:612
self_relative_ptr< T > operator--(int)
Postfix decrement operator.
Definition: self_relative_ptr.hpp:358
persistent_ptr< T > to_persistent_ptr() const
Conversion to persitent ptr.
Definition: self_relative_ptr.hpp:207
bool operator==(self_relative_ptr< T > const &lhs, std::nullptr_t) noexcept
Equality operator with nullptr.
Definition: self_relative_ptr.hpp:452
pmem::detail::sp_array_access< T >::type operator[](difference_type i) const noexcept
Array access operator.
Definition: self_relative_ptr.hpp:257
element_type * get() const noexcept
Get the direct pointer.
Definition: self_relative_ptr.hpp:197
bool operator!=(std::nullptr_t, self_relative_ptr< T > const &lhs) noexcept
Inequality operator with nullptr.
Definition: self_relative_ptr.hpp:485
bool operator>=(self_relative_ptr< T > const &lhs, std::nullptr_t) noexcept
Compare a self_relative_ptr with a null pointer.
Definition: self_relative_ptr.hpp:623
bool operator!=(self_relative_ptr< T > const &lhs, std::nullptr_t) noexcept
Inequality operator with nullptr.
Definition: self_relative_ptr.hpp:474
ptrdiff_t operator-(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs)
Subtraction operator for self-relative pointers of identical type.
Definition: self_relative_ptr.hpp:678
bool operator>=(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Greater or equal than operator.
Definition: self_relative_ptr.hpp:541
self_relative_ptr(const self_relative_ptr &ptr) noexcept
Copy constructor.
Definition: self_relative_ptr.hpp:163
void swap(self_relative_ptr< T > &a, self_relative_ptr< T > &b)
Swaps two self_relative_ptr objects of the same type.
Definition: self_relative_ptr.hpp:417
typename base_type::difference_type difference_type
The self_relative_ptr difference type.
Definition: self_relative_ptr.hpp:100
pmem::detail::sp_member_access< T >::type operator->() const noexcept
Member access operator.
Definition: self_relative_ptr.hpp:244
self_relative_ptr(self_relative_ptr< U > const &r) noexcept
Copy constructor from a different self_relative_ptr<>.
Definition: self_relative_ptr.hpp:181
constexpr self_relative_ptr() noexcept=default
Default constructor, equal the nullptr.
self_relative_ptr & operator=(std::nullptr_t)
Nullptr move assignment operator.
Definition: self_relative_ptr.hpp:311
self_relative_ptr< T > operator+(self_relative_ptr< T > const &lhs, std::ptrdiff_t s)
Addition operator for self-relative pointers.
Definition: self_relative_ptr.hpp:645
bool operator==(std::nullptr_t, self_relative_ptr< T > const &lhs) noexcept
Equality operator with nullptr.
Definition: self_relative_ptr.hpp:463
std::random_access_iterator_tag iterator_category
Random access iterator requirements (members)
Definition: self_relative_ptr.hpp:95
Persistent pointer class.
Definition: persistent_ptr.hpp:153
void conditional_add_to_tx(const T *that, std::size_t count=1, uint64_t flags=0)
Conditionally add 'count' objects to a transaction.
Definition: common.hpp:176
std::ostream & operator<<(std::ostream &os, const radix_tree< K, V, BV, MtMode > &tree)
Prints tree in DOT format.
Definition: radix_tree.hpp:2843
pmem::detail::self_relative_ptr_base_impl< std::ptrdiff_t > self_relative_ptr_base
self_relative_ptr base (non-template) class
Definition: self_relative_ptr_base.hpp:36
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent smart pointer.
Base class for self_relative_ptr.
Helper template for persistent ptr specialization.