39 #if defined(NPT_CONFIG_HAVE_NEW_H)
100 template <
typename X,
typename P>
105 if (predicate(
function(
m_Items[i]), return_value)) {
106 if (match) *match =
true;
110 if (match) *match =
false;
114 template <
typename X>
122 if (n == 0)
return &
m_Items[i];
142 template <
typename T>
155 template <
typename T>
172 template <
typename T>
188 template <
typename T>
192 m_ItemCount(item_count),
197 new ((
void*)&
m_Items[i])
T(items[i]);
204 template <
typename T>
212 ::operator
delete((
void*)m_Items);
218 template <
typename T>
223 if (
this == ©)
return *
this;
232 new ((
void*)&m_Items[i])
T(copy.
m_Items[i]);
241 template <
typename T>
258 template <
typename T>
263 allocated = 2*m_Capacity;
268 if (allocated == 0) allocated = 1;
270 if (allocated < count) allocated = count;
273 return (
T*)::operator
new(allocated*
sizeof(
T));
279 template <
typename T>
287 T* new_items = Allocate(count, new_capacity);
288 if (new_items ==
NULL) {
291 if (m_ItemCount && m_Items) {
292 for (
unsigned int i=0; i<m_ItemCount; i++) {
294 new ((
void*)&new_items[i])
T(m_Items[i]);
300 ::operator
delete((
void*)m_Items);
302 m_Capacity = new_capacity;
310 template <
typename T>
320 new ((
void*)&m_Items[m_ItemCount++])
T(item);
328 template <
typename T>
333 return Erase(which, which);
339 template <
typename T>
349 if (first_index >= m_ItemCount ||
350 last_index >= m_ItemCount ||
351 first_index > last_index) {
358 for (
NPT_Ordinal i=first_index; i<first_index+shifted; i++) {
359 m_Items[i] = m_Items[i+interval];
363 for (
NPT_Ordinal i=first_index+shifted; i<m_ItemCount; i++) {
368 m_ItemCount -= interval;
376 template <
typename T>
385 if (needed > m_Capacity) {
388 T* new_items = Allocate(needed, new_capacity);
390 m_Capacity = new_capacity;
394 new((
void*)&new_items[i])
T(m_Items[i]);
399 for (
NPT_Ordinal i=where_index; i<m_ItemCount; i++) {
400 new((
void*)&new_items[i+repeat])
T(m_Items[i]);
405 ::operator
delete((
void*)m_Items);
409 for (
NPT_Ordinal i=m_ItemCount; i>where_index; i--) {
410 new((
void*)&m_Items[i+repeat-1])
T(m_Items[i-1]);
416 for (
NPT_Cardinal i=where_index; i<where_index+repeat; i++) {
417 new((
void*)&m_Items[i])
T(item);
421 m_ItemCount += repeat;
429 template <
typename T>
433 if (size < m_ItemCount) {
439 }
else if (size > m_ItemCount) {
440 return Resize(size,
T());
449 template <
typename T>
453 if (size < m_ItemCount) {
455 }
else if (size > m_ItemCount) {
458 new ((
void*)&m_Items[i])
T(fill);
469 template <
typename T>
474 if (m_Items[i] == data)
return true;
483 template <
typename T>
488 if (other.
m_ItemCount != m_ItemCount)
return false;
492 if (!(m_Items[i] == other.
m_Items[i]))
return false;
501 template <
typename T>
506 return !(*
this == other);
509 #endif // _NPT_ARRAY_H_
NPT_Result Insert(Iterator where, const T &item, NPT_Cardinal count=1)
#define NPT_SUCCESS
Result indicating that the operation or call succeeded.
NPT_Result Add(const T &item)
Iterator GetLastItem() const
NPT_Cardinal GetCapacity() const
NPT_Result Erase(NPT_Ordinal first, NPT_Ordinal last)
NPT_Cardinal GetItemCount() const
Iterator GetFirstItem() const
bool Contains(const T &data) const
T * Find(const X &predicate, NPT_Ordinal n=0, NPT_Ordinal *pos=NULL) const
#define NPT_ERROR_OUT_OF_MEMORY
#define NPT_ERROR_INVALID_PARAMETERS
bool operator!=(const NPT_Array< T > &other) const
NPT_Result Erase(NPT_Ordinal which)
const int NPT_ARRAY_INITIAL_MAX_SIZE
Iterator GetItem(NPT_Ordinal n)
NPT_Array< T > & operator=(const NPT_Array< T > ©)
NPT_Result Resize(NPT_Cardinal count)
bool operator==(const NPT_Array< T > &other) const
const T & operator[](NPT_Ordinal pos) const
NPT_Result ApplyUntil(const X &function, const P &predicate, bool *match=NULL) const
NPT_Result Apply(const X &function) const
#define NPT_POINTER_TO_LONG(_p)
NPT_Result Erase(Iterator which)
T * Allocate(NPT_Cardinal count, NPT_Cardinal &allocated)
NPT_Result Reserve(NPT_Cardinal count)
unsigned int NPT_Cardinal
T & operator[](NPT_Ordinal pos)