9 #ifndef LIBPMEMOBJ_CPP_DEFRAG_HPP
10 #define LIBPMEMOBJ_CPP_DEFRAG_HPP
12 #include <type_traits>
18 #include <libpmemobj/atomic_base.h>
19 #include <libpmemobj/base.h>
26 using for_each_ptr_function = void (*)(obj::persistent_ptr_base &ptr);
29 using t_has_for_each_ptr =
typename std::enable_if<
30 std::is_same<decltype(std::declval<T>().for_each_ptr(
31 std::declval<for_each_ptr_function>())),
35 using t_is_defragmentable = supports<T, t_has_for_each_ptr>;
49 static constexpr
typename std::enable_if<detail::t_is_defragmentable<T>::value,
51 is_defragmentable() noexcept
63 static constexpr
typename std::enable_if<!detail::t_is_defragmentable<T>::value,
65 is_defragmentable() noexcept
110 template <
typename T>
111 typename std::enable_if<is_defragmentable<T>(),
void>::type
114 if (pmemobj_pool_by_ptr(&t) != pop.
handle())
115 throw std::runtime_error(
116 "object is not from the chosen pool");
119 this->container.push_back(&ptr);
138 template <
typename T,
typename = T>
139 typename std::enable_if<!is_defragmentable<T>(),
void>::type
142 if (pmemobj_pool_by_ptr(&t) != pop.
handle())
143 throw std::runtime_error(
144 "object is not from the chosen pool");
160 template <
typename T>
164 if (pmemobj_pool_by_oid(ptr.raw()) != pop.
handle())
165 throw std::runtime_error(
166 "persistent_ptr does not point to an object from the chosen pool");
168 this->container.push_back(&ptr);
190 pobj_defrag_result result = this->pop.
defrag(
191 this->container.data(), this->container.size());
197 std::vector<persistent_ptr_base *> container;