Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
pool.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//pool.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//pool.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with pool.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
25
26
27#ifndef BERTINI_GENERIC_POOL_HPP
28#define BERTINI_GENERIC_POOL_HPP
29
30namespace bertini {
31
32 namespace detail {
33
34
36 template<typename ObjT>
38 {
39 using PointerType = std::shared_ptr<ObjT>;
40
42 static
44 {
45 return std::make_shared<ObjT>(std::move(d));
46 }
47
49 static
51 {
52 return std::make_shared<ObjT>();
53 }
54
55 };
56
57
59 template<typename ObjT>
61
62
63
65 template<typename ObjT, class PointerPolicy = DefaultPointerPolicy<ObjT> >
66 class Pool
67 {
68
69
70
71
72 public:
73
74 using HeldType = typename PointerPolicy::PointerType;
75 using PoolHolderType = std::vector< HeldType >;
76
78 static
80 {
81 // held_data_.push_back(PointerPolicy::FromObj(d));
82 held_data_.push_back(PointerPolicy::FromObj(d));
83 return held_data_.back();
84 }
85
87 static
89 {
90 held_data_.push_back(d);
91 return held_data_.back();
92 }
93
95 template<typename ... Ts>
96 static
97 HeldType Make(Ts&& ...ts )
98 {
99 auto thing = std::shared_ptr<ObjT>(new ObjT(ts...));
100 held_data_.push_back(thing);
101 return held_data_.back();
102 }
103
105 static
107 {
108 std::remove_if(held_data_.begin(), held_data_.end(), [](HeldType const& h){return h.use_count()==1;});
109 }
110
111 private:
112 static
113 PoolHolderType held_data_;
114 };
115
117 template<typename ObjT, class Policy> typename Pool<ObjT,Policy>::PoolHolderType Pool<ObjT,Policy>::held_data_;
119 } // re: detail
120} // re: bertini
121
122#endif
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