General information:Author: klaasje Version: 1.0 Date: Wed Oct 20 9:03:04 MET 1999 |
Header files:
|
Code files:
|
class for iterator on DL_List
template iterator for any list/node type
This class is the base class to attach/instantiate an iterator on a double linked list.
DL_List The iterator is used to traverse and perform functions on the nodes of a list.
More then 1 iterator can be attached to a list. The list keeps track of the number of iterators that are attached to it.
Depending on this certain operations are allowed are not. For instance a node can only be deleted if there is only one iterator attached to the list.
class
Dtype
Object for traversing a DL_List of the same Dtype
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: NONE |
Declaration:
DL_Iter(DL_List<Dtype>* newlist)
Parameters:
newlist : list for the iterator
Description:
Construct an iterator object for a given list of type Dtype
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: NONE |
Declaration:
DL_Iter(DL_Iter* otheriter)
Parameters:
otheriter : other iterator on same list
Description:
Constructor of iterator for the same list as another iterator
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: NONE |
Declaration:
DL_Iter()
Description:
Constructor without an attached list
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: NONE |
Declaration:
~DL_Iter()
Description:
destructor
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void Error(char* function,Lerror a_error)
Parameters:
function : function string that generated this error
a_error : error code to generate a message for
Description:
Report off Iterator ErrorsError report for list error inside DL_Iter classthe error function is used internally in the iterator class to report errors,the function will generate a message based on the error code.Then an exception will be generated using the global _messagehandler class instance.
Example:
to call error from inside an DL_List class
Error&&BRAKO&"Dremove_all&"D,ITER_GT_O&&BRAKC&&SEMI
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void Attach(DL_List<Dtype>* newlist)
Parameters:
newlist : the list to attached the iterator to
Description:
This attaches an iterator to a list of a given type, the list must exist.This way an iterator to a specific list can be madestatic to a class, and can be used for several lists at the same time.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void Detach()
Description:
This detaches an iterator from a list of a given type, the list must exist.This way an iterator to a specific list can be made static to a class,and can be used for several lists at the same time.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void foreach_f(void &&BRAKO*fp&&BRAKC &&BRAKODtype n&&BRAKC )
Description:
execute given function for each item in the list/iterator
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void insend(Dtype n)
Description:
list mutationsinsert after tail item
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void insbegin(Dtype n)
Description:
insert before head item
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void insbefore(Dtype n)
Description:
insert before current iterator position
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void insafter(Dtype n)
Description:
insert after current iterator position
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void takeover(DL_List<Dtype>* otherlist)
Parameters:
otherlist : the list to take the items from
Description:
to move all objects in a list to the list of the iterator.
Comments:
The iterator level must be one to be able to use this function, else an error will be generated
The list may not be the same list as the iterator list
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void takeover(DL_Iter* otheriter)
Parameters:
otheriter : the iterator to take the items from
Description:
to move all objects in a list (using iterator of that list) to the list of the iterator.
Comments:
The iterator level for both iterators must be one to be able to use this function, else an error will be generated
The list may not be the same list as the iterator list
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void takeover(DL_Iter* otheriter, int maxcount)
Parameters:
otheriter : the iterator to take the items from
maxcount : maximum number of objects to take over
Description:
to move maxcount objects in a list (using iterator of that list) to the list of the iterator.
Comments:
The iterator level for both iterators must be one to be able to use this function, else an error will be generated
The list may not be the same list as the iterator list
If less then maxcount objects are available in the source iterator, all of them are taken and no error will accur.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void remove()
Description:
remove object at current iterator position from the list.
Comments:
The object itself is not deleted, only removed from the list. The user is responsible for memory management.
The iterator level must be one to be able to use this function, else an error will be generated
The list must contain an object at the current iterator position, else an error will be generated.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void removehead()
Description:
Remove head item
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void removetail()
Description:
Remove tail item
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void remove_all()
Description:
Remove all items
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL empty()
Description:
is list empty (contains items or not)?
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL hitroot()
Description:
is iterator at root node (begin or end)?
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL athead()
Description:
is iterator at head/first node?
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL attail()
Description:
is iterator at tail/last node?
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL has(Dtype otheritem)
Parameters:
otheritem : item to search for
Description:
is given item member of the list
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: int |
Declaration:
int count()
Return value:
number of objects stored in the list.
Description:
Number of items in the list
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void totail()
Description:
go to last item, if list is empty goto hite
Comments:
If there are no elements in the list, the position will be set to the root object.
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void tohead()
Description:
go to first item, if list is empty goto hite
Comments:
If there are no elements in the list, the position will be set to the root object.
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void toroot()
Description:
set the iterator position to the root (empty dummy) object in the list.
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void operator++(void)
Description:
set the iterator position to next object in the list ( can be the root also).
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void operator++(int)
Description:
set iterator to next item (pre fix)
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void operator--(void)
Description:
set the iterator position to previous object in the list ( can be the root also)(postfix).
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void operator--(int)
Description:
set the iterator position to previous object in the list ( can be the root also)(pre fix).
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void operator>>(int)
Description:
set the iterator position n objects in the next direction ( can be the root also).
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void operator<<(int)
Description:
set the iterator position n objects in the previous direction ( can be the root also).
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void next_wrap()
Description:
set the iterator position to next object in the list, if this would be the root object,then set the iterator at the head object
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void prev_wrap()
Description:
set the iterator position to previous object in the list, if this would be the root object,then set the iterator at the tail object
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void reset_tail()
Description:
move root in order to make the current node the tailput the iterator root object after the current iterator position in the list.The current object will become the new tail of the list.
Comments:
The iterator level must be one to be able to use this function, else an error will be generated
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void reset_head()
Description:
move root in order to make the current node the headput the iterator root object before the current iterator position in the list.The current object will become the new head of the list.
Comments:
The iterator level must be one to be able to use this function, else an error will be generated
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL toitem(Dtype)
Description:
put the iterator at the position of the given object in the list.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void toiter(DL_Iter* otheriter)
Parameters:
otheriter : other iterator to let this iterator point to
Description:
put the iterator at the same position as the given iterator in the list.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL tonode(DL_Node<Dtype>*)
Return value:
returns true if the node was in the list, else false
Description:
put the iterator at the position of the given node in the list.
Comments:
DO NOT use this function. Normally you will not be able to address the nodes in a list.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: G_BOOL |
Declaration:
G_BOOL iterate(void)
Return value:
returns True if not at the end/root of the list else False.
Description:
iterate through all items of the listadvance the iterator one position in the next direction in the list.
Comments:
This function combines iteration and testing for the end of the list in one.
Therefore we do not have to advance the iterator ourselves.
The iterator is first put to the next object, before testing for the end of the list.
This is why we need to start at the root element in general usage.
scope: public | purpose: normal | inline?: yes | function property: standard | type: basic | typename: Dtype |
Declaration:
Dtype item()
Return value:
returns the object where the iterator is pointing to at the moment.
Description:
To get the item at the current iterator position
Comments:
If the iterator is at the root of the list an error will be generated, since there is no item there.
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void mergesort(int &&BRAKO*fcmp&&BRAKC &&BRAKODtype, Dtype&&BRAKC)
Description:
sort list with mergesort
scope: public | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void cocktailsort(int &&BRAKO*&&BRAKC&&BRAKODtype,Dtype&&BRAKC, void &&BRAKO*&&BRAKC&&BRAKODtype,Dtype&&BRAKC=NULL)
Description:
sort list with cocktailsort
scope: protected | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void mergesort_rec(int &&BRAKO*fcmp&&BRAKC&&BRAKODtype,Dtype&&BRAKC, DL_Node<Dtype> *RT1,int n)
Description:
sort list with mergesort
scope: protected | purpose: normal | inline?: no | function property: standard | type: basic | typename: void |
Declaration:
void mergetwo(int &&BRAKO*fcmp&&BRAKC&&BRAKODtype,Dtype&&BRAKC, DL_Node<Dtype> *RT1,DL_Node<Dtype> *RT2)
Description:
sort list with mergesort
scope: protected | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void next()
Description:
set the iterator position to next object in the list ( can be the root also).
Comments:
Use this function inside a new class derived from DL_Iter.
scope: protected | purpose: normal | inline?: yes | function property: standard | type: basic | typename: void |
Declaration:
void prev()
Description:
set the iterator position to previous object in the list ( can be the root also).
Comments:
Use this function inside a new class derived from DL_Iter.
scope: protected | type: basic | typename: DL_List<Dtype> * |
Declaration:
DL_List<Dtype> *_list
Description:
the list for this iterator
scope: protected | type: basic | typename: DL_Node<Dtype> * |
Declaration:
DL_Node<Dtype> *_current
Description:
the current position of the iterator
to insert integer a and b into list and remove_all directly using an iterator
DL_List<int>* a_list = new DL_List<int>(); // declaration and allocation int a=123; int b=345; { DL_Iter<int>* a_listiter=new DL_Iter<int>(a_list); a_listiter->insbegin(a) a_listiter->insbegin(b) a_listiter->remove_all() } //to destruct the iterator before the list is deleted delete a_list; #delete it (must have no iterators attached to it)