17 #ifndef PAGESPEED_KERNEL_BASE_POOL_H_
18 #define PAGESPEED_KERNEL_BASE_POOL_H_
21 #include "base/logging.h"
26 namespace net_instaweb {
43 typedef typename PoolElement<T>::Position
iterator;
44 typedef typename std::list<T*>::const_iterator const_iterator;
54 return contents_.empty();
59 return contents_.size();
64 return contents_.begin();
69 return contents_.begin();
74 return contents_.end();
78 const_iterator
end()
const {
79 return contents_.end();
84 iterator* position =
object->pool_position();
85 contents_.push_back(
object);
88 iterator back_iter = contents_.end();
90 *position = back_iter;
97 DCHECK(**position ==
object);
98 contents_.erase(*position);
99 *position = contents_.end();
106 if (!contents_.empty()) {
107 result = contents_.front();
116 if (!contents_.empty()) {
117 result = contents_.front();
118 iterator* position = result->pool_position();
119 DCHECK(*position == contents_.begin());
120 contents_.pop_front();
121 *position = contents_.end();
128 STLDeleteElements(&contents_);
137 std::list<T*> contents_;
const_iterator begin() const
const Iterator pointing to beginning of pool
Definition: pool.h:68
Position * pool_position()
Definition: pool_element.h:41
bool empty() const
Is pool empty?
Definition: pool.h:53
T * Remove(T *object)
Definition: pool.h:95
iterator begin()
Iterator pointing to beginning of pool.
Definition: pool.h:63
const_iterator end() const
Iterator pointing just past end of pool.
Definition: pool.h:78
T * RemoveOldest()
Definition: pool.h:114
PoolElement< T >::Position iterator
We can iterate over a pool using this iterator type.
Definition: pool.h:43
void Add(T *object)
Add object to pool. The object must not currently reside in a pool.
Definition: pool.h:83
iterator end()
Iterator pointing just past end of pool.
Definition: pool.h:73
size_t size() const
Size of pool.
Definition: pool.h:58
T * oldest() const
Return oldest object in pool, or NULL.
Definition: pool.h:104
void DeleteAll()
DeleteAll: delete all elements of pool.
Definition: pool.h:127
void Clear()
Clear: clear pool without deleting elements.
Definition: pool.h:132