27#ifndef BERTINI_GENERIC_POOL_HPP
28#define BERTINI_GENERIC_POOL_HPP
36 template<
typename ObjT>
45 return std::make_shared<ObjT>(std::move(d));
52 return std::make_shared<ObjT>();
59 template<
typename ObjT>
65 template<
typename ObjT,
class Po
interPolicy = DefaultPo
interPolicy<ObjT> >
74 using HeldType =
typename PointerPolicy::PointerType;
82 held_data_.push_back(PointerPolicy::FromObj(d));
83 return held_data_.back();
90 held_data_.push_back(d);
91 return held_data_.back();
95 template<
typename ... Ts>
99 auto thing = std::shared_ptr<ObjT>(
new ObjT(ts...));
100 held_data_.push_back(thing);
101 return held_data_.back();
108 std::remove_if(held_data_.begin(), held_data_.end(), [](
HeldType const& h){return h.use_count()==1;});
A process-wide cache of objects, held by pointer, that hands out shared references.
Definition pool.hpp:67
static HeldType Make(Ts &&...ts)
Construct an object in place in the pool, returning the held pointer.
Definition pool.hpp:97
static HeldType PtrAdd(HeldType d)
Add an already-held pointer to the pool, returning it.
Definition pool.hpp:88
static void PurgeCache()
Drop pooled objects that are no longer referenced anywhere else.
Definition pool.hpp:106
std::vector< HeldType > PoolHolderType
The container of held pointers.
Definition pool.hpp:75
static HeldType NonPtrAdd(ObjT d)
Add an object (by value) to the pool, returning the held pointer.
Definition pool.hpp:79
typename PointerPolicy::PointerType HeldType
The pointer type the pool holds.
Definition pool.hpp:74
Definition configured.hpp:34
SharedPointerPolicy< ObjT > DefaultPointerPolicy
The default pool pointer policy (shared_ptr).
Definition pool.hpp:60
Definition algorithm_builder.hpp:36
Pool pointer policy that holds objects via std::shared_ptr.
Definition pool.hpp:38
std::shared_ptr< ObjT > PointerType
The held pointer type.
Definition pool.hpp:39
static PointerType DefaultConstructed()
Make a held pointer to a default-constructed object.
Definition pool.hpp:50
static PointerType FromObj(ObjT d)
Make a held pointer from an object value.
Definition pool.hpp:43