|
Page Speed Optimization Libraries
1.13.35.1
|
#include "pool.h"
Public Types | |
| typedef PoolElement< T >::Position | iterator |
| We can iterate over a pool using this iterator type. | |
|
typedef std::list< T * > ::const_iterator | const_iterator |
Public Member Functions | |
| bool | empty () const |
| Is pool empty? | |
| size_t | size () const |
| Size of pool. | |
| iterator | begin () |
| Iterator pointing to beginning of pool. | |
| const_iterator | begin () const |
| const Iterator pointing to beginning of pool | |
| iterator | end () |
| Iterator pointing just past end of pool. | |
| const_iterator | end () const |
| Iterator pointing just past end of pool. | |
| void | Add (T *object) |
| Add object to pool. The object must not currently reside in a pool. More... | |
| T * | Remove (T *object) |
| T * | oldest () const |
| Return oldest object in pool, or NULL. | |
| T * | RemoveOldest () |
| void | DeleteAll () |
| DeleteAll: delete all elements of pool. | |
| void | Clear () |
| Clear: clear pool without deleting elements. | |
A pool holds references to objects of type T that provide a pool_position method (which they can do by extending PoolElement in pool_element.h, or by providing a getter method of type PoolElement::Position* pool_position() (an abstract settable pointer for a PoolElement::Position). Pool objects are maintained in insertion order.
We can insert and remove references from a pool, ask for an arbitrary reference contained in a pool, and clear or delete all pool elements. By default on destruction we delete pool elements using DeleteAll(); if a pool does not acquire object ownership, we should instead .Clear() it before destruction.
|
inline |
Add object to pool. The object must not currently reside in a pool.
We need to get an iterator to the last element. We locally bind to avoid potential compiler trouble.
|
inline |
Remove specified object from pool. The object must have previously been inserted into this pool. Returns object.
|
inline |
Remove the least-recently-inserted object from the pool. Potentially cheaper than Remove(Oldest()).
1.8.6