Whenever a list class derived from ACObjectList is needed, you should copy this file and follow the steps listed in the header to obtain a working list class. Whereas ACObjectList leaves open the sort key (just uses a void pointer) and the type of the object that is to be stored, the derived list class is type-safe. The template has been tested and can be considered to be error-free. So all list classes obtained by following the instructions in the header can be assumed to be correct as well. Only if you change something or add own functions, these must be tested separately. The template uses a structure SKey to store the keys. SKey should always contain copies of the keys used in the function parameters.
All files ending in "temp" will most likely contain such list classes.
global items used:
member types:
struct
SKey: contains the keys.
member functions:
CTemplate
(INT32 aSize = ArrayAllocationSize): Makes a new list.
virtual
~CTemplate (): Deletes all objects in the list by calling DeleteAll().
virtual
int Compare (void* key1, void *key2) const: Here, you should cast
the two key pointers to the type of your key and then compare the two keys.
Return -1 if key1 is less than key2, 0 if the keys are
equal and +1 if key1 is greater than key2.
EBool
Delete (FUNCTION_ARGUMENT_LIST): If the object with the given key(s)
is found, it is deleted and True is returned. If it is not found, the function
returns False.
EBool
DeleteAll (): Deletes all entries in the list. The function returns
True if at least one object was deleted, False if the list was empty.
virtual
void DeleteKey (void *key): Casts key to the type of your
key (to SKey) and then deletes it.
T*
Find (FUNCTION_ARGUMENT_LIST): Returns the object with the key(s)
given in the argument list or NULL if no such object was found.
T*
GetCurrentObject (): Returns a pointer to the object that has been
accessed last, or NULL if no object has been accessed or if this information
is not available anymore.
EBool
GetCurrentObjectKey (FCT_ARGUMENT_LIST_REFERENCES): If no object has
been accessed or if this information is not available anymore, the function
returns False. Otherwise, the key(s) of the object accessed last are copied
into the function arguments.
T*
GetFirst (): Returns the first object in the list or NULL if no object
is stored.
T*
GetLast (): Returns the last object in the list or NULL if no object
is stored.
T*
GetNext (): Returns the next object in the list (as seen from the
previously accessed object) or NULL if the end of the list has been reached
or if no object is stored.
T*
GetPrev (): Returns the previous object in the list (as seen from
the previously accessed object) or NULL if the beginning of the list has
been reached or if no object is stored.
EBool
Insert (T* object, FUNCTION_ARGUMENT_LIST): If there is no entry with
the key(s), the object is stored with this key(s) and True is returned.
If an object with this key(s) already exists, False is returned and the
object is not stored.
T*
Remove (FUNCTION_ARGUMENT_LIST): If an object with the given key(s)
is found, it is removed from the list and the pointer to it is returned.
Else NULL is returned.