4 #ifndef PMEMOBJ_PERSISTENT_POOL_PTR_HPP
5 #define PMEMOBJ_PERSISTENT_POOL_PTR_HPP
20 class persistent_pool_ptr {
22 friend class persistent_pool_ptr;
24 typedef persistent_pool_ptr<T> this_type;
31 typedef typename pmem::detail::sp_element<T>::type element_type;
33 persistent_pool_ptr() : off(0)
41 persistent_pool_ptr(std::nullptr_t) noexcept : off(0)
53 persistent_pool_ptr(PMEMoid oid) noexcept : off(oid.off)
65 persistent_pool_ptr(uint64_t _off) noexcept : off(_off)
77 typename =
typename std::enable_if<
78 std::is_convertible<Y *, T *>::value>::type>
79 persistent_pool_ptr(
const persistent_pool_ptr<Y> &r) noexcept
92 typename =
typename std::enable_if<
93 std::is_convertible<Y *, T *>::value>::type>
105 persistent_pool_ptr(
const persistent_pool_ptr &r) noexcept : off(r.off)
124 persistent_pool_ptr(persistent_pool_ptr &&r) noexcept
125 : off(std::move(r.off))
133 persistent_pool_ptr &
134 operator=(persistent_pool_ptr &&r)
136 conditional_add_to_tx(
this);
137 this->off = std::move(r.off);
142 persistent_pool_ptr &operator=(std::nullptr_t)
144 conditional_add_to_tx(
this);
160 persistent_pool_ptr &
161 operator=(
const persistent_pool_ptr &r)
163 conditional_add_to_tx(
this);
179 persistent_pool_ptr &
182 conditional_add_to_tx(
this);
183 this->off = r.raw().off;
198 persistent_pool_ptr &
199 operator=(
const PMEMoid &oid)
201 conditional_add_to_tx(
this);
217 template <
typename Y,
218 typename =
typename std::enable_if<
219 std::is_convertible<Y *, T *>::value>::type>
220 persistent_pool_ptr &
221 operator=(
const persistent_pool_ptr<Y> &r)
223 conditional_add_to_tx(
this);
240 template <
typename Y,
241 typename =
typename std::enable_if<
242 std::is_convertible<Y *, T *>::value>::type>
243 persistent_pool_ptr &
246 conditional_add_to_tx(
this);
247 this->off = r.raw().off;
260 get(uint64_t pool_uuid)
const noexcept
262 PMEMoid oid = {pool_uuid, this->off};
263 return static_cast<element_type *
>(pmemobj_direct(oid));
267 operator()(uint64_t pool_uuid)
const noexcept
269 return get(pool_uuid);
280 get_persistent_ptr(uint64_t pool_uuid)
const noexcept
282 PMEMoid oid = {pool_uuid, this->off};
290 swap(persistent_pool_ptr &other)
292 conditional_add_to_tx(
this);
293 conditional_add_to_tx(&other);
300 explicit operator bool() const noexcept
302 return this->off != 0;
313 raw_oid(uint64_t pool_uuid)
const noexcept
315 PMEMoid oid = {pool_uuid, this->off};
328 conditional_add_to_tx(
this);
335 inline persistent_pool_ptr<T> &
338 conditional_add_to_tx(
this);
339 this->off +=
sizeof(T);
347 inline persistent_pool_ptr<T>
350 persistent_pool_ptr<T> ret(*
this);
359 inline persistent_pool_ptr<T> &
362 conditional_add_to_tx(
this);
363 this->off -=
sizeof(T);
371 inline persistent_pool_ptr<T>
374 persistent_pool_ptr<T> ret(*
this);
383 inline persistent_pool_ptr<T> &
386 conditional_add_to_tx(
this);
387 this->off += s *
sizeof(T);
395 inline persistent_pool_ptr<T> &
398 conditional_add_to_tx(
this);
399 this->off -= s *
sizeof(T);
404 inline persistent_pool_ptr<T>
407 persistent_pool_ptr<T> ret(*
this);
408 ret.off += s *
sizeof(T);
413 inline persistent_pool_ptr<T>
416 persistent_pool_ptr<T> ret(*
this);
417 ret.off -= s *
sizeof(T);
429 static_assert(!std::is_polymorphic<element_type>::value,
430 "Polymorphic types are not supported");
439 template <
typename T,
typename Y>
442 const persistent_pool_ptr<Y> &rhs) noexcept
444 return lhs.raw() == rhs.raw();
450 template <
typename T,
typename Y>
453 const persistent_pool_ptr<Y> &rhs) noexcept
455 return !(lhs == rhs);
461 template <
typename T>
463 operator!=(
const persistent_pool_ptr<T> &lhs, std::nullptr_t) noexcept
465 return lhs.raw() != 0;
471 template <
typename T>
473 operator!=(std::nullptr_t,
const persistent_pool_ptr<T> &lhs) noexcept
475 return lhs.raw() != 0;
481 template <
typename T>
483 operator==(
const persistent_pool_ptr<T> &lhs, std::nullptr_t) noexcept
485 return lhs.raw() == 0;
491 template <
typename T>
493 operator==(std::nullptr_t,
const persistent_pool_ptr<T> &lhs) noexcept
495 return lhs.raw() == 0;
498 template <
class T,
class U>
499 persistent_pool_ptr<T>
500 static_persistent_pool_pointer_cast(
const persistent_pool_ptr<U> &r)
502 static_assert(std::is_convertible<T *, U *>::value,
503 "Cannot cast persistent_pool_ptr");
504 return persistent_pool_ptr<T>(r.raw());
510 #endif // PMEMOBJ_PERSISTENT_POOL_PTR_HPP