Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3652 in orxonox.OLD


Ignore:
Timestamp:
Mar 25, 2005, 5:51:00 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: added list iterator template. this is a fix in the list framework, that should I should have made long time ago. modified the list to make it more performant — benchmarking rulez

Location:
orxonox/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r3646 r3652  
    119119                 lib/util/ini_parser.h \
    120120                 lib/math/vector.h \
    121                  lib/math/vector_new.h \
    122                  lib/math/quaternion.h \
    123121                 lib/math/curve.h \
    124122                 glmenu/glmenu_imagescreen.h
  • orxonox/trunk/src/Makefile.in

    r3646 r3652  
    323323                 lib/util/ini_parser.h \
    324324                 lib/math/vector.h \
    325                  lib/math/vector_new.h \
    326                  lib/math/quaternion.h \
    327325                 lib/math/curve.h \
    328326                 glmenu/glmenu_imagescreen.h
  • orxonox/trunk/src/lib/util/list.h

    r3586 r3652  
    4646};
    4747
    48 class Iterator
    49 {
    50 
     48
     49
     50template<class T> struct listElement
     51{
     52  listElement* prev;
     53  T* curr;
     54  listElement* next;
     55};
     56
     57template<class T> class tIterator
     58{
    5159 public:
    52   bool hasNext();
    53   WorldEntity* next();
     60  tIterator(listElement<T>* startElement);
     61  ~tIterator();
     62 
     63  T* nextElement();
    5464
    5565 private:
    56 
    57 };
     66  listElement<T>* currentEl;
     67  listElement<T>* firstEl;
     68};
     69
     70
     71template<class T>
     72tIterator<T>::tIterator (listElement<T>* startElement)
     73{
     74  this->currentEl = startElement;
     75  this->firstEl = startElement;
     76}
     77
     78
     79template<class T>
     80tIterator<T>::~tIterator ()
     81{
     82  this->currentEl = NULL;
     83}
     84
     85
     86template<class T>
     87inline T* tIterator<T>::nextElement ()
     88{
     89  if( this->currentEl == NULL)
     90    {
     91      PRINTF(1)("Iterator has not been initialized - there is no currentEl\n");
     92      return NULL;
     93    }
     94  if( this->currentEl->next == NULL)
     95    return NULL;
     96  return this->currentEl->next->curr;
     97}
     98
    5899
    59100
    60101template<class T> class tList
    61102{
    62  private:
    63   struct listElement
    64   {
    65     listElement* prev;
    66     T* curr;
    67     listElement* next;
    68   };
    69 
    70   Uint32 size;
    71   listElement* first;
    72   listElement* last;
    73   listElement* currentEl;
    74103 
    75104 public:
    76105  tList ();
    77106  ~tList ();
    78  
    79107
    80108  void add(T* entity);
     
    85113  int getSize();
    86114  T* enumerate();
     115  tIterator<T>* getIterator();
    87116  T* nextElement();
    88117  T* nextElement(T* toEntity);
    89118  T* toArray();
    90119  void debug();
     120
     121 private:
     122
     123  Uint32 size;
     124  listElement<T>* first;
     125  listElement<T>* last;
     126  listElement<T>* currentEl;
     127
    91128};
    92129
     
    106143  while(this->currentEl != NULL)
    107144    {
    108       listElement* le = this->currentEl->next;
     145      listElement<T>* le = this->currentEl->next;
    109146      //delete this->currentEl->curr;
    110147      delete this->currentEl;
     
    121158{
    122159  if( entity == NULL) return;
    123   listElement* el = new listElement;
     160  listElement<T>* el = new listElement<T>;
    124161  el->prev = this->last;
    125162  el->curr = entity;
     
    139176  if( entity == NULL) return;
    140177  this->currentEl = this->first;
    141   listElement* te;
     178  listElement<T>* te;
    142179  while( this->currentEl != NULL)
    143180    {
     
    167204  while(this->currentEl != NULL)
    168205    {
    169       listElement* le = this->currentEl->next;
     206      listElement<T>* le = this->currentEl->next;
    170207      //delete this->currentEl->curr;
    171208      delete this->currentEl;
     
    203240{
    204241  //if( this->last == this->first == NULL) return NULL;
    205   if(this->size == 0) return NULL;
     242  if( this->size == 0) return NULL;
    206243  this->currentEl = this->first;
    207244  return this->currentEl->curr;
     
    210247
    211248template<class T>
     249tIterator<T>* tList<T>::getIterator()
     250{
     251  if( this->size == 0) return NULL;
     252  tIterator<T>* iterator = new tIterator<T>(this->first);
     253  return iterator;
     254}
     255
     256
     257template<class T>
    212258T* tList<T>::nextElement()
    213259{
    214260  // if( this->last == this->first == NULL) return NULL;
    215   if(this->size == 0) return NULL;
     261  if( this->size == 0) return NULL;
    216262  this->currentEl = this->currentEl->next;
    217   if(this->currentEl == NULL) return NULL;
     263  if( this->currentEl == NULL) return NULL;
    218264  return this->currentEl->curr;
    219265}
  • orxonox/trunk/src/orxonox.cc

    r3651 r3652  
    628628          mi = mittel / (float)VECTOR_MAX;
    629629          printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi);
    630          
    631          
    632 
    633          
    634 
    635630        }
    636      
    637 
    638631    }
    639632}
Note: See TracChangeset for help on using the changeset viewer.