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
85 using element_type =
typename pmem::detail::sp_element<T>::type;
99 using difference_type =
typename base_type::difference_type;
155 static_cast<element_type *
>(pmemobj_direct(oid))))
174 typename =
typename std::enable_if<
176 typename std::remove_cv<T>::type,
177 typename std::remove_cv<U>::type>::value &&
178 !std::is_void<U>::value,
179 decltype(
static_cast<T *
>(std::declval<U *>()))>::type>
195 inline element_type *
198 return static_cast<element_type *
>(
218 explicit operator bool() const noexcept
234 typename pmem::detail::sp_dereference<T>::type
operator*() const
237 return *(this->
get());
243 typename pmem::detail::sp_member_access<T>::type
operator->() const
254 template <typename = typename std::enable_if<!std::is_void<T>::value>>
255 typename pmem::detail::sp_array_access<T>::type
259 (i < pmem::detail::sp_extent<T>::value ||
260 pmem::detail::sp_extent<T>::value == 0) &&
261 "persistent array index out of bounds");
263 return this->
get()[i];
294 template <
typename Y,
295 typename =
typename std::enable_if<
296 std::is_convertible<Y *, T *>::value>::type>
312 detail::conditional_add_to_tx(
this);
313 this->offset = self_offset(
nullptr);
323 detail::conditional_add_to_tx(
this);
324 this->offset +=
static_cast<difference_type
>(
sizeof(T));
347 detail::conditional_add_to_tx(
this);
348 this->offset -=
static_cast<difference_type
>(
sizeof(T));
371 detail::conditional_add_to_tx(
this);
372 this->offset += s *
static_cast<difference_type
>(
sizeof(T));
382 detail::conditional_add_to_tx(
this);
383 this->offset -= s *
static_cast<difference_type
>(
sizeof(T));
394 static_assert(!std::is_polymorphic<element_type>::value,
395 "Polymorphic types are not supported");
400 self_offset(element_type *ptr)
const noexcept
422 template <
typename T,
typename Y>
427 return lhs.to_byte_pointer() == rhs.to_byte_pointer();
433 template <
typename T,
typename Y>
438 return !(lhs == rhs);
444 template <
typename T>
454 template <
typename T>
464 template <
typename T>
474 template <
typename T>
487 template <
typename T,
typename Y>
492 return lhs.to_byte_pointer() < rhs.to_byte_pointer();
500 template <
typename T,
typename Y>
513 template <
typename T,
typename Y>
526 template <
typename T,
typename Y>
539 template <
typename T>
543 return std::less<typename self_relative_ptr<T>::element_type *>()(
550 template <
typename T>
554 return std::less<typename self_relative_ptr<T>::element_type *>()(
561 template <
typename T>
565 return !(
nullptr < lhs);
571 template <
typename T>
575 return !(rhs <
nullptr);
581 template <
typename T>
585 return nullptr < lhs;
591 template <
typename T>
595 return rhs <
nullptr;
601 template <
typename T>
605 return !(lhs <
nullptr);
611 template <
typename T>
615 return !(
nullptr < rhs);
621 template <
typename T>
622 inline self_relative_ptr<T>
633 template <
typename T>
634 inline self_relative_ptr<T>
649 template <
typename T,
typename Y,
650 typename =
typename std::enable_if<
651 std::is_same<typename std::remove_cv<T>::type,
652 typename std::remove_cv<Y>::type>::value>>
657 static_cast<ptrdiff_t
>(
sizeof(T));
663 template <
typename T>
667 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:81
self_relative_ptr< T > operator++(int)
Postfix increment operator.
Definition: self_relative_ptr.hpp:333
self_relative_ptr< T > & operator+=(std::ptrdiff_t s)
Addition assignment operator.
Definition: self_relative_ptr.hpp:369
pmem::detail::sp_dereference< T >::type operator*() const noexcept
Dereference operator.
Definition: self_relative_ptr.hpp:234
self_relative_ptr(element_type *ptr) noexcept
Volatile pointer constructor.
Definition: self_relative_ptr.hpp:133
T & reference
The reference type of the value pointed to by the self_relative_ptr.
Definition: self_relative_ptr.hpp:109
self_relative_ptr & operator=(const self_relative_ptr &r)
Assignment operator.
Definition: self_relative_ptr.hpp:277
T value_type
The type of the value pointed to by the self_relative_ptr.
Definition: self_relative_ptr.hpp:104
self_relative_ptr(persistent_ptr< T > ptr) noexcept
Constructor from persistent_ptr<T>
Definition: self_relative_ptr.hpp:141
self_relative_ptr(PMEMoid oid) noexcept
PMEMoid constructor.
Definition: self_relative_ptr.hpp:153
self_relative_ptr< T > & operator--()
Prefix decrement operator.
Definition: self_relative_ptr.hpp:345
self_relative_ptr< T > & operator++()
Prefix increment operator.
Definition: self_relative_ptr.hpp:321
void verify_type()
Verify if element_type is not polymorphic.
Definition: self_relative_ptr.hpp:392
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:298
self_relative_ptr< T > & operator-=(std::ptrdiff_t s)
Subtraction assignment operator.
Definition: self_relative_ptr.hpp:380
self_relative_ptr< T > operator--(int)
Postfix decrement operator.
Definition: self_relative_ptr.hpp:357
persistent_ptr< T > to_persistent_ptr() const
Conversion to persitent ptr.
Definition: self_relative_ptr.hpp:206
pmem::detail::sp_array_access< T >::type operator[](difference_type i) const noexcept
Array access operator.
Definition: self_relative_ptr.hpp:256
element_type * get() const noexcept
Get the direct pointer.
Definition: self_relative_ptr.hpp:196
self_relative_ptr(const self_relative_ptr &ptr) noexcept
Copy constructor.
Definition: self_relative_ptr.hpp:162
typename base_type::difference_type difference_type
The self_relative_ptr difference type.
Definition: self_relative_ptr.hpp:99
pmem::detail::sp_member_access< T >::type operator->() const noexcept
Member access operator.
Definition: self_relative_ptr.hpp:243
self_relative_ptr(self_relative_ptr< U > const &r) noexcept
Copy constructor from a different self_relative_ptr<>.
Definition: self_relative_ptr.hpp:180
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:310
std::random_access_iterator_tag iterator_category
Random access iterator requirements (members)
Definition: self_relative_ptr.hpp:94
Persistent pointer class.
Definition: persistent_ptr.hpp:152
bool operator==(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Equality operator.
Definition: self_relative_ptr.hpp:424
std::ostream & operator<<(std::ostream &os, const radix_tree< K, V, BV, MtMode > &tree)
Prints tree in DOT format.
Definition: radix_tree.hpp:2840
bool operator<=(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Less or equal than operator.
Definition: self_relative_ptr.hpp:502
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:623
void swap(concurrent_map< Key, Value, Comp, Allocator > &lhs, concurrent_map< Key, Value, Comp, Allocator > &rhs)
Non-member swap.
Definition: concurrent_map.hpp:151
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:635
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:528
bool operator!=(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Inequality operator.
Definition: self_relative_ptr.hpp:435
bool operator>(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Greater than operator.
Definition: self_relative_ptr.hpp:515
bool operator<(self_relative_ptr< T > const &lhs, self_relative_ptr< Y > const &rhs) noexcept
Less than operator.
Definition: self_relative_ptr.hpp:489
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.