A generic container to handle a pool of objects. More...
Public Types | |
typedef std::vector< T >::iterator | iterator |
the iterator of a Pool | |
typedef std::vector< T > ::const_iterator | const_iterator |
the constant iterator of a Pool | |
typedef std::vector< T > ::reverse_iterator | reverse_iterator |
the reverse iterator of a Pool | |
typedef std::vector< T > ::const_reverse_iterator | const_reverse_iterator |
the constant reverse iterator of a Pool | |
Public Member Functions | |
Pool (size_t capacity=DEFAULT_CAPACITY) | |
Constructor of Pool. | |
T & | operator[] (size_t index) |
Gets the element of the Pool at index. | |
const T & | operator[] (size_t index) const |
Gets the element of the Pool at index. | |
size_t | size () const |
Gets the number of active elements in this Pool. | |
size_t | getNbActive () const |
Gets the number of active elements in this Pool. | |
size_t | getNbInactive () const |
Gets the number of inactive elements in this Pool. | |
size_t | getNbTotal () const |
Gets the number of elements in this Pool. | |
size_t | getNbReserved () const |
Gets the capacity of this Pool. | |
size_t | getNbEmpty () const |
Gets the room left for new elements in this Pool. | |
size_t | getMaxTotal () const |
Gets the maximum number of elements this Pool had. | |
iterator | begin () |
Gets an iterator referring to the first active element in this Pool. | |
iterator | end () |
Gets an iterator referring to the past-the-end active element in this Pool. | |
iterator | beginActive () |
Gets an iterator referring to the first active element in this Pool. | |
iterator | endActive () |
Gets an iterator referring to the past-the-end active element in this Pool. | |
iterator | beginInactive () |
Gets an iterator referring to the first inactive element in this Pool. | |
iterator | endInactive () |
Gets an iterator referring to the past-the-end inactive element in this Pool. | |
const_iterator | begin () const |
Gets an iterator referring to the first active element in this Pool. | |
const_iterator | end () const |
Gets an iterator referring to the past-the-end active element in this Pool. | |
const_iterator | beginActive () const |
Gets an iterator referring to the first active element in this Pool. | |
const_iterator | endActive () const |
Gets an iterator referring to the past-the-end active element in this Pool. | |
const_iterator | beginInactive () const |
Gets an iterator referring to the first inactive element in this Pool. | |
const_iterator | endInactive () const |
Gets an iterator referring to the past-the-end inactive element in this Pool. | |
reverse_iterator | rbegin () |
Gets a reverse iterator referring to the first active element in this Pool. | |
reverse_iterator | rend () |
Gets a reverse iterator referring to the past-the-end active element in this Pool. | |
reverse_iterator | rbeginActive () |
Gets a reverse iterator referring to the first active element in this Pool. | |
reverse_iterator | rendActive () |
Gets a reverse iterator referring to the past-the-end active element in this Pool. | |
reverse_iterator | rbeginInactive () |
Gets a reverse iterator referring to the first inactive element in this Pool. | |
reverse_iterator | rendInactive () |
Gets a reverse iterator referring to the past-the-end inactive element in this Pool. | |
const_reverse_iterator | rbegin () const |
Gets a reverse iterator referring to the first active element in this Pool. | |
const_reverse_iterator | rend () const |
Gets a reverse iterator referring to the past-the-end active element in this Pool. | |
const_reverse_iterator | rbeginActive () const |
Gets a reverse iterator referring to the first active element in this Pool. | |
const_reverse_iterator | rendActive () const |
Gets a reverse iterator referring to the past-the-end active element in this Pool. | |
const_reverse_iterator | rbeginInactive () const |
Gets a reverse iterator referring to the first inactive element in this Pool. | |
const_reverse_iterator | rendInactive () const |
Gets a reverse iterator referring to the past-the-end inactive element in this Pool. | |
T & | front () |
Gets the first active element. | |
T & | back () |
Gets the last active element. | |
T & | frontActive () |
Gets the first active element. | |
T & | backActive () |
Gets the last active element. | |
T & | frontInactive () |
Gets the first inactive element. | |
T & | backInactive () |
Gets the last inactive element. | |
const T & | front () const |
Gets the first active element. | |
const T & | back () const |
Gets the last active element. | |
const T & | frontActive () const |
Gets the first active element. | |
const T & | backActive () const |
Gets the last active element. | |
const T & | frontInactive () const |
Gets the first inactive element. | |
const T & | backInactive () const |
Gets the last inactive element. | |
void | assign (T &value) |
Fills the Pool with a copy of the passed element. | |
bool | pushActive (T &element) |
Adds an active element to this Pool. | |
bool | pushInactive (T &element) |
Adds an inactive element to this Pool. | |
void | makeInactive (size_t index) |
Inactivates an active element. | |
void | makeAllInactive () |
Inactivates all the elements. | |
T * | makeActive () |
Activates the first inactive element. | |
T * | makeActive (size_t index) |
Activates the index inactive element. | |
void | erase (size_t index) |
Removes an element from this Pool. | |
void | clear () |
Removes all elements in this Pool. | |
void | reallocate (size_t capacity) |
reallocates the Pool | |
Static Public Attributes | |
static const unsigned int | DEFAULT_CAPACITY = 1000 |
the default capacity of a Pool |
A generic container to handle a pool of objects.
A Pool is a container built upon a std vector. It allows to store continuous objects by handling active and inactive ones.
A Pool is designed to be faster than a vector to handle. However, the order of elements is not fixed.
A Pool holds 2 continuous list of elements : the actives and the inactives :
So when activating or disactivating an element, a single swap is used which is faster than the displacement of all following elements when inserting or removing an element from a vector.
Elements are not removed in a Pool but only inactivated. Typically, elements will be removed when the Pool has to be destroyed or reinitialize.
Another difference with a vector is that the reallocation is not automatic but only manual with a call to reallocate(unsigned int). Therefore adding elements to a full Pool will have no effect until its capacity is increased.
Definition at line 52 of file SPK_Pool.h.
typedef std::vector<T>::const_iterator const_iterator |
the constant iterator of a Pool
Definition at line 60 of file SPK_Pool.h.
typedef std::vector<T>::const_reverse_iterator const_reverse_iterator |
the constant reverse iterator of a Pool
Definition at line 66 of file SPK_Pool.h.
the iterator of a Pool
Definition at line 57 of file SPK_Pool.h.
typedef std::vector<T>::reverse_iterator reverse_iterator |
the reverse iterator of a Pool
Definition at line 63 of file SPK_Pool.h.
Pool | ( | size_t | capacity = DEFAULT_CAPACITY |
) |
Constructor of Pool.
The capacity is the maximum number of elements a Pool can hold.
Unlike a std vector, the capacity is not automatically increased when reaching it. The user has to manually make a call to reallocate(unsigned int) to increase the capacity. If an elements is added to a full Pool, nothing will happen.
capacity | : the maximum number of elements the Pool can hold |
Definition at line 616 of file SPK_Pool.h.
void assign | ( | T & | value | ) |
Fills the Pool with a copy of the passed element.
The Pool is filled entirely which means its number of elements will be equal to its capacity.
Note that all added elements are inactive.
value | : the element which will be copied into the Pool |
Definition at line 918 of file SPK_Pool.h.
const T & back | ( | ) | const |
Gets the last active element.
This is the constant version of back().
Definition at line 888 of file SPK_Pool.h.
T & back | ( | ) |
Gets the last active element.
This method is the standard equivalent to backActive().
Definition at line 852 of file SPK_Pool.h.
const T & backActive | ( | ) | const |
Gets the last active element.
This is the constant version of backActive().
Definition at line 900 of file SPK_Pool.h.
T & backActive | ( | ) |
Gets the last active element.
This method is the equivalent to the standard back().
Definition at line 864 of file SPK_Pool.h.
const T & backInactive | ( | ) | const |
Gets the last inactive element.
This is the constant version of backInactive().
Definition at line 912 of file SPK_Pool.h.
T & backInactive | ( | ) |
Gets the last inactive element.
Definition at line 876 of file SPK_Pool.h.
Pool< T >::const_iterator begin | ( | ) | const |
Gets an iterator referring to the first active element in this Pool.
This is the constant version of begin().
Definition at line 738 of file SPK_Pool.h.
Gets an iterator referring to the first active element in this Pool.
This method is the standard equivalent to beginActive().
Definition at line 702 of file SPK_Pool.h.
Pool< T >::const_iterator beginActive | ( | ) | const |
Gets an iterator referring to the first active element in this Pool.
This is the constant version of beginActive().
Definition at line 750 of file SPK_Pool.h.
Gets an iterator referring to the first active element in this Pool.
This method is equivalent to the standard begin().
Definition at line 714 of file SPK_Pool.h.
Pool< T >::const_iterator beginInactive | ( | ) | const |
Gets an iterator referring to the first inactive element in this Pool.
This is the constant version of beginInactive().
Definition at line 762 of file SPK_Pool.h.
Gets an iterator referring to the first inactive element in this Pool.
Note that this method retuns the same iterator as end() and endActive(), but due to syntax, should not be use for the same purpose.
Definition at line 726 of file SPK_Pool.h.
void clear | ( | ) |
Removes all elements in this Pool.
Definition at line 1014 of file SPK_Pool.h.
Pool< T >::const_iterator end | ( | ) | const |
Gets an iterator referring to the past-the-end active element in this Pool.
This is the constant version of end().
Definition at line 744 of file SPK_Pool.h.
Gets an iterator referring to the past-the-end active element in this Pool.
This method is the standard equivalent to endActive().
It also returns the same iterator as beginInactive() but, to respect the syntax, should not be used for the same purpose.
Definition at line 708 of file SPK_Pool.h.
Pool< T >::const_iterator endActive | ( | ) | const |
Gets an iterator referring to the past-the-end active element in this Pool.
This is the constant version of endActive().
Definition at line 756 of file SPK_Pool.h.
Gets an iterator referring to the past-the-end active element in this Pool.
This method is equivalent to the standard end().
It also returns the same iterator as beginInactive() but, to respect the syntax, should not be used for the same purpose.
Definition at line 720 of file SPK_Pool.h.
Pool< T >::const_iterator endInactive | ( | ) | const |
Gets an iterator referring to the past-the-end inactive element in this Pool.
This is the constant version of endInactive().
Definition at line 768 of file SPK_Pool.h.
Gets an iterator referring to the past-the-end inactive element in this Pool.
Definition at line 732 of file SPK_Pool.h.
void erase | ( | size_t | index | ) |
Removes an element from this Pool.
The index is checked for bounds. If it is out of bounds nothing happens.
Note that either an active or inactive element can be removed.
index | : the index of the element to remove |
Definition at line 997 of file SPK_Pool.h.
const T & front | ( | ) | const |
Gets the first active element.
This is the constant version of front().
Definition at line 882 of file SPK_Pool.h.
T & front | ( | ) |
Gets the first active element.
This method is the standard equivalent to frontActive().
Definition at line 846 of file SPK_Pool.h.
const T & frontActive | ( | ) | const |
Gets the first active element.
This is the constant version of frontActive().
Definition at line 894 of file SPK_Pool.h.
T & frontActive | ( | ) |
Gets the first active element.
This method is equivalent to the standard front().
Definition at line 858 of file SPK_Pool.h.
const T & frontInactive | ( | ) | const |
Gets the first inactive element.
This is the constant version of frontInactive().
Definition at line 906 of file SPK_Pool.h.
T & frontInactive | ( | ) |
Gets the first inactive element.
Definition at line 870 of file SPK_Pool.h.
size_t getMaxTotal | ( | ) | const |
Gets the maximum number of elements this Pool had.
This is useful to check if the capacity is well set or not.
Definition at line 696 of file SPK_Pool.h.
size_t getNbActive | ( | ) | const |
Gets the number of active elements in this Pool.
This method is equivalent to the standard size()
Definition at line 666 of file SPK_Pool.h.
size_t getNbEmpty | ( | ) | const |
Gets the room left for new elements in this Pool.
This is defined by : capacity - number of elements.
Definition at line 690 of file SPK_Pool.h.
size_t getNbInactive | ( | ) | const |
Gets the number of inactive elements in this Pool.
Definition at line 672 of file SPK_Pool.h.
size_t getNbReserved | ( | ) | const |
Gets the capacity of this Pool.
The capacity is the maximum number of elements a Pool can hold.
Definition at line 684 of file SPK_Pool.h.
size_t getNbTotal | ( | ) | const |
Gets the number of elements in this Pool.
the number of elements is defined by : number of active elements + number of inactive elements.
Definition at line 678 of file SPK_Pool.h.
T * makeActive | ( | size_t | index | ) |
Activates the index inactive element.
The index starts at the first inactive element.
This method is a bit slower than makeActive() but makeActive() has the same effect as makeActive(0).
If the element at index is out of bounds, NULL is returned
index | : the inactive element to activate |
Definition at line 986 of file SPK_Pool.h.
T * makeActive | ( | ) |
Activates the first inactive element.
A pointer to the activated element is returned. If there is no inactive element to activate, NULL is returned.
Definition at line 976 of file SPK_Pool.h.
void makeAllInactive | ( | ) |
Inactivates all the elements.
Definition at line 970 of file SPK_Pool.h.
void makeInactive | ( | size_t | index | ) |
Inactivates an active element.
The index is tested and if it does not point to an active element, nothing will happen.
index | : the index of the active element to inactivate |
Definition at line 960 of file SPK_Pool.h.
const T & operator[] | ( | size_t | index | ) | const |
Gets the element of the Pool at index.
This is the constant version of operator[](size_t).
index | : the index of the element to access |
Definition at line 654 of file SPK_Pool.h.
T & operator[] | ( | size_t | index | ) |
Gets the element of the Pool at index.
Note that the index is not tested and can therefore be out of bounds.
index | : the index of the element to access |
Definition at line 648 of file SPK_Pool.h.
bool pushActive | ( | T & | element | ) |
Adds an active element to this Pool.
element | : the element to add to this Pool |
Definition at line 930 of file SPK_Pool.h.
bool pushInactive | ( | T & | element | ) |
Adds an inactive element to this Pool.
element | : the element to add to this Pool |
Definition at line 946 of file SPK_Pool.h.
Pool< T >::const_reverse_iterator rbegin | ( | ) | const |
Gets a reverse iterator referring to the first active element in this Pool.
This is the constant version of rbegin().
Definition at line 810 of file SPK_Pool.h.
Pool< T >::reverse_iterator rbegin | ( | ) |
Gets a reverse iterator referring to the first active element in this Pool.
This method is the standard equivalent to rbeginActive().
Definition at line 774 of file SPK_Pool.h.
Pool< T >::const_reverse_iterator rbeginActive | ( | ) | const |
Gets a reverse iterator referring to the first active element in this Pool.
This is the constant version of rbeginActive().
Definition at line 822 of file SPK_Pool.h.
Pool< T >::reverse_iterator rbeginActive | ( | ) |
Gets a reverse iterator referring to the first active element in this Pool.
This method is equivalent to the standard rbegin().
Definition at line 786 of file SPK_Pool.h.
Pool< T >::const_reverse_iterator rbeginInactive | ( | ) | const |
Gets a reverse iterator referring to the first inactive element in this Pool.
This is the constant version of rbeginInactive().
Definition at line 834 of file SPK_Pool.h.
Pool< T >::reverse_iterator rbeginInactive | ( | ) |
Gets a reverse iterator referring to the first inactive element in this Pool.
Note that this method retuns the same iterator as rend() and rendActive(), but due to syntax, should not be use for the same purpose.
Definition at line 798 of file SPK_Pool.h.
void reallocate | ( | size_t | capacity | ) |
reallocates the Pool
This will invalidates all iterators on the Pool.
If the new capacity is smaller than the number of elements, nothing happens.
capacity | : the new desired capacity for this Pool |
Definition at line 1021 of file SPK_Pool.h.
Pool< T >::const_reverse_iterator rend | ( | ) | const |
Gets a reverse iterator referring to the past-the-end active element in this Pool.
This is the constant version of rend().
Definition at line 816 of file SPK_Pool.h.
Pool< T >::reverse_iterator rend | ( | ) |
Gets a reverse iterator referring to the past-the-end active element in this Pool.
This method is the standard equivalent to rendActive().
It also returns the same reverse iterator as rbeginInactive() but, to respect the syntax, should not be used for the same purpose.
Definition at line 780 of file SPK_Pool.h.
Pool< T >::const_reverse_iterator rendActive | ( | ) | const |
Gets a reverse iterator referring to the past-the-end active element in this Pool.
This is the constant version of rendActive().
Definition at line 828 of file SPK_Pool.h.
Pool< T >::reverse_iterator rendActive | ( | ) |
Gets a reverse iterator referring to the past-the-end active element in this Pool.
This method is equivalent to the standard rend().
It also returns the same reverse iterator as rbeginInactive() but, to respect the syntax, should not be used for the same purpose.
Definition at line 792 of file SPK_Pool.h.
Pool< T >::const_reverse_iterator rendInactive | ( | ) | const |
Gets a reverse iterator referring to the past-the-end inactive element in this Pool.
This is the constant version of rendInactive().
Definition at line 840 of file SPK_Pool.h.
Pool< T >::reverse_iterator rendInactive | ( | ) |
Gets a reverse iterator referring to the past-the-end inactive element in this Pool.
Definition at line 804 of file SPK_Pool.h.
size_t size | ( | ) | const |
Gets the number of active elements in this Pool.
This method is the standard equivalent to getNbActive()
Definition at line 660 of file SPK_Pool.h.
const unsigned int DEFAULT_CAPACITY = 1000 [static] |
the default capacity of a Pool
Definition at line 69 of file SPK_Pool.h.