Version 4 (modified by patrick, 20 years ago) (diff) |
---|
Module Description
How to use certain modules in the Orxonox Framework [br] Currently we have following modules descriptions here:
- list (list.h)
list
There is a list template called "tList" use it as follows:
Use in Functions without Global Reference
It you just want to create a new list and just quickly use it make it as follows:
#include "list.h" /* include the header */ #include "debug.h" /* for use of PRINTF */ . . . tList<char>* nameList = new tList<char>(); /* create the new list*/ nameList->add("Pumba"); /* add some elements*/ nameList->add("Mogli"); nameList->add("Timon"); tIterator<char>* nameIterator = nameList->getIterator(); /* get the iterator - JAVA style */ char name* = nameIterator->nextElement(); /* this returns the FIRST element */ while( name != NULL) /* nextElement() will return NULL at the end */ { PRINTF(3)("found name: %s in list\n", name); name = nameIterator->nextElement(); /* give back the next element or NULL if last */ } delete nameIterator; /* don't forget to delete the iterator reference again . .
This code will have an output like this:
found name: Pumpa in list found name: Mogli in list found name: Timon in list
You can make lists of whatever you want eg also from WorldEntities:
#include "list.h" . . tList<WorldEntity>* entityList = new tList<WorldEntity>(); /* crete new list*/ entityList->add(new WorldEntity()); /* just adds an new entity */ . .
And you can make Lists of Lists
#include "list.h" . . tList<char>* nameList = new tList<char>(); tList<tList<char> >* nameListList = new tList<tList<char> >(); /* don't forget the space (_): >_> otherwhise it will be interpreted as an operator */ . .
Now I hear you screem: "ENOUGH"! And you are right…
Use in Header Files
If you want a list as a class attribute you have to make a forward declaration of the list:
#inlcude "list.h" /* include the header of the list */ template<class T> class tList; /* forward declaration of the list */ class ExampleClass { private: tList<> };