Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 248


Ignore:
Timestamp:
Nov 26, 2007, 1:57:37 AM (16 years ago)
Author:
landauf
Message:

changed iterator: it now needs a list-element to start from (Iterator<classname> it = ObjectList<classname>::start() or end() for ++it or —it, respectively).

Location:
code/branches/objecthierarchie/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchie/src/IdentifierIncludes.h

    r246 r248  
    22#include "Factory.h"
    33#include "ClassFactory.h"
    4 //#include "IdentifierList.h"
    5 //#include "ObjectList.h"
    64#include "Iterator.h"
    75#include "OrxonoxClass.h"
  • code/branches/objecthierarchie/src/Iterator.h

    r239 r248  
    1010            Iterator()
    1111            {
    12                 this->elementForwards_ = ClassIdentifier<T>::getIdentifier()->objects_->first_;
    13                 this->elementBackwards_ = ClassIdentifier<T>::getIdentifier()->objects_->last_;
    14                 this->iteratingForwards_ = true;
     12                this->element_ = 0;
    1513            }
    1614
    17             Iterator<T> operator++(int step)
     15            Iterator(ObjectListElement<T>* element)
    1816            {
    19                 Iterator<T> copy = *this;
    20 
    21                 if (step < 1)
    22                     step = 1;
    23 
    24                 for (int i = 0; i < step; i++)
    25                     this->elementForwards_ = this->elementForwards_->next_;
    26 
    27                 return copy;
     17                this->element_ = element;
    2818            }
    2919
    3020            Iterator<T> operator++()
    3121            {
    32                 this->elementForwards_ = this->elementForwards_->next_;
     22                this->element_ = this->element_->next_;
    3323                return *this;
    34             }
    35 
    36             Iterator<T> operator--(int step)
    37             {
    38                 Iterator<T> copy = *this;
    39 
    40                 if (this->iteratingForwards_)
    41                 {
    42                     this->iteratingForwards_ = false;
    43                 }
    44                 else
    45                 {
    46                     if (step < 1)
    47                         step = 1;
    48 
    49                     for (int i = 0; i < step; i++)
    50                         this->elementBackwards_ = this->elementBackwards_->prev_;
    51                 }
    5224            }
    5325
    5426            Iterator<T> operator--()
    5527            {
    56                 if (this->iteratingForwards_)
    57                     this->iteratingForwards_ = false;
    58                 else
    59                     this->elementBackwards_ = this->elementBackwards_->prev_;
    60 
     28                this->element_ = this->element_->prev_;
    6129                return *this;
    6230            }
     
    6432            T* operator*()
    6533            {
    66                 if (this->iteratingForwards_)
    67                     return this->elementForwards_->object_;
    68                 else
    69                     return this->elementBackwards_->object_;
     34                return this->element_->object_;
    7035            }
    7136
    7237            T* operator->() const
    7338            {
    74                 if (this->iteratingForwards_)
    75                     return this->elementForwards_->object_;
    76                 else
    77                     return this->elementBackwards_->object_;
     39                return this->element_->object_;
    7840
    7941            }
     
    8143            operator bool()
    8244            {
    83                 if (this->iteratingForwards_)
    84                     return (this->elementForwards_ != 0);
    85                 else
    86                     return (this->elementBackwards_->prev_ != 0);
     45                return (this->element_ != 0);
    8746            }
    8847
     
    9251                    std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n";
    9352
    94                 if (this->iteratingForwards_)
    95                     return (this->elementForwards_ != 0);
    96                 else
    97                     return (this->elementBackwards_->prev_ != 0);
     53                return (this->element_ != 0);
    9854            }
    9955
    100 
    10156        private:
    102             ObjectListElement<T>* elementForwards_;
    103             ObjectListElement<T>* elementBackwards_;
    104             bool iteratingForwards_;
     57            ObjectListElement<T>* element_;
    10558    };
    10659}
  • code/branches/objecthierarchie/src/ObjectList.h

    r246 r248  
    3939    // ###############################
    4040    template <class T>
     41    class Iterator;
     42
     43    template <class T>
    4144    class ObjectList
    4245    {
     
    4750            void remove(OrxonoxClass* object, bool bIterateForwards = true);
    4851
     52            inline static Iterator<T> start()
     53                { Iterator<T>(pointer_s->first_); }
     54            inline static Iterator<T> end()
     55                { Iterator<T>(pointer_s->last_); }
     56
    4957            ObjectListElement<T>* first_;
    5058            ObjectListElement<T>* last_;
     59
     60        private:
     61            static ObjectList<T>* pointer_s;
    5162    };
     63
     64    template <class T>
     65    ObjectList<T>* ObjectList<T>::pointer_s = 0;
    5266
    5367    template <class T>
     
    5670        this->first_ = 0;
    5771        this->last_ = 0;
     72
     73        this->pointer_s = this;
    5874    }
    5975
  • code/branches/objecthierarchie/src/orxonox.cc

    r246 r248  
    435435        delete test9_06;
    436436*/
    437 /*
     437
    438438        std::cout << "Test 10\n";
    439439        Identifier* test10_01 = Class(A1B2);
     
    451451        std::cout << "1\n";
    452452        int count;
    453         count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     453
     454        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
    454455        std::cout << "Anzahl BaseObjects: " << count << "\n";
    455         count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     456        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
    456457        std::cout << "Anzahl A1: " << count << "\n";
    457         count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     458        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
    458459        std::cout << "Anzahl A1B1: " << count << "\n";
    459         count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     460        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
    460461        std::cout << "Anzahl A1B1C1: " << count << "\n";
    461         count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     462        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
    462463        std::cout << "Anzahl A2: " << count << "\n";
    463464
     
    479480        }
    480481
    481         count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     482        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
    482483        std::cout << "Anzahl BaseObjects: " << count << "\n";
    483         count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     484        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
    484485        std::cout << "Anzahl A1: " << count << "\n";
    485         count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     486        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
    486487        std::cout << "Anzahl A1B1: " << count << "\n";
    487         count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     488        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
    488489        std::cout << "Anzahl A1B1C1: " << count << "\n";
    489         count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     490        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
    490491        std::cout << "Anzahl A2: " << count << "\n";
    491492
    492         for (Iterator<A2B1C1> it; it; ++it)
     493        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
    493494            std::cout << "Name: " << it->name_ << "\n";
    494495
    495496        std::cout << "3\n";
    496         for (Iterator<A2B1C1> it; it; --it)
     497        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
    497498            std::cout << "Name: " << it->name_ << "\n";
    498499
     
    500501        delete test10_08;
    501502
    502         count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     503        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
    503504        std::cout << "Anzahl BaseObjects: " << count << "\n";
    504         count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     505        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
    505506        std::cout << "Anzahl A1: " << count << "\n";
    506         count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     507        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
    507508        std::cout << "Anzahl A1B1: " << count << "\n";
    508         count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     509        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
    509510        std::cout << "Anzahl A1B1C1: " << count << "\n";
    510         count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     511        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
    511512        std::cout << "Anzahl A2: " << count << "\n";
    512513
    513514        std::cout << "5\n";
    514         for (Iterator<A2B1C1> it; it; ++it)
     515        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
    515516            std::cout << "Name: " << it->name_ << "\n";
    516517
    517518        std::cout << "6\n";
    518         for (Iterator<A2B1C1> it; it; --it)
     519        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
    519520            std::cout << "Name: " << it->name_ << "\n";
    520521
     
    522523        delete test10_09;
    523524
    524         count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     525        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it != 0; --it) { count++; }
    525526        std::cout << "Anzahl BaseObjects: " << count << "\n";
    526         count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     527        count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it != 0; --it) { count++; }
    527528        std::cout << "Anzahl A1: " << count << "\n";
    528         count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     529        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::end(); it; --it) { count++; }
    529530        std::cout << "Anzahl A1B1: " << count << "\n";
    530         count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     531        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::end(); it; --it) { count++; }
    531532        std::cout << "Anzahl A1B1C1: " << count << "\n";
    532         count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     533        count = 0; for (Iterator<A2> it = ObjectList<A2>::end(); it; --it) { count++; }
    533534        std::cout << "Anzahl A2: " << count << "\n";
    534535
    535536        std::cout << "8\n";
    536         for (Iterator<A2B1C1> it; it; ++it)
     537        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
    537538            std::cout << "Name: " << it->name_ << "\n";
    538539
    539540        std::cout << "9\n";
    540         for (Iterator<A2B1C1> it; it; --it)
     541        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
    541542            std::cout << "Name: " << it->name_ << "\n";
    542543
     
    544545        delete test10_10;
    545546
    546         count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     547        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
    547548        std::cout << "Anzahl BaseObjects: " << count << "\n";
    548         count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     549        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
    549550        std::cout << "Anzahl A1: " << count << "\n";
    550         count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     551        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
    551552        std::cout << "Anzahl A1B1: " << count << "\n";
    552         count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     553        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
    553554        std::cout << "Anzahl A1B1C1: " << count << "\n";
    554         count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     555        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
    555556        std::cout << "Anzahl A2: " << count << "\n";
    556557
    557558        std::cout << "11\n";
    558         for (Iterator<A2B1C1> it; it; ++it)
     559        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
    559560            std::cout << "Name: " << it->name_ << "\n";
    560561
    561562        std::cout << "12\n";
    562         for (Iterator<A2B1C1> it; it; --it)
     563        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
    563564            std::cout << "Name: " << it->name_ << "\n";
    564 */
     565
    565566
    566567      }
Note: See TracChangeset for help on using the changeset viewer.