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) {}
71 maxSize(max_pool_size), freeIndex(0), ctorFunc(DefaultConstructor()) {}
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;
179 #endif // CDPL_UTIL_OBJECTSTACK_HPP