9 #ifndef LIBPMEMOBJ_CPP_SELF_RELATIVE_PTR_BASE_IMPL_HPP
10 #define LIBPMEMOBJ_CPP_SELF_RELATIVE_PTR_BASE_IMPL_HPP
13 #include <type_traits>
38 template <
typename OffsetType>
42 using difference_type = std::ptrdiff_t;
43 using offset_type = OffsetType;
44 using byte_type = uint8_t;
45 using byte_ptr_type = byte_type *;
46 using const_byte_ptr_type =
const byte_type *;
56 : offset(nullptr_offset)
64 : offset(nullptr_offset)
104 detail::conditional_add_to_tx(
this);
118 detail::conditional_add_to_tx(
this);
133 detail::conditional_add_to_tx(
this);
134 detail::conditional_add_to_tx(&other);
162 explicit operator void *()
const noexcept
170 explicit operator byte_ptr_type() const noexcept
178 static difference_type
191 return offset == nullptr_offset;
223 uintptr_t mask = other_offset == nullptr_offset;
225 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(
226 reinterpret_cast<const_byte_ptr_type
>(
this) +
229 return reinterpret_cast<void *
>(ptr);
248 uintptr_t mask = ptr.is_null();
250 difference_type distance_between_self =
251 reinterpret_cast<const_byte_ptr_type
>(&ptr) -
252 reinterpret_cast<const_byte_ptr_type
>(
this);
253 distance_between_self &=
254 reinterpret_cast<difference_type &
>(mask);
255 return ptr.offset + distance_between_self;
275 uintptr_t mask = ptr ==
nullptr;
277 difference_type new_offset =
static_cast<byte_ptr_type
>(ptr) -
278 reinterpret_cast<const_byte_ptr_type
>(
this) - 1;
279 new_offset &=
reinterpret_cast<difference_type &
>(mask);
287 static constexpr difference_type nullptr_offset = 0;
289 template <
typename T>
296 template <
typename T>
300 using difference_type =
typename access_type::difference_type;
302 template <
typename Po
interType>
303 static difference_type
304 pointer_to_offset(
const access_type &obj, PointerType *ptr)
309 template <
typename Po
interType>
311 offset_to_pointer(difference_type offset,
const access_type &obj)
314 return static_cast<PointerType *
>(ptr);
Static class accesssor to self_relative_ptr_base.
Definition: self_relative_ptr_base_impl.hpp:297
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
self_relative_ptr_base_impl(self_relative_ptr_base_impl const &r) noexcept
Copy constructor.
Definition: self_relative_ptr_base_impl.hpp:83
constexpr self_relative_ptr_base_impl(std::nullptr_t) noexcept
Nullptr constructor.
Definition: self_relative_ptr_base_impl.hpp:63
void * to_void_pointer() const noexcept
Conversion to void*.
Definition: self_relative_ptr_base_impl.hpp:154
difference_type pointer_to_offset(void *ptr) const noexcept
Conversion pointer to offset.
Definition: self_relative_ptr_base_impl.hpp:262
void * offset_to_pointer(difference_type other_offset) const noexcept
Conversion to void* use other offset.
Definition: self_relative_ptr_base_impl.hpp:209
byte_ptr_type to_byte_pointer() const noexcept
Conversion to byte pointer.
Definition: self_relative_ptr_base_impl.hpp:145
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
constexpr self_relative_ptr_base_impl() noexcept
Default constructor, equal the nullptr.
Definition: self_relative_ptr_base_impl.hpp:55
self_relative_ptr_base_impl(void *ptr) noexcept
Volatile pointer constructor.
Definition: self_relative_ptr_base_impl.hpp:73
self_relative_ptr_base_impl & operator=(self_relative_ptr_base_impl const &r)
Assignment operator.
Definition: self_relative_ptr_base_impl.hpp:100
self_relative_ptr_base_impl(difference_type offset) noexcept
Offset constructor.
Definition: self_relative_ptr_base_impl.hpp:200
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:236
self_relative_ptr_base_impl & operator=(std::nullptr_t &&)
Nullptr move assignment operator.
Definition: self_relative_ptr_base_impl.hpp:116
Commonly used functionality.
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Helper template for persistent ptr specialization.