ilist

The ilist is a template library modeled after the STL list. Instead of allocating a container for the elements, it uses base classes for the elements. This way much less alloc an free operations are needed, which saves a lot of cpu time and memory. Also when iterating thru the list one indirection less is needed. It uses the istd namespace.

File information

Filecommon/ilib/ilist.h

Classes list
listElement

class list members list
~list
front
empty
back
push_front
push_back
pop_front
pop_back
insertBefore
insertBehind
swap
sort

class listElement members listElement
~listElement
goNext
goPrev
remove
getList
compare
swap

Examples

Classes

list

template <class T> class list {
    ...
};

The list itself consisting of a head and tail pointer to a class T.

listElement

template <class T> class listElement {
    ...
};

Used as a base class for elements. This contains the forward and backward linking pointer and a pointer to the list itself.

class list members

list

list()

constructor, clears the list

~list

~list()

destructor, removes all elements from the list

front

const T * front()

returns front (head) of list.

empty

bool empty()

back

const T * back()

returns back (tail) of list.

push_front

void push_front(T * e)

Add an element to the front (head) of the list.

push_back

void push_back(T * e)

Add an element to the back (tail) of the list.

pop_front

T * pop_front()

Remove an element from the front (head) of the list.

pop_back

T * pop_back()

Remove an element from the back (tail) of the list.

insertBefore

void insertBefore(T * e, T * before)

Insert the element e before the element identified by 'before' in the list.

insertBehind

void insertBehind(T * e, T * behind)

Insert the element e behind the element identified by 'behind' in the list.

swap

void swap(T * a, T * b)

Swaps the values of the two given listElement objects. The swap function of listElement must be overwritten, also the pointers a and b passed to swap must point to a valid object.

sort

void sort(T * start = NULL, T * end = NULL)

Sorts the list by using quicksort. The sort will be done between start and end. If start is NULL, the start of the list will be used, and if end is NULL, the end of the list. So by calling sort() withouth parameters, the sorting will be done for the whole list. During sorting, the function will call listElement::compare() and listElement::swap(). So both of them must be implemented to not end up with an assertion.

class listElement members

listElement

listElement()

~listElement

virtual ~listElement()

The destructor of a list element removes the element from the list.

goNext

const T * goNext()

Returns the next element in the list.

goPrev

const T * goPrev()

Returns the previous element in the list.

remove

void remove()

Removes the element from the list.

getList

const list * getList()

Returns the list, in which this element is linked.

compare

virtual int compare(T * e)

Will be called from list::sort() to know how to handle the item and the one passed to compare. The function need to return a value less than 0, if this is < e, zero if this is equal to e or a value greater than 0 if this is > e. If you don't whant to call list::sort, there is no need to override this function.

swap

virtual void swap(T * with)

Will be called from list::sort() or list::swap() to swap the instance of the listElement object with the one passed. The implementation of the function is responsible to switch all fields of this and with. If you don't whant to call list::sort() or list::swap(), there is no need to override this function.

Examples

    // use the ilist base class
class sample : public istd::listElement<sample> {

}
 ...
    // defining the list
istd::list<sample> samples;
 ...
    // iterating thru the list
for(class sample * s = samples.front(); s; s=s->goNext()) {
    ...
}