Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5111 in orxonox.OLD for trunk/src/lib/util


Ignore:
Timestamp:
Aug 23, 2005, 11:13:56 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: reverted the last steps, because they created a huge pack of seg-faults

Location:
trunk/src/lib/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/ini_parser.cc

    r5110 r5111  
    5858  {
    5959    tIterator<IniSection>* sectionIt = this->sections->getIterator();
    60     IniSection* sectionEnum = sectionIt->firstElement();
     60    IniSection* sectionEnum = sectionIt->nextElement();
    6161    while (sectionEnum)
    6262    {
    6363      tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
    64       IniEntry* entryEnum = entryIt->firstElement();
     64      IniEntry* entryEnum = entryIt->nextElement();
    6565      while (entryEnum)
    6666      {
     
    192192    {
    193193      tIterator<IniSection>* sectionIt = this->sections->getIterator();
    194       IniSection* sectionEnum = sectionIt->firstElement();
     194      IniSection* sectionEnum = sectionIt->nextElement();
    195195      while (sectionEnum)
    196196      {
     
    198198
    199199        tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
    200         IniEntry* entryEnum = entryIt->firstElement();
     200        IniEntry* entryEnum = entryIt->nextElement();
    201201        while (entryEnum)
    202202        {
     
    246246{
    247247  tIterator<IniSection>* sectionIt = this->sections->getIterator();
    248   IniSection* sectionEnum = sectionIt->firstElement();
     248  IniSection* sectionEnum = sectionIt->nextElement();
    249249  while (sectionEnum)
    250250  {
     
    347347  {
    348348    tIterator<IniSection>* sectionIt = this->sections->getIterator();
    349     IniSection* sectionEnum = sectionIt->firstElement();
     349    IniSection* sectionEnum = sectionIt->nextElement();
    350350    while (sectionEnum)
    351351    {
     
    395395  {
    396396    tIterator<IniSection>* sectionIt = this->sections->getIterator();
    397     IniSection* sectionEnum = sectionIt->firstElement();
     397    IniSection* sectionEnum = sectionIt->nextElement();
    398398    while (sectionEnum)
    399399    {
     
    401401      {
    402402        tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
    403         IniEntry* entryEnum = entryIt->firstElement();
     403        IniEntry* entryEnum = entryIt->nextElement();
    404404        while (entryEnum)
    405405        {
     
    452452  {
    453453    tIterator<IniSection>* sectionIt = this->sections->getIterator();
    454     IniSection* sectionEnum = sectionIt->firstElement();
     454    IniSection* sectionEnum = sectionIt->nextElement();
    455455    while (sectionEnum)
    456456    {
     
    458458
    459459      tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
    460       IniEntry* entryEnum = entryIt->firstElement();
     460      IniEntry* entryEnum = entryIt->nextElement();
    461461      while (entryEnum)
    462462      {
  • trunk/src/lib/util/list.h

    r5110 r5111  
    1212#endif
    1313
    14 template<class T> class tIterator;
     14
    1515
    1616//! a list element of the tList,
     
    2323
    2424/**
     25 *  an iterator class
     26
     27   this enables the user to iterate through a list very easely
     28*/
     29template<class T> class tIterator
     30{
     31 public:
     32  tIterator(listElement<T>* startElement);
     33  ~tIterator();
     34
     35  T* nextElement();
     36  T* seekElement(T* element);
     37
     38 private:
     39  listElement<T>*    currentEl;                      //!< pointer to the current list element in the iterator
     40  listElement<T>*    tmpEl;                          //!< temp listElemnt pointer
     41  listElement<T>*    startElement;                   //!< pointer to the start of the list
     42};
     43
     44
     45/**
     46 *  iterator constructor
     47 * @param startElement:  the first list element from the tList
     48
     49   normaly you will use it like this:
     50
     51   tIterator<char>* nameIterator = nameList->getIterator();
     52   char name* = nameIterator->nextElement();
     53   while( name != NULL)
     54   {
     55     PRINTF(3)("found name: %s in list\n", name);
     56     name = nameIterator->nextElement();
     57   }
     58   delete nameIterator;
     59*/
     60template<class T>
     61inline tIterator<T>::tIterator (listElement<T>* startElement)
     62{
     63  this->currentEl = startElement;
     64  this->tmpEl = NULL;
     65  this->startElement = startElement;
     66}
     67
     68
     69/**
     70 *  the destructor
     71*/
     72template<class T>
     73inline tIterator<T>::~tIterator ()
     74{
     75  this->currentEl = NULL;
     76}
     77
     78
     79/**
     80 *  use it to iterate through the list
     81 * @returns next list element
     82*/
     83template<class T>
     84inline T* tIterator<T>::nextElement ()
     85{
     86  if( this->currentEl == NULL)
     87    return NULL;
     88
     89  this->tmpEl = this->currentEl;
     90  this->currentEl = this->currentEl->next;
     91  return this->tmpEl->curr;
     92}
     93
     94/**
     95 *  gets the element after the selected one, sets the iterator to this point in the list
     96 * @param element the element to seek
     97 * @returns next list element
     98
     99  Attention: if you seek an element, the iterator pointer will point to the NEXT listelement after the argument!
     100 */
     101template<class T>
     102inline T* tIterator<T>::seekElement (T* element)
     103{
     104  for(this->tmpEl = this->startElement; this->tmpEl != NULL; this->tmpEl = this->tmpEl->next)
     105  {
     106    if( unlikely(this->tmpEl->curr == element))
     107    {
     108      if( this->tmpEl->next != NULL)
     109      {
     110        this->currentEl = this->tmpEl->next->next;
     111        return this->tmpEl->next->curr;
     112      }
     113      return NULL;
     114    }
     115  }
     116  return NULL;
     117}
     118
     119
     120
     121/**
    25122 *  the list template class
    26123
     
    29126template<class T> class tList
    30127{
    31   friend class tIterator<T>;
    32 
    33128 public:
    34129  tList ();
     
    40135  void removeLast();
    41136  void flush();
    42   T* firstElement() const;
    43   T* lastElement() const;
    44   bool isEmpty() const;
    45   unsigned int getSize() const;
     137  T* firstElement();
     138  T* lastElement();
     139  bool isEmpty();
     140  unsigned int getSize();
    46141  bool inList(T* entity);
    47   tIterator<T>* getIterator() const;
     142  tIterator<T>* getIterator();
    48143  T* nextElement(T* toEntity);
    49144  T* toArray();
     
    208303*/
    209304template<class T>
    210 inline T* tList<T>::firstElement() const
     305inline T* tList<T>::firstElement()
    211306{
    212307  return this->first->curr;
     
    219314*/
    220315template<class T>
    221 inline T* tList<T>::lastElement() const
     316inline T* tList<T>::lastElement()
    222317{
    223318  return this->last->curr;
     
    230325*/
    231326template<class T>
    232 inline bool tList<T>::isEmpty() const
     327inline bool tList<T>::isEmpty()
    233328{
    234329  return (this->size==0)?true:false;
     
    264359*/
    265360template<class T>
    266 inline unsigned int tList<T>::getSize() const
     361inline unsigned int tList<T>::getSize()
    267362{
    268363  return this->size;
     
    277372*/
    278373template<class T>
    279 inline tIterator<T>* tList<T>::getIterator() const
    280 {
    281   return new tIterator<T>(this);
     374inline tIterator<T>* tList<T>::getIterator()
     375{
     376  tIterator<T>* iterator = new tIterator<T>(this->first);
     377  return iterator;
    282378}
    283379
     
    318414}
    319415
    320 
    321 
    322 
    323 /**
    324  *  an iterator class
    325 
    326    this enables the user to iterate through a list very easely
    327  */
    328 template<class T> class tIterator
    329 {
    330   public:
    331     tIterator(const tList<T>* list);
    332     ~tIterator();
    333 
    334     T* firstElement();
    335     T* nextElement();
    336     T* seekElement(T* element);
    337 
    338   private:
    339     listElement<T>*    currentEl;                      //!< pointer to the current list element in the iterator
    340     listElement<T>*    tmpEl;                          //!< temp listElemnt pointer
    341     const tList<T>*    list;                           //!< The List, that we want to iterate through
    342 };
    343 
    344 
    345 /**
    346  *  iterator constructor
    347  * @param startElement:  the first list element from the tList
    348 
    349    normaly you will use it like this:
    350 
    351    tIterator<char>* nameIterator = nameList->getIterator();
    352                 char name* = nameIterator->nextElement();
    353                 while( name != NULL)
    354 {
    355                 PRINTF(3)("found name: %s in list\n", name);
    356                 name = nameIterator->nextElement();
    357 }
    358                 delete nameIterator;
    359  */
    360                 template<class T>
    361                 inline tIterator<T>::tIterator (const tList<T>* list)
    362 {
    363   this->currentEl = list->first;
    364   this->tmpEl = NULL;
    365   this->list = list;
    366 }
    367 
    368 
    369 /**
    370  *  the destructor
    371  */
    372 template<class T>
    373     inline tIterator<T>::~tIterator ()
    374 {
    375   this->currentEl = NULL;
    376 }
    377 
    378 template<class T>
    379     inline T* tIterator<T>::firstElement ()
    380 {
    381   this->currentEl = this->list->first;
    382   if (this->currentEl == NULL)
    383     return NULL;
    384   else
    385     return this->currentEl->curr;
    386 }
    387 
    388 
    389 /**
    390  *  use it to iterate through the list
    391  * @returns next list element
    392  */
    393 template<class T>
    394     inline T* tIterator<T>::nextElement ()
    395 {
    396   if( this->currentEl == NULL || this->currentEl->next == NULL)
    397   {
    398     this->currentEl = NULL;
    399     return NULL;
    400   }
    401 
    402   this->currentEl = this->currentEl->next;
    403   return this->currentEl->curr;
    404 }
    405 
    406 /**
    407  *  gets the element after the selected one, sets the iterator to this point in the list
    408  * @param element the element to seek
    409  * @returns next list element
    410 
    411   Attention: if you seek an element, the iterator pointer will point to the NEXT listelement after the argument!
    412  */
    413 template<class T>
    414     inline T* tIterator<T>::seekElement (T* element)
    415 {
    416   for(this->tmpEl = this->list->first; this->tmpEl != NULL; this->tmpEl = this->tmpEl->next)
    417   {
    418     if( unlikely(this->tmpEl->curr == element))
    419     {
    420       if( this->tmpEl->next != NULL)
    421       {
    422         this->currentEl = this->tmpEl;
    423         return this->tmpEl->next->curr;
    424       }
    425       return NULL;
    426     }
    427   }
    428   return NULL;
    429 }
    430 
    431416#endif /* _LIST_H */
Note: See TracChangeset for help on using the changeset viewer.