| | 1 | = Module Description = |
| | 2 | How to use certain modules in the Orxonox Framework |
| | 3 | |
| | 4 | == list == |
| | 5 | There is a list template called "tList" use it as follows: |
| | 6 | |
| | 7 | === Use in Functions without Global Reference === |
| | 8 | It you just want to create a new list and just quickly use it make it as follows: |
| | 9 | {{{ |
| | 10 | #include "list.h" /* include the header */ |
| | 11 | #include "debug.h" /* for use of PRINTF */ |
| | 12 | . |
| | 13 | . |
| | 14 | . |
| | 15 | tList<char>* nameList = new tList<char*>(); /* create the new list*/ |
| | 16 | |
| | 17 | nameList->add("Pumba"); /* add some elements*/ |
| | 18 | nameList->add("Mogli"); |
| | 19 | nameList->add("Timon"); |
| | 20 | |
| | 21 | tIterator<char>* nameIterator = nameList->getIterator(); /* get the iterator - JAVA style */ |
| | 22 | char name* = nameIterator->nextElement(); /* this returns the FIRST element */ |
| | 23 | while( name != NULL) /* nextElement() will return NULL at the end */ |
| | 24 | { |
| | 25 | PRINTF(3)("found name: %s in list\n", name); |
| | 26 | name = nameIterator->nextElement(); /* give back the next element or NULL if last */ |
| | 27 | } |
| | 28 | . |
| | 29 | . |
| | 30 | }}} |
| | 31 | This code will have an output like this: |
| | 32 | {{{ |
| | 33 | found name: Pumpa in list |
| | 34 | found name: Mogli in list |
| | 35 | found name: Timon in list |
| | 36 | }}} |
| | 37 | You can make lists of whatever you want eg also from WorldEntities: |
| | 38 | {{{ |
| | 39 | #include "list.h" |
| | 40 | . |
| | 41 | . |
| | 42 | tList<WorldEntity>* entityList = new tList<WorldEntity>(); /* crete new list*/ |
| | 43 | entityList->add(new WorldEntity()); /* just adds an new entity */ |
| | 44 | . |
| | 45 | . |
| | 46 | }}} |
| | 47 | And you can make Lists of Lists :)) |
| | 48 | {{{ |
| | 49 | #include "list.h" |
| | 50 | . |
| | 51 | . |
| | 52 | tList<char>* nameList = new tList<char>(); |
| | 53 | tList<tList<char> >* nameListList = new tList<tList<char> >(); /* don't forget the space (_): >_> |
| | 54 | otherwhise it will be interpreted |
| | 55 | as an operator |
| | 56 | */ |
| | 57 | . |
| | 58 | . |
| | 59 | }}} |
| | 60 | Now I hear you screem: "ENOUGH"! And you are right...:) |
| | 61 | |
| | 62 | === Use in Header Files === |
| | 63 | If you want a list as a class attribute you have to make a forward declaration of the list: |
| | 64 | {{{ |
| | 65 | |
| | 66 | #inlcude "list.h" /* include the header of the list */ |
| | 67 | |
| | 68 | template<class T> class tList; /* forward declaration of the list */ |
| | 69 | |
| | 70 | class ExampleClass |
| | 71 | { |
| | 72 | private: |
| | 73 | tList<> |
| | 74 | }; |
| | 75 | |
| | 76 | }}} |