33 #ifndef __H__UG__pointer_array_impl__
34 #define __H__UG__pointer_array_impl__
45 m_array(NULL), m_data(NULL), m_size(0), m_capacity(0)
53 assign_pointer_const_array(pa);
74 assign_pointer_const_array(pa);
95 m_data =
new TPtr[m_size];
96 memcpy(m_data, pa.
m_data,
sizeof(TPtr) * m_size);
104 template <
class TPtr>
111 template <
class TPtr>
118 template <
class TPtr>
126 template <
class TPtr>
132 if(size > m_capacity){
134 m_data =
new TPtr[size];
139 memcpy(m_data, array,
sizeof(TPtr) * size);
150 template <
class TPtr>
155 reserve(capacity, m_array == m_data);
158 template <
class TPtr>
160 reserve(
size_t capacity,
bool copyOldData)
162 if(capacity > m_capacity){
163 PtrArray newData =
new TPtr[capacity];
165 if(m_data && copyOldData)
166 memcpy(newData, m_data,
sizeof(TPtr) * m_capacity);
168 m_capacity = capacity;
172 if(m_array == m_data)
180 template <
class TPtr>
187 template <
class TPtr>
193 if(m_array != m_data){
195 reserve(max<size_t>(1, m_size * 2),
false);
197 memcpy(m_data, m_array,
sizeof(TPtr) * m_size);
202 if(m_size >= m_capacity)
203 reserve(max<size_t>(1, m_capacity * 2),
true);
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
void set_external_array(TPtr const *array, size_t size, bool bCopy=false)
set the array on which the container operates.
Definition: pointer_const_array_impl.hpp:128
void clear()
clears the container
Definition: pointer_const_array_impl.hpp:182
PointerConstArray & operator=(const PointerConstArray &pa)
Definition: pointer_const_array_impl.hpp:67
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
void reserve(size_t capacity)
reserves memory but does not alter the size
Definition: pointer_const_array_impl.hpp:152
void push_back(TPtr p)
appends the given pointer at the end of the array.
Definition: pointer_const_array_impl.hpp:189
PtrArray m_data
Definition: pointer_const_array.h:141
TPtr * PtrArray
Definition: pointer_const_array.h:86
TPtr const operator[](size_t i) const
returns the i-th entry of the array. Make sure that i < size().
Definition: pointer_const_array_impl.hpp:120
PointerConstArray()
Definition: pointer_const_array_impl.hpp:44
bool empty() const
returns true if the associated array is empty
Definition: pointer_const_array_impl.hpp:113
void assign_pointer_const_array(const PointerConstArray &pa)
copies contents from the given PointerConstArray
Definition: pointer_const_array_impl.hpp:82
ConstPtrArray m_array
Definition: pointer_const_array.h:140
size_t m_size
Definition: pointer_const_array.h:142
~PointerConstArray()
Definition: pointer_const_array_impl.hpp:58
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
Definition: smart_pointer.h:814