A generic class that handles lists. More...
#include <ilog/list.h>
Public Member Functions | |
IlListOf(NAME) () | |
Constructor. More... | |
~IlListOf(NAME) () | |
Destructor. More... | |
void | append (TYPE element) |
Appends an element to the list. More... | |
IlListOf(NAME) * | copy () const |
Creates a copy of this list. More... | |
void | empty () |
Empties the list. More... | |
IlBoolean | find (TYPE element) const |
Queries the existence of an element. More... | |
IlUInt | getLength () const |
Retrieves the length of the list. More... | |
TYPE | getValue (IlUInt pos) const |
Retrieves an element. More... | |
void | insert (TYPE element, IlInt pos=0) |
Inserts an element in the list. More... | |
TYPE | operator[] (IlUInt pos) const |
Retrieves an element. More... | |
IlBoolean | remove (TYPE element) |
Removes an element. More... | |
A generic class that handles lists.
Library: ilog
This class is generated by the macro IlDefineListOf(NAME, TYPE)
.
It handles a list of objects of the type TYPE
. The major restriction of this class is that TYPE
must be a type that can be cast to and from a void*
.
An IlListOf(NAME)
is a single linked list that can be grown and queried. It does not handle the deletion of the object it stores.
There are different ways of enumerating the elements of an IlListOf(NAME)
:
operator[]
, you can enumerate the elements of a list. This is easy to use, but it doesn't give the optimal performance, and you must take care not to modify the list in your code; otherwise some indexes might become invalid. IlMapList
macro: you can apply an expression to each element of the list. This is very fast, but you must not modify the list itself while you are enumerating its elements. IlDefineListOf(NAME, TYPE)
macro), two other classes are created: IlListIteratorOf(NAME)
and IlSafeListIteratorOf(NAME)
. These classes are designed to simplify the enumeration of the elements of a list, and the Safe version, although a little slower than the other, enables you to manipulate the list even while you are enumerating its elements. IlListOf(NAME)::IlListOf(NAME) | ( | ) |
Constructor.
Initializes a new empty list.
IlListOf(NAME)::~IlListOf(NAME) | ( | ) |
Destructor.
Empties the list.
void IlListOf(NAME)::append | ( | TYPE | element | ) |
Appends an element to the list.
The new element becomes the last element of this list. The element is not copied.
element | The element that must be appended to the list. |
insert()
. IlListOf(NAME)* IlListOf(NAME)::copy | ( | ) | const |
Creates a copy of this list.
The elements are not copied.
void IlListOf(NAME)::empty | ( | ) |
Empties the list.
The elements are not destroyed. The list is left with no elements.
IlBoolean IlListOf(NAME)::find | ( | TYPE | element | ) | const |
Queries the existence of an element.
element | The element that is searched in the list. |
IlTrue
if the element is stored in the list, and IlFalse
if it is not. IlUInt IlListOf(NAME)::getLength | ( | ) | const |
Retrieves the length of the list.
TYPE IlListOf(NAME)::getValue | ( | IlUInt | pos | ) | const |
Retrieves an element.
pos | The index, in this list, of the element to be retrieved. |
0
if the index is invalid. Note that 0
is a also a valid value for an element in the list. void IlListOf(NAME)::insert | ( | TYPE | element, |
IlInt | pos = 0 |
||
) |
Inserts an element in the list.
The element is not copied.
element | The element that must be inserted in the list. |
pos | The position, in the list where this element must be inserted. 0 indicates that you want element to become the first element of the list. Any invalid value (such as a negative location, or an index that is greater than the size of the list) will append element to the list. |
append()
. TYPE IlListOf(NAME)::operator[] | ( | IlUInt | pos | ) | const |
Retrieves an element.
pos | The index, in this list, of the element to be retrieved. |
0
if the index is invalid. Note that 0
is a also a valid value for an element in the list. IlBoolean IlListOf(NAME)::remove | ( | TYPE | element | ) |
Removes an element.
The element is not destroyed.
element | The element that is removed from the list. |
IlTrue
if the element was removed successfully. If the element is not stored in this list, this member function returns IlFalse
, indicating that a problem occurred.