23 #ifndef __REUSABLE_VECTOR_H__ 24 #define __REUSABLE_VECTOR_H__ 29 template <
class DATA_TYPE>
47 DATA_TYPE&
get(
unsigned int index)
const;
51 int size()
const {
return(myNextEmpty);}
56 std::vector<DATA_TYPE*> myCont;
57 unsigned int myNextEmpty;
66 template <
class DATA_TYPE>
69 for(
unsigned int i = 0; i < myCont.size(); i++)
80 template <
class DATA_TYPE>
89 template <
class DATA_TYPE>
92 if(myNextEmpty == myCont.size())
95 myCont.resize(myCont.size() + 1);
98 myCont[myNextEmpty] =
new DATA_TYPE;
104 myCont[myNextEmpty]->clear();
107 DATA_TYPE* returnVal = myCont[myNextEmpty];
116 template <
class DATA_TYPE>
119 if((index < myNextEmpty) && (index >= 0))
122 if(myCont[index] == NULL)
124 throw(std::runtime_error(
"ReusableVector::get BUG, found a null pointer."));
126 return(*myCont[index]);
130 throw(std::runtime_error(
"ReusableVector::get called with out of range index."));
134 template <
class DATA_TYPE>
void reset()
Clear the vector contents.
void clear()
Clear the vector contents.
Create a vector of DATA_TYPE that reuses created objects to save on memory reallocations.
DATA_TYPE & getNextEmpty()
Get a reference to a new entry to be populated so the user can directly populate it rather than havin...
int size() const
Return the number of populated entries in the vector.
DATA_TYPE & get(unsigned int index) const
Get a reference to the data at the specified index.