class representing the list header in a linked list system More...
#include <list2d.h>
Public Member Functions | |
List2Dh () | |
constructor; | |
virtual | ~List2Dh () |
destructor; will free resources; | |
void | erase (void) |
remove all items from this list by deleting them More... | |
void | setFirst (List2De *pNew) |
set first item | |
void | setCount (int iNew) |
set number of items | |
List2De * | first (void) const |
get first item | |
List2De * | last (void) const |
get last item | |
int | count (void) const |
get the number of items | |
bool | isEmpty (void) const |
the number of items is 0? | |
int | itemIndex (const List2De *pIt) const |
returns the index of a particular item inside this chain More... | |
bool | has (const List2De *pIt) const |
tell if an item is part of this chain | |
void | append (List2De *pIt) |
append an item (insert after last) More... | |
void | prepend (List2De *pIt) |
prepend an item (insert as first item) More... | |
void | insert (List2De *p_new, int index) |
insert a item at specified index More... | |
void | ackAdd (List2De *pNew) |
header is informed about an item being added More... | |
void | remove (int i) |
remove the item at given index More... | |
void | remove (List2De *pIt) |
remove a particular item More... | |
void | ackDel (List2De *pNew) |
header is informed about an item being deleted More... | |
void | dbgDump (void) const |
print the content of this object to debug output | |
bool | contains (const List2De *p_el) const |
tell if this list contains an entry | |
List2De * | item (int i) const |
List2De * | at (int i) const |
List2De * | operator[] (int i) const |
Stack | |
Stack related functionality | |
void | push (List2De *pIt) |
prepend an item (insert as first item) More... | |
void | pushBack (List2De *pIt) |
append an item (insert after last) More... | |
List2De * | pop (void) |
extract first item | |
List2De * | popBack (void) |
extract last item | |
Protected Attributes | |
List2De * | it_1 |
pointer to first element in list | |
int | iCnt |
number of items that belong to this chain | |
Friends | |
class | List2De |
class representing the list header in a linked list system
These lists are simple chains of objects. Each list must have:
The constructor for this class only initialises itself. No chain can be appended at the moment of creation. Destruction code makes use of the erase() function to destroy all child elements (it assumes that the elements were allocated using new() and deletes them using delete).
The erase() function is public and may be used at any time to clean the list and delete all items in it (freeing of memory included). Also, low level access to internal fields is allowed using setFirst() and setCount();
To get an item at a particular 0 based index use item(). First and last items in the chain may be found using first() and last().
To get the number of items that are hosted inside a chain use the count() function. To find out if the chain contains a particular pointer, feed it to the has() function, that returns true if the item was found. A similar function is itemIndex(), that returns the 0 based index of a pointer or -1 if it was not found.
Items may be append() -ed, prepend() -ed to the chain or insert() -ed at a given, 0 based, index. It should be noted that none of these functions check if the item is already part of a chain. If the item is part of another chain, the caller is required to extract the item before the call.
If the caller already inserted the items into the chain, ackAdd() function may be used to inform the header AFTER the insertion. The function will only update the counter and, if inserted item is first item, the pointer.
To extract an item from the chain WITHOUT deleting the item, remove() function is used. The caller may provide either the 0 based index or the pointer to the item to remove.
If the caller already removed the items from the chain, ackDel() function may be used to inform the header AFTER the removal. The function will only update the counter and, if the item is first item, the pointer. It is expected that the item has it's internal fields intact (pointer to next item is used to replace internal pointer).
|
inline |
header is informed about an item being added
If the caller already inserted the items into the chain, this function may be used to inform the header AFTER the insertion. The function will only update the counter and, if inserted item is first item, the pointer.
|
inline |
header is informed about an item being deleted
If the caller already removed the items from the chain, ackDel() function may be used to inform the header AFTER the removal. The function will only update the counter and, if the item is first item, the pointer. It is expected that the item has it's internal fields intact (pointer to next item is used to replace internal pointer).
void List2Dh::append | ( | List2De * | pIt | ) |
append an item (insert after last)
It should be noted that this function does not check if the item is already part of a chain. If the item is part of another chain, the caller is required to extract the item before the call.
|
inline |
get nth item
void List2Dh::erase | ( | void | ) |
remove all items from this list by deleting them
This function assumes that the List2De elements were allocated using new() and it deletes them using delete).
void List2Dh::insert | ( | List2De * | p_new, |
int | index | ||
) |
insert a item at specified index
It should be noted that this function does not check if the item is already part of a chain. If the item is part of another chain, the caller is required to extract the item before the call.
List2De * List2Dh::item | ( | int | i | ) | const |
get nth item
int List2Dh::itemIndex | ( | const List2De * | pIt | ) | const |
returns the index of a particular item inside this chain
The index is 0 based. If the pointer was not found inside the chain the function returns -1.
|
inline |
get nth item
void List2Dh::prepend | ( | List2De * | pIt | ) |
prepend an item (insert as first item)
It should be noted that this function does not check if the item is already part of a chain. If the item is part of another chain, the caller is required to extract the item before the call.
|
inline |
prepend an item (insert as first item)
It should be noted that this function does not check if the item is already part of a chain. If the item is part of another chain, the caller is required to extract the item before the call.
|
inline |
append an item (insert after last)
It should be noted that this function does not check if the item is already part of a chain. If the item is part of another chain, the caller is required to extract the item before the call.
void List2Dh::remove | ( | int | i | ) |
remove the item at given index
extract an item from the chain WITHOUT deleting the item
void List2Dh::remove | ( | List2De * | pIt | ) |
remove a particular item
extract an item from the chain WITHOUT deleting the item