GPL_DoubleList

GPL_DoubleList

gpl

1998 12-05


CLASS

GPL_DoubleList - C++ non-intrusive doubly linked list template


SYNOPSIS

GPL_DoubleList<data_type> idlist();
GPL_IDoubleList<data_type> idlist();


Class GPL_DoubleList is a non-intrusive doubly linked list. It is non-intrusive in that objects added to the list do not need to have the data members necessary for linked list operations (such as pointers to the next and previous objects in the list). Internally an object with these data members is created that points to the object of type data_type that is to be added. This newly created object is then added to the list.


Since the objects are merely pointed to by the list infrastructure, an object may be in more than one list at a particular time. This is not possible with the intrusive linked list GPL_IDoubleList.


Class GPL_IDoubleList is an intrusive doubly linked list. It is intrusive in that the objects in the list must have the data members necessary for the linked list operations (such as pointers to the next and previous objects in the list). Therefore, data_type must be derived from class GPL_DoubleNode which provides the needed data members.


Since the required data members are embedded in the objects, a single object may be part of only one list at a time. If this is not acceptable see GPL_DoubleList which is a non-intrusive linked list. However, GPL_IDoubleList is more efficient than GPL_DoubleList.


The list has the concept of a current object pointer. In most cases, the member functions ToHead() and PostIncrement() are used to set this pointer to the first object in the list and then go through the list an object by object.


CONSTRUCTOR


MEMBER FUNCTIONS


CONVENIENCE MEMBER FUNCTIONS


OUTDATED MEMBER FUNCTIONS


NOTES

There are some caveats with the non-intrusive list. When a node in an intrusive list is deleted, the destructor will automatically remove it from the list. However, this cannot happen with the non-intrusive list because there is no way to connect functionality with the destruction of a non-intruded object (there is no imformation embedded in the object itself).


Also, for the non-intrusive list, an insertion function will not fail if the object is already in the list. It will simply be added to the list again. This means that with a non-intrusive list it is possible for an object to be in the same list more than once. The function RemoveNode() will remove the first instance (pointer) to the object in the list. This means that if an object is in the list more than once, is then removed once and the actual object deleted, the list will effectively be corrupt because the remaining pointers will be to a non-existant object.