18 #define MAXCAPACITY (SLint)(pow(2.0f, (SLfloat)(sizeof(U) * 8))) - 1
27 template<
class T,
class U>
59 template<
class T,
class U>
67 template<
class T,
class U>
72 _contents =
new T[_capacity];
75 template<
class T,
class U>
84 template<
class T,
class U>
95 template<
class T,
class U>
101 SL_LOG(
"SLVector::operator[]: Index >= size! Overflow! Argh!");
102 return _contents[_size - 1];
113 template<
class T,
class U>
120 SL_LOG(
"SLVector::operator[]: Index >= size! Overflow! Argh!");
121 return _contents[_size - 1];
127 template<
class T,
class U>
135 template<
class T,
class U>
143 template<
class T,
class U>
160 temp =
new T[_capacity];
161 for (i = 0; i < _capacity; ++i)
174 template<
class T,
class U>
183 SL_LOG(
"SLVector::reserve: newSize > Max. capacity");
188 if ((U)newSize >= _size)
190 _capacity = (U)newSize;
191 temp =
new T[_capacity];
192 for (i = 0; i < _size; i++)
193 temp[i] = _contents[i];
199 template<
class T,
class U>
204 if (_size >= _capacity)
206 reserve(_capacity * 2);
208 _contents[_size] = element;
215 _contents =
new T[_capacity];
216 _contents[0] = element;
220 template<
class T,
class U>
225 SL_EXIT_MSG(
"SLVector::erase(SLuint index): Index out of range!");
227 else if (index == _size - 1)
236 T* temp =
new T[_capacity];
237 for (j = 0; j < _size; ++j)
240 temp[j] = _contents[j];
242 temp[j] = _contents[j + 1];
249 template<
class T,
class U>
255 for (i = 0; i < (_size / 2); i++)
258 _contents[i] = _contents[_size - i - 1];
259 _contents[_size - i - 1] = temp;
263 template<
class T,
class U>
269 SL_LOG(
"SLVector::reserve: newSize > Max. capacity");
274 _capacity = (U)newSize;
277 if (_capacity) _contents =
new T[_capacity];
280 template<
class T,
class U>
#define SL_EXIT_MSG(message)
Template class for dynamic vector.
virtual ~SLVector()
standard destructor
U _capacity
internal size of array of type U
void push_back(const T element)
appends element at end
void resize(SLuint64 size=0)
deletes all, sets _size=size
T * _contents
pointer to the array of type T
U _size
real size of array of type U
void erase(U i)
delete element at pos i
void reverse()
reverses the order
void reserve(SLuint64 newSize)
set capacity = newSize
void pop_back()
deletes element at end
T & at(SLuint i)
returns element at pos i
SLVector()
creates empty array
U capacity()
returns internal size
SLVector< T, U > & operator=(const SLVector &a)
assignment operator
T & operator[](SLuint i)
access operator
void set(const SLVector &a)
set array with another
void set(std::string path, const std::vector< char > &data)