29 #ifndef CDPL_UTIL_OBJECTSTACK_HPP
30 #define CDPL_UTIL_OBJECTSTACK_HPP
35 #include <boost/ptr_container/ptr_vector.hpp>
67 maxSize(stack.maxSize), freeIndex(0), ctorFunc(stack.ctorFunc),
68 initFunc(stack.initFunc), cleanFunc(stack.cleanFunc) {}
75 maxSize(max_pool_size), freeIndex(0), ctorFunc(ctor_func)
82 if (freeIndex == allocObjects.size())
83 allocObjects.push_back(ctorFunc());
99 cleanFunc(allocObjects[freeIndex]);
102 if (maxSize > 0 && freeIndex <= maxSize && allocObjects.size() > maxSize)
103 allocObjects.erase(allocObjects.begin() + maxSize, allocObjects.end());
109 std::for_each(allocObjects.begin(), allocObjects.begin() + freeIndex,
113 if (maxSize > 0 && allocObjects.size() > maxSize)
114 allocObjects.erase(allocObjects.begin() + maxSize, allocObjects.end());
126 if (maxSize > 0 && allocObjects.size() > maxSize)
127 allocObjects.erase(allocObjects.begin() + std::max(freeIndex, maxSize), allocObjects.end());
133 allocObjects.erase(allocObjects.begin() + freeIndex, allocObjects.end());
138 allocObjects.clear();
156 maxSize = stack.maxSize;
157 ctorFunc = stack.ctorFunc;
158 initFunc = stack.initFunc;
160 if (maxSize > 0 && allocObjects.size() > maxSize)
161 allocObjects.erase(allocObjects.begin() + std::max(freeIndex, maxSize), allocObjects.end());
167 typedef boost::ptr_vector<ObjectType> AllocObjectList;
170 std::size_t freeIndex;
171 AllocObjectList allocObjects;
ObjectStack.
Definition: ObjectStack.hpp:49
void put()
Definition: ObjectStack.hpp:93
std::function< ObjectType *()> ConstructorFunction
Definition: ObjectStack.hpp:54
void setCleanupFunction(const ObjectFunction &func)
Definition: ObjectStack.hpp:146
void putAll()
Definition: ObjectStack.hpp:106
ObjectStack & operator=(const ObjectStack &stack)
Definition: ObjectStack.hpp:151
void setMaxSize(std::size_t max_size)
Definition: ObjectStack.hpp:122
ObjectType * get()
Definition: ObjectStack.hpp:80
void freeMemory(bool unused_only=true)
Definition: ObjectStack.hpp:130
std::function< void(ObjectType &)> ObjectFunction
Definition: ObjectStack.hpp:55
std::size_t getMaxSize() const
Definition: ObjectStack.hpp:117
ObjectStack(const C &ctor_func, std::size_t max_pool_size)
Definition: ObjectStack.hpp:74
void setInitFunction(const ObjectFunction &func)
Definition: ObjectStack.hpp:141
ObjectStack(std::size_t max_pool_size=0)
Definition: ObjectStack.hpp:70
ObjectStack(const ObjectStack &stack)
Definition: ObjectStack.hpp:66
~ObjectStack()
Definition: ObjectStack.hpp:78
T ObjectType
Definition: ObjectStack.hpp:52
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int C
Specifies Carbon.
Definition: AtomType.hpp:92
The namespace of the Chemical Data Processing Library.
Definition: ObjectStack.hpp:58
T * operator()() const
Definition: ObjectStack.hpp:60