17 void* DynArray::__alloc(
size_t Bytes ) {
21 void* DynArray::__realloc(
void* pBlk,
size_t Bytes ) {
26 void* DynArray::__free(
void* pBlk ) {
31 #pragma warning( disable: 4355 ) // 'this' in base member initializer list 35 : Count(_count), Size(_size), Items(*this)
39 Init( dwSize, wDelta );
43 #pragma warning( default: 4355 ) 54 dwSize = dwSize ?
ROUND_UP( dwSize, wDelta ) : wDelta;
58 #if USE_DYNARRAY_LIMIT 59 _size = (dwSize <= MAX_DYNITEM) ? dwSize : MAX_DYNITEM;
63 _items = _size ? (PVOID*)__alloc( _size*
sizeof(PVOID) ) : NULL;
69 if (_items) _items = (PVOID*)__free( _items );
74 #if USE_DYNARRAY_LIMIT 75 if( Item == NULL || _count == MAX_DYNITEM )
85 #if USE_DYNARRAY_LIMIT 86 if (_size > MAX_DYNITEM) _size = MAX_DYNITEM;
88 size_t nbytes = _size*
sizeof(PVOID);
89 tmp = _items ? __realloc( _items,nbytes ) : __alloc( nbytes );
91 _items = (PVOID*) tmp;
99 _items[_count-1] = Item;
110 if ((Index >= (_count-1)) || (!p))
115 size_t nbytes = (_count-Index-1)*
sizeof(PVOID);
116 memmove( &_items[Index+1], &_items[Index], nbytes );
133 return Remove( _count-1 );
145 if (index >= 0)
Delete( index );
150 if (Index >= _count)
return;
157 while( _count )
Delete( _count-1 );
163 return (index >= 0) ?
Remove( index ) : NULL;
168 if (Index >= _count)
return NULL;
169 PVOID item =
At( Index );
171 DWORD bytes = (_count-Index)*
sizeof(PVOID);
172 if (bytes) memmove( &_items[Index], &_items[Index+1], bytes );
173 _items[_count] = NULL;
180 for(
DWORD i=0; i<_count; i++ )
181 if (_items[i] == Item)
return LONG( i );
187 if (Index >= _count)
return NULL;
188 return _items[Index];
193 for(
DWORD i=0; i<_count; i++ )
194 if (Match( _items[i],userData ))
201 for(
DWORD i=_count; i>0; i-- )
202 if (Match( _items[i-1],userData ))
209 for(
DWORD i=0; i<_count; i++ )
210 if( !Action( _items[i],userData ))
231 if (!Item1)
return 1;
else if (!Item2)
return -1;
232 return _tcscmp( (
TSTR)Item1, (
TSTR)Item2 );
239 for( Index=0; Index < _count; Index++ ) {
240 PVOID itemKey = _items[ Index ];
241 if (itemKey) itemKey =
KeyOf( itemKey );
243 int cmp =
Compare( itemKey, Key );
244 if (cmp == 0)
return true;
245 else if (cmp > 0)
return false;
253 if (!Item)
return NULL;
void * mem_Realloc(void *pBlk, size_t Bytes)
void * mem_Alloc(size_t Bytes)
virtual void DeleteAll(void)
#define END_NAMESPACE(name)
bool(CALLBACK * DYN_ITEMFUNC)(PVOID Item, PVOID UserData)
void Init(DWORD Size, WORD Delta)
void Delete(PVOID &Item)
<
PVOID InsertAt(DWORD Index, PVOID Item)
void * mem_Free(void *pBlk)
PVOID FirstThat(DYN_ITEMFUNC Match, PVOID userData) const
PVOID At(DWORD Index) const
#define ROUND_UP(x, chunk)
virtual short Compare(PVOID Key1, PVOID Key2)
virtual void DeleteItem(PVOID &Item)
LONG IndexOf(PVOID Item) const
SortDynArray(DWORD Size=16, WORD Delta=16)
virtual PVOID KeyOf(PVOID Item)
#define BEGIN_NAMESPACE(name)
bool ForEach(DYN_ITEMFUNC Action, PVOID userData) const
PVOID LastThat(DYN_ITEMFUNC Match, PVOID userData) const
bool Search(PVOID Key, DWORD &Index)