A container for fast array allocation/deallocation. More...
#include <Radiant/VectorStorage.hpp>
Public Types | |
| typedef std::vector< T >::iterator | iterator |
| Iterator. | |
Public Member Functions | |
| void | append (const T &x) |
| Appends an object to the vector. More... | |
| T & | append () |
| Increase the size of the storage by one, and return the last object. More... | |
| iterator | begin () |
| Returns iterator to the beginning of the vector. More... | |
| void | clear () |
| Resets the internal object counter to zero. More... | |
| T * | data () |
| Pointer to the first element. More... | |
| const T * | data () const |
| Pointer to the first element. More... | |
| bool | empty () const |
| Returns true if the vector is empty. More... | |
| iterator | end () |
| Returns iterator to the end of the vector. More... | |
| void | erase (size_t index) |
| Erase an element. More... | |
| void | expand (size_t size) |
| Expand the size of the storage buffer to desired size. More... | |
| const T & | get (size_t index) const |
| Gets an object, without safety checks. More... | |
| T & | get (size_t index) |
| Gets an object, without safety checks. More... | |
| T & | getExpand (size_t index) |
| Gets a value from the vector and expand the vector if necessary. More... | |
| T & | getLast () |
| Gets reference to the last elemnt. More... | |
| const T & | getLast () const |
| Gets reference to the last elemnt. More... | |
| const T & | getLast (size_t n) const |
| Gets the element at size() - n - 1. More... | |
| const T & | getSafe (size_t index) const |
| Gets an object, and check that the index is valid. More... | |
| T & | getSafe (size_t index) |
| Gets an object, and check that the index is valid. More... | |
| T & | last () |
| Gets reference to the last elemnt. More... | |
| const T & | last (size_t n) const |
| Gets the element at size() - n - 1. More... | |
| void | merge (VectorStorage &that) |
| Appends elements from that to the end of this. More... | |
| VectorStorage & | operator= (const VectorStorage &that) |
| Copies a vector. More... | |
| T & | operator[] (size_t i) |
| Returns the element at the given index. More... | |
| const T & | operator[] (size_t i) const |
| Returns the element at the given index. More... | |
| void | prepend (const T &x) |
| Push an object to the beginning of the array. More... | |
| void | push_back (const T &x) |
| Appends an object to the vector, equals append(x). More... | |
| void | putBack (size_t n) |
| Remove n elements from the end of the storage. More... | |
| size_t | reserved () const |
| The number of allocated objects. More... | |
| void | reset () |
| Resets the internal object counter to zero. More... | |
| void | resize (size_t size) |
| Resizes the vector. More... | |
| void | setAll (const T &value) |
| Fills the vector with the given value. More... | |
| size_t | size () const |
| The number of objecs in the array. More... | |
| void | swap (VectorStorage &that) |
| Swaps two VectorStorages. More... | |
| void | truncate (size_t n) |
| Resets the internal object counter to n. More... | |
| std::vector< T > & | vector () |
| Returns the internal data storage area. More... | |
| VectorStorage () | |
| Creates an empty vector storage object. | |
A container for fast array allocation/deallocation.
This class for handling resources that need to be frequently allocated/deallocated. The key point is that the memory is deallocated only in the destructor or when explicitly desired.
Internally this class uses std::vector to do the real memory handling. It is sometimes used as a member variable of some class.
Example:
VectorStorage<Item> items;
elems.expand(5000); This is entirely optional
Now we would use the "items" object for a longer time inside the while-loop.
while(keepGoing()) {
items.reset(); while(fillingTheBuffer()) {
Item item;
items.append(item);
}doSomeThingWithTheItems(items); }
|
inline |
Appends an object to the vector.
The storage area is automatically incremented if necessary.
| x | Element to append |
|
inline |
Increase the size of the storage by one, and return the last object.
The storage area is automatically incremented if necessary.
|
inline |
Returns iterator to the beginning of the vector.
|
inline |
Resets the internal object counter to zero.
This function does not erase any objects.
|
inline |
Pointer to the first element.
|
inline |
Pointer to the first element.
|
inline |
Returns true if the vector is empty.
|
inline |
Returns iterator to the end of the vector.
|
inline |
Erase an element.
The size of the storage is shrunk by one.
| index | Index of element to remove |
|
inline |
Expand the size of the storage buffer to desired size.
This function can be run in software initialization phase, to
avoid the need to resize the buffer later on.
| size | new size of buffer |
|
inline |
Gets an object, without safety checks.
| index | Index of element to retrieve |
|
inline |
Gets an object, without safety checks.
| index | Index of element to retrieve |
|
inline |
Gets a value from the vector and expand the vector if necessary.
| index | Index of element to retrieve |
|
inline |
Gets reference to the last elemnt.
|
inline |
Gets reference to the last elemnt.
|
inline |
Gets the element at size() - n - 1.
| n | Element-index, counted from the back |
|
inline |
Gets an object, and check that the index is valid.
If the index is not valid, then assertion is raised, and the software stops.
| index | Index of element to retrieve |
|
inline |
Gets an object, and check that the index is valid.
If the index is not valid, then assertion is raised, and the software stops.
| index | Index of element to retrieve |
|
inline |
Gets reference to the last elemnt.
|
inline |
Gets the element at size() - n - 1.
| n | Element-index, counted from the back |
|
inline |
Appends elements from that to the end of this.
| that | Vector to merge with |
|
inline |
Copies a vector.
| that | Vector to copy from |
|
inline |
Returns the element at the given index.
| i | Index of element to retrieve |
|
inline |
Returns the element at the given index.
| i | Index of element to retrieve |
|
inline |
Push an object to the beginning of the array.
This function call takes some time on larger arrays, so it
should be used with care.
| x | Element to prepend |
|
inline |
Appends an object to the vector, equals append(x).
This method has been implemented so that this class looks and feels more like a typical STL container.
| x | Element to append |
|
inline |
Remove n elements from the end of the storage.
| n | Number of elements to remove |
|
inline |
The number of allocated objects.
|
inline |
Resets the internal object counter to zero.
This function does not erase any objects.
|
inline |
Resizes the vector.
| size | new size of buffer |
|
inline |
Fills the vector with the given value.
| value | to fill with |
|
inline |
The number of objecs in the array.
|
inline |
Swaps two VectorStorages.
| that | Vector to swap with |
|
inline |
Resets the internal object counter to n.
| n | New value of object counter |
|
inline |
Returns the internal data storage area.