VIPER REFERENCE MANUAL


NAME
iflMultiList - simple doubly-linked list template class

HEADER FILE
#include <ifl/iflList.h>

PUBLIC METHOD SUMMARY

   Constructor
template<class itemType, class linkageType> iflMultiList (  );

   Editing
void append ( linkageType* item);
void appendList ( iflMultiList* list);
void appendSubList ( linkageType* bgn, linkageType* end);
void clear (  );
void insert ( linkageType* item);
void insertList ( iflMultiList* list);
void insertAfter ( linkageType* item, linkageType* before);
void insertBefore ( linkageType* item, linkageType* after);
void insertSubList ( linkageType* bgn, linkageType* end);
void unlink ( linkageType* item);

   Query
int isEmpty (  ) const;
itemType* head (  ) const;
itemType* tail (  ) const;
itemType* getNext ( const linkageType* item) const;
itemType* getPrev ( const linkageType* item) const;

PUBLIC MEMBER SUMMARY
iflListItem hd;

CLASS DESCRIPTION
The iflMutliList template class provides a lightweight, fast, doubly-linked list template. The derived template class iflList is identical with the restriction that the items in the list must have only one iflListItem base class (i.e. they can only be on one list at a time.

   Using iflMutliList and iflList
Derive from iflListItem to place objects of the derived type in a doubly-linked list (iflList<derivedType>); for example to define a list element that can hold an x,y int pair you would write:
    class XY : public iflListItem {
    public:
        XY(int X, int Y) { x = X; y = Y; }
        int x, y;
    };
You could then use it with code like:
    XY foo(3,4);
    iflList<XY> list;
    list.append(&foo);
    ...
    iflListIter<XY> iter(list);
    XY* item;
    while (item = iter.next()) item->unlink();
If you need to place an object in two lists simultaneously you would write something like:
    class A : public iflListItem {};
    class B : public iflListItem {};

    class XY : public A, public B {
    public:
        XY(int X, int Y) { x = X; y = Y; }
        int x, y;
    };
and to operate on the "A" list of the XY elements:
    XY foo(3,4);
    iflMutliList<XY,A> list;
    list.append(&foo);
    ...
    iflMultiListIter<XY,A> iter(list);
    XY* xy;
    while (item = iter.next()) item->unlink();

METHOD DESCRIPTIONS

   iflMultiList()
template<class itemType, class linkageType> iflMultiList (  );

Creates an iflMultiList of length zero (that is, an empty list). The items will be of type itemType. Access to the next and prev pointers will be done through casts to type linkageType. This template class is useful when used with items that will be placed on more than one type of list.

For cases where the items will be placed on only one list, use the derived template class iflList. The iflList constructor is identical except only the itemType is supplied as a template argument, the linkageType is automatically filled in as iflListItem. It is declared as:
    template<class itemType> iflList();

   append()
void append ( linkageType* item);

Appends item to the end of the list.

   appendList()
void appendList ( iflMultiList* list);

Removes all of the items from list and appends them to the end of this list (in the same order that they were on the original list).

   appendSubList()
void appendSubList ( linkageType* bgn, linkageType* end);

Removes all of the items between bgn and end, inclusive, from whatever list they are on and appends them to the end of this list (in the same order that they were on the original list).

   clear()
void clear (  );

Clears the list of all items. This is not usually a good idea, but is sometimes necessary to avoid an assertion failure on destruction.

   getNext()
itemType* getNext ( const linkageType* item) const;

Returns the item immediately following item or NULL if item is at the end of the list.

   getPrev()
itemType* getPrev ( const linkageType* item) const;

Returns the item immediately preceding item or NULL if item is at the beginning of the list.

   head()
itemType* head (  ) const;

Returns the item at the head of the list or NULL if the list is empty.

   insert()
void insert ( linkageType* item);

Inserts item at the front of the list.

   insertAfter()
void insertAfter ( linkageType* item, linkageType* before);

Inserts item immediately following the item indicated by before.

   insertBefore()
void insertBefore ( linkageType* item, linkageType* after);

Inserts item immediately preceding the item indicated by after.

   insertList()
void insertList ( iflMultiList* list);

Removes all of the items from list and prepends them to the front of this list (in the same order that they were on the original list).

   insertSubList()
void insertSubList ( linkageType* bgn, linkageType* end);

Removes all of the items between bgn and end, inclusive, from whatever list they are on and prepends them to the front of this list (in the same order that they were on the original list).

   isEmpty()
int isEmpty (  ) const;

Returns TRUE if the list is empty, FALSE otherwise.

   tail()
itemType* tail (  ) const;

Returns the item at the tail of the list or NULL if the list is empty.

   unlink()
void unlink ( linkageType* item);

Unlinks the item from the list. If item is not on the list, the result is undefined.

MEMBER DESCRIPTIONS

   hd
iflListItem hd;

The head of the list. This member should be be accessed directly. This member should not be accessed directly (it's public because we can't figure out how to make it private and still compile).

SEE ALSO
iflMultiListIter, iflMultiListIterRev