9 #ifndef PMEMOBJ_PERSISTENT_POOL_PTR_HPP
10 #define PMEMOBJ_PERSISTENT_POOL_PTR_HPP
14 #include <type_traits>
25 class persistent_pool_ptr {
27 friend class persistent_pool_ptr;
29 typedef persistent_pool_ptr<T> this_type;
36 typedef typename pmem::detail::sp_element<T>::type element_type;
38 persistent_pool_ptr() : off(0)
46 persistent_pool_ptr(std::nullptr_t) noexcept : off(0)
58 persistent_pool_ptr(PMEMoid oid) noexcept : off(oid.off)
70 persistent_pool_ptr(uint64_t _off) noexcept : off(_off)
82 typename =
typename std::enable_if<
83 std::is_convertible<Y *, T *>::value>::type>
84 persistent_pool_ptr(
const persistent_pool_ptr<Y> &r) noexcept
97 typename =
typename std::enable_if<
98 std::is_convertible<Y *, T *>::value>::type>
110 persistent_pool_ptr(
const persistent_pool_ptr &r) noexcept : off(r.off)
129 persistent_pool_ptr(persistent_pool_ptr &&r) noexcept
130 : off(std::move(r.off))
138 persistent_pool_ptr &
139 operator=(persistent_pool_ptr &&r)
142 this->off = std::move(r.off);
147 persistent_pool_ptr &operator=(std::nullptr_t)
165 persistent_pool_ptr &
166 operator=(
const persistent_pool_ptr &r)
184 persistent_pool_ptr &
188 this->off = r.
raw().off;
203 persistent_pool_ptr &
204 operator=(
const PMEMoid &oid)
222 template <
typename Y,
223 typename =
typename std::enable_if<
224 std::is_convertible<Y *, T *>::value>::type>
225 persistent_pool_ptr &
226 operator=(
const persistent_pool_ptr<Y> &r)
245 template <
typename Y,
246 typename =
typename std::enable_if<
247 std::is_convertible<Y *, T *>::value>::type>
248 persistent_pool_ptr &
252 this->off = r.
raw().off;
265 get(uint64_t pool_uuid)
const noexcept
267 PMEMoid oid = {pool_uuid, this->off};
268 return static_cast<element_type *
>(pmemobj_direct(oid));
272 operator()(uint64_t pool_uuid)
const noexcept
274 return get(pool_uuid);
285 get_persistent_ptr(uint64_t pool_uuid)
const noexcept
287 PMEMoid oid = {pool_uuid, this->off};
295 swap(persistent_pool_ptr &other)
299 std::swap(this->off, other.off);
305 explicit operator bool() const noexcept
307 return this->off != 0;
318 raw_oid(uint64_t pool_uuid)
const noexcept
320 PMEMoid oid = {pool_uuid, this->off};
340 inline persistent_pool_ptr<T> &
344 this->off +=
sizeof(T);
352 inline persistent_pool_ptr<T>
355 persistent_pool_ptr<T> ret(*
this);
364 inline persistent_pool_ptr<T> &
368 this->off -=
sizeof(T);
376 inline persistent_pool_ptr<T>
379 persistent_pool_ptr<T> ret(*
this);
388 inline persistent_pool_ptr<T> &
389 operator+=(std::ptrdiff_t s)
392 this->off += s *
sizeof(T);
400 inline persistent_pool_ptr<T> &
401 operator-=(std::ptrdiff_t s)
404 this->off -= s *
sizeof(T);
409 inline persistent_pool_ptr<T>
410 operator+(std::ptrdiff_t s)
412 persistent_pool_ptr<T> ret(*
this);
413 ret.off += s *
sizeof(T);
418 inline persistent_pool_ptr<T>
419 operator-(std::ptrdiff_t s)
421 persistent_pool_ptr<T> ret(*
this);
422 ret.off -= s *
sizeof(T);
434 static_assert(!std::is_polymorphic<element_type>::value,
435 "Polymorphic types are not supported");
445 template <
typename T,
typename Y>
447 operator==(
const persistent_pool_ptr<T> &lhs,
448 const persistent_pool_ptr<Y> &rhs) noexcept
450 return lhs.raw() == rhs.raw();
457 template <
typename T,
typename Y>
459 operator!=(
const persistent_pool_ptr<T> &lhs,
460 const persistent_pool_ptr<Y> &rhs) noexcept
462 return !(lhs == rhs);
469 template <
typename T>
471 operator!=(
const persistent_pool_ptr<T> &lhs, std::nullptr_t) noexcept
473 return lhs.raw() != 0;
480 template <
typename T>
482 operator!=(std::nullptr_t,
const persistent_pool_ptr<T> &lhs) noexcept
484 return lhs.raw() != 0;
491 template <
typename T>
493 operator==(
const persistent_pool_ptr<T> &lhs, std::nullptr_t) noexcept
495 return lhs.raw() == 0;
502 template <
typename T>
504 operator==(std::nullptr_t,
const persistent_pool_ptr<T> &lhs) noexcept
506 return lhs.raw() == 0;
509 template <
class T,
class U>
510 persistent_pool_ptr<T>
511 static_persistent_pool_pointer_cast(
const persistent_pool_ptr<U> &r)
513 static_assert(std::is_convertible<T *, U *>::value,
514 "Cannot cast persistent_pool_ptr");
515 return persistent_pool_ptr<T>(r.raw());
const PMEMoid & raw() const noexcept
Get PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:151
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
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent smart pointer.
Helper template for persistent ptr specialization.