uLib  User mode C/C++ extended API library for Win32 programmers.
uLib::DynArray Class Reference

#include <uLib/DynArray.h>

Inheritance diagram for uLib::DynArray:
uLib::SortDynArray

Detailed Description

Simple dynamic array (storing void*) to contain whatever..

The base method DeleteItem uses mem_Free() to dispose of the item data, so
if you use mem_Alloc() for your items, you don't need a descendant DynArray.

Definition at line 51 of file DynArray.h.

Public Data

DWORD const & Count
 
DWORD const & Size
 
DynArray const & Items
 

Public Functions

 DynArray (DWORD Size=16, WORD Delta=16)
 
virtual ~DynArray ()
 
void Init (DWORD Size, WORD Delta)
 
void Done ()
 
PVOID operator+= (PVOID Item)
 
PVOID operator -= (PVOID Item)
 
PVOID Insert (PVOID Item)
 
PVOID InsertAt (DWORD Index, PVOID Item)
 
PVOID Push (PVOID Item)
 
PVOID Pull (void)
 
PVOID Pop (void)
 
virtual void DeleteItem (PVOID &Item)
 
virtual void DeleteAll (void)
 
void Delete (PVOID &Item)
 < More...
 
void Delete (DWORD Index)
 
PVOID Remove (PVOID Item)
 
PVOID Remove (DWORD Index)
 
LONG IndexOf (PVOID Item) const
 
PVOID At (DWORD Index) const
 
PVOID FirstThat (DYN_ITEMFUNC Match, PVOID userData) const
 
PVOID LastThat (DYN_ITEMFUNC Match, PVOID userData) const
 
bool ForEach (DYN_ITEMFUNC Action, PVOID userData) const
 
PVOID operator[] (DWORD Index) const
 

Constructor & Destructor Documentation

◆ DynArray()

uLib::DynArray::DynArray ( DWORD  Size = 16,
WORD  Delta = 16 
)
Parameters
SizeInitial size of array.
DeltaNr of slots to add when array fills up.

Definition at line 34 of file DynArray.cpp.

◆ ~DynArray()

uLib::DynArray::~DynArray ( )
virtual

The destructor calls DeleteAll, which invokes DeleteItem on each item.

Definition at line 46 of file DynArray.cpp.

Member Function Documentation

◆ Init()

void uLib::DynArray::Init ( DWORD  Size,
WORD  Delta 
)

Used by c'tor

Definition at line 51 of file DynArray.cpp.

◆ Done()

void uLib::DynArray::Done ( )

Used by d'tor

Definition at line 66 of file DynArray.cpp.

◆ operator+=()

PVOID uLib::DynArray::operator+= ( PVOID  Item)
inline

Add Item to the array.

Definition at line 68 of file DynArray.h.

◆ operator -=()

PVOID uLib::DynArray::operator -= ( PVOID  Item)
inline

Remove Item from the array.

Definition at line 69 of file DynArray.h.

◆ Insert()

PVOID uLib::DynArray::Insert ( PVOID  Item)

Appends Item to the collection. Override: if needed.

Parameters
ItemItem to add to array.
Returns
On success return Item, else return NULL.

Definition at line 72 of file DynArray.cpp.

◆ InsertAt()

PVOID uLib::DynArray::InsertAt ( DWORD  Index,
PVOID  Item 
)

Inserts Item at the specified index. Existing items are moved.
If Index is beyond the end of collection InsertAt() equals Insert().

Parameters
IndexIndex where to insert item. Zero based.
ItemPointer to item.
Returns
On success return Item, else return NULL.

Definition at line 105 of file DynArray.cpp.

◆ Push()

PVOID uLib::DynArray::Push ( PVOID  Item)

Push(), Pull(), and Pop(), enables the DynArray to be used as a stack or que.
Push() / Pull() acts as a queue (FIFO), and Push() / Pop() acts as a stack (LIFO).
On failure they all return NULL, on success the item.

Insert Item into stack/queue.

Definition at line 121 of file DynArray.cpp.

◆ Pull()

PVOID uLib::DynArray::Pull ( void  )

Remove an iten. Push/Pull = FIFO (queue) action.

Definition at line 126 of file DynArray.cpp.

◆ Pop()

PVOID uLib::DynArray::Pop ( void  )

Remove an iten. Push/Pop = LIFO (stack) action.

Definition at line 131 of file DynArray.cpp.

◆ DeleteItem()

void uLib::DynArray::DeleteItem ( PVOID &  Item)
virtual

DeleteItem() should destroy Item, and set the ptr to NULL.
You must override this if your items are allocated any other way than mem_Alloc().
See also ~DynArray().

Definition at line 136 of file DynArray.cpp.

◆ DeleteAll()

void uLib::DynArray::DeleteAll ( void  )
virtual

Definition at line 155 of file DynArray.cpp.

◆ Delete() [1/2]

void uLib::DynArray::Delete ( PVOID &  Item)

<

DeleteAll() deletes all items in the collection.

Parameters
ItemPointer to item to delete.

Definition at line 142 of file DynArray.cpp.

◆ Delete() [2/2]

void uLib::DynArray::Delete ( DWORD  Index)

Delete() deletes the item and removes it from collection.

Parameters
IndexIndex of item to delete.

Definition at line 148 of file DynArray.cpp.

◆ Remove() [1/2]

PVOID uLib::DynArray::Remove ( PVOID  Item)
Parameters
ItemPointer to item to remove.

Definition at line 160 of file DynArray.cpp.

◆ Remove() [2/2]

PVOID uLib::DynArray::Remove ( DWORD  Index)

Remove() removes the item without deleting it.

Parameters
IndexIndex of item to remove.
Returns
Returns the pointer to the item (for your processing), or NULL.

Definition at line 166 of file DynArray.cpp.

◆ IndexOf()

LONG uLib::DynArray::IndexOf ( PVOID  Item) const

IndexOf() returns the index of Item if it exists, else it returns -1.

Definition at line 177 of file DynArray.cpp.

◆ At()

PVOID uLib::DynArray::At ( DWORD  Index) const

At() retrieves the item at Index.

Definition at line 185 of file DynArray.cpp.

◆ FirstThat()

PVOID uLib::DynArray::FirstThat ( DYN_ITEMFUNC  Match,
PVOID  userData 
) const

Returns the first item in the collection that matches userData,
according to the supplied Match function.

Parameters
MatchCallback function to compare items.
userDataArbitrary data to pass to the comparison funtion.
Returns
If no item matches, it returns NULL.

Definition at line 191 of file DynArray.cpp.

◆ LastThat()

PVOID uLib::DynArray::LastThat ( DYN_ITEMFUNC  Match,
PVOID  userData 
) const

LastThat() works like FirstThat(), exept that it finds the last item.

Definition at line 199 of file DynArray.cpp.

◆ ForEach()

bool uLib::DynArray::ForEach ( DYN_ITEMFUNC  Action,
PVOID  userData 
) const

Calls the supplied Action function for each item in the collection,
or until the Action callback returns false.

Parameters
ActionCallback function to process items.
userDataArbitrary data to pass to the action funtion.
Returns
Returns false if an Action returned false, else true.

Definition at line 207 of file DynArray.cpp.

◆ operator[]()

PVOID uLib::DynArray::operator[] ( DWORD  Index) const
inline

Provide subscript access to the array's items.

Definition at line 133 of file DynArray.h.

Member Data Documentation

◆ Count

DWORD const& uLib::DynArray::Count

Nr of items in collection (ReadOnly)

Definition at line 53 of file DynArray.h.

◆ Size

DWORD const& uLib::DynArray::Size

Allocated pointer array length (ReadOnly)

Definition at line 54 of file DynArray.h.

◆ Items

DynArray const& uLib::DynArray::Items

Self-reference for subscript access through pointer.
Example: MyArrayPtr->Items[ index ];

Definition at line 55 of file DynArray.h.


The documentation for this class was generated from the following files: