PMDK C++ bindings 1.13.0
This is the C++ bindings documentation for PMDK's libpmemobj.
utils.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2/* Copyright 2016-2019, Intel Corporation */
3
8#ifndef LIBPMEMOBJ_CPP_UTILS_HPP
9#define LIBPMEMOBJ_CPP_UTILS_HPP
10
13#include <libpmemobj/base.h>
14
15namespace pmem
16{
17
18namespace obj
19{
20
30template <typename T>
31inline pool_base
32pool_by_vptr(const T *that)
33{
34 auto pop = pmemobj_pool_by_ptr(that);
35 if (!pop)
36 throw pmem::pool_error("Object not in an open pool.");
37
38 return pool_base(pop);
39}
40
50template <typename T>
51inline pool_base
53{
54 auto pop = pmemobj_pool_by_oid(ptr.raw());
55 if (!pop)
56 throw pmem::pool_error("Object not in an open pool.");
57
58 return pool_base(pop);
59}
60
61} /* namespace obj */
62
63} /* namespace pmem */
64
65#endif /* LIBPMEMOBJ_CPP_UTILS_HPP */
const PMEMoid & raw() const noexcept
Get PMEMoid encapsulated by this object.
Definition: persistent_ptr_base.hpp:151
Persistent pointer class.
Definition: persistent_ptr.hpp:152
The non-template pool base class.
Definition: pool.hpp:50
Custom pool error class.
Definition: pexceptions.hpp:45
pool_base pool_by_pptr(const persistent_ptr< T > ptr)
Retrieve pool handle for the given persistent_ptr.
Definition: utils.hpp:52
pool_base pool_by_vptr(const T *that)
Retrieve pool handle for the given pointer.
Definition: utils.hpp:32
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent smart pointer.
Custom exceptions.