Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 6, 2015, 2:51:14 PM (9 years ago)
Author:
landauf
Message:

no static functions anymore in ObjectList. you need to instantiate an ObjectList to use it.
this allows for prettier for-loop syntax when iterating over an ObjectList of a specific context: for (T* object : ObjectList<T>(context)) { … }

Location:
code/branches/cpp11_v2/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/ClassTreeMask.cc

    r10919 r10920  
    851851            this->objectIterator_ = Context::getRootContext()->getObjectList(this->subclassIterator_->first)->begin();
    852852        else
    853             this->objectIterator_ = ObjectList<BaseObject>::end();
     853            this->objectIterator_ = ObjectList<BaseObject>().end();
    854854
    855855        // Check if the iterator points on a valid object. If not, go to the next object by calling ++
  • code/branches/cpp11_v2/src/libraries/core/Loader.cc

    r10917 r10920  
    207207        if (!file)
    208208            return;
    209         for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; )
     209        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>().begin(); it; )
    210210        {
    211211            if ((it->getFile() == file) && mask.isIncluded(it->getIdentifier()))
  • code/branches/cpp11_v2/src/libraries/core/class/Identifier.h

    r10919 r10920  
    415415    void ClassIdentifier<T>::destroyObjects(Listable*)
    416416    {
    417         ObjectListBase* objectList = Context::getRootContext()->getObjectList(this);
    418         ObjectListElement<T>* begin = static_cast<ObjectListElement<T>*>(objectList->begin());
    419         ObjectListElement<T>* end = static_cast<ObjectListElement<T>*>(objectList->end());
    420         for (typename ObjectList<T>::iterator it = begin; it != end; )
     417        ObjectList<T> list(Context::getRootContext()->getObjectList(this));
     418        for (typename ObjectList<T>::iterator it = list.begin(); it != list.end(); )
    421419            this->destroyObject(*(it++));
    422420    }
  • code/branches/cpp11_v2/src/libraries/core/object/ObjectList.h

    r10774 r10920  
    7171            typedef ObjectListIterator<T> iterator;
    7272
    73             /// Returns the size of the list (for the root context)
    74             inline static size_t size()
    75             {   return size(Context::getRootContext());   }
     73            ObjectList() : ObjectList(Context::getRootContext()) {}
     74            ObjectList(Context* context) : ObjectList(context->getObjectList<T>()) {}
     75            ObjectList(ObjectListBase* list) : list_(list) {}
     76
    7677            /// Returns the size of the list
    77             inline static size_t size(Context* context)
    78             {
    79                 return context->getObjectList<T>()->size();
    80             }
     78            inline size_t size()
     79            {   return this->list_->size();   }
    8180
    82             /// Returns an Iterator to the first element in the list (for the root context).
    83             inline static ObjectListIterator<T> begin()
    84             {   return begin(Context::getRootContext());   }
    8581            /// Returns an Iterator to the first element in the list.
    86             inline static ObjectListIterator<T> begin(Context* context)
    87             {
    88                 ObjectListBase* list = context->getObjectList<T>();
    89                 return static_cast<ObjectListElement<T>*>(list->begin());
    90             }
     82            inline ObjectListIterator<T> begin()
     83            {   return static_cast<ObjectListElement<T>*>(this->list_->begin());   }
     84            /// Returns an Iterator to the element after the last element in the list.
     85            inline ObjectListIterator<T> end()
     86            {   return static_cast<ObjectListElement<T>*>(this->list_->end());   }
    9187
    92             /// Returns an Iterator to the element after the last element in the list (for the root context).
    93             inline static ObjectListIterator<T> end()
    94             {   return end(Context::getRootContext());   }
    95             /// Returns an Iterator to the element after the last element in the list.
    96             inline static ObjectListIterator<T> end(Context* context)
    97             {
    98                 ObjectListBase* list = context->getObjectList<T>();
    99                 return static_cast<ObjectListElement<T>*>(list->end());
    100             }
     88            /// Returns an Iterator to the last element in the list.
     89            inline ObjectListIterator<T> rbegin()
     90            {   return static_cast<ObjectListElement<T>*>(this->list_->rbegin());   }
     91            /// Returns an Iterator to the element before the first element in the list.
     92            inline ObjectListIterator<T> rend()
     93            {   return static_cast<ObjectListElement<T>*>(this->list_->rend());   }
    10194
    102             /// Returns an Iterator to the last element in the list (for the root context).
    103             inline static ObjectListIterator<T> rbegin()
    104             {   return rbegin(Context::getRootContext());   }
    105             /// Returns an Iterator to the last element in the list.
    106             inline static ObjectListIterator<T> rbegin(Context* context)
    107             {
    108                 ObjectListBase* list = context->getObjectList<T>();
    109                 return static_cast<ObjectListElement<T>*>(list->rbegin());
    110             }
    111 
    112             /// Returns an Iterator to the element before the first element in the list (for the root context).
    113             inline static ObjectListIterator<T> rend()
    114             {   return rend(Context::getRootContext());   }
    115             /// Returns an Iterator to the element before the first element in the list.
    116             inline static ObjectListIterator<T> rend(Context* context)
    117             {
    118                 ObjectListBase* list = context->getObjectList<T>();
    119                 return static_cast<ObjectListElement<T>*>(list->rend());
    120             }
     95        private:
     96            ObjectListBase* list_;
    12197    };
    12298}
  • code/branches/cpp11_v2/src/libraries/core/object/ObjectListIterator.h

    r10769 r10920  
    4141    Usage:
    4242    @code
    43     for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)
     43    ObjectList<myClass> list;
     44    for (ObjectListIterator<myClass> it = list.begin(); it != list.end(); ++it)
    4445    {
    4546        it->someFunction(...);
  • code/branches/cpp11_v2/src/libraries/network/packet/Gamestate.cc

    r10919 r10920  
    126126  mem += GamestateHeader::getSize();
    127127  ObjectList<Synchronisable>::iterator it;
    128   for(it = ObjectList<Synchronisable>::begin(); it; ++it)
     128  for(it = ObjectList<Synchronisable>().begin(); it; ++it)
    129129  {
    130130
  • code/branches/cpp11_v2/src/modules/gametypes/SpaceRaceController.cc

    r10919 r10920  
    5959
    6060        virtualCheckPointIndex = -2;
    61         if (ObjectList<SpaceRaceManager>::size() != 1)
    62             orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>::size() << endl;
     61        if (ObjectList<SpaceRaceManager>().size() != 1)
     62            orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>().size() << endl;
    6363        for (SpaceRaceManager* manager : ObjectList<SpaceRaceManager>())
    6464        {
     
    299299        orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl;
    300300        RaceCheckPoint* newTempRaceCheckPoint;
    301         for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
     301        ObjectList<SpaceRaceManager> list;
     302        for (ObjectList<SpaceRaceManager>::iterator it = list.begin(); it!= list.end(); ++it)
    302303        {
    303304            newTempRaceCheckPoint = new RaceCheckPoint((*it));
     
    488489        std::vector<StaticEntity*> problematicObjects;
    489490
    490         for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it)
     491        ObjectList<StaticEntity> list;
     492        for (ObjectList<StaticEntity>::iterator it = list.begin(); it!= list.end(); ++it)
    491493        {
    492494
  • code/branches/cpp11_v2/src/modules/jump/Jump.cc

    r10916 r10920  
    141141        }
    142142
    143         ObjectList<JumpPlatform>::iterator beginPlatform = ObjectList<JumpPlatform>::begin();
    144         ObjectList<JumpPlatform>::iterator endPlatform = ObjectList<JumpPlatform>::end();
    145         ObjectList<JumpPlatform>::iterator itPlatform = beginPlatform;
     143        ObjectList<JumpPlatform> listPlatform;
     144        ObjectList<JumpPlatform>::iterator itPlatform = listPlatform.begin();
    146145        Vector3 platformPosition;
    147146
    148         while (itPlatform != endPlatform)
     147        while (itPlatform != listPlatform.end())
    149148        {
    150149            platformPosition = itPlatform->getPosition();
     
    163162
    164163        // Deleted deactivated platforms
    165         ObjectList<JumpPlatformDisappear>::iterator beginDisappear = ObjectList<JumpPlatformDisappear>::begin();
    166         ObjectList<JumpPlatformDisappear>::iterator endDisappear = ObjectList<JumpPlatformDisappear>::end();
    167         ObjectList<JumpPlatformDisappear>::iterator itDisappear = beginDisappear;
    168 
    169         while (itDisappear != endDisappear)
     164        ObjectList<JumpPlatformDisappear> listDisappear;
     165        ObjectList<JumpPlatformDisappear>::iterator itDisappear = listDisappear.begin();
     166
     167        while (itDisappear != listDisappear.end())
    170168        {
    171169            if (!itDisappear->isActive())
     
    182180        }
    183181
    184         ObjectList<JumpPlatformTimer>::iterator beginTimer = ObjectList<JumpPlatformTimer>::begin();
    185         ObjectList<JumpPlatformTimer>::iterator endTimer = ObjectList<JumpPlatformTimer>::end();
    186         ObjectList<JumpPlatformTimer>::iterator itTimer = beginTimer;
    187 
    188         while (itTimer != endTimer)
     182        ObjectList<JumpPlatformTimer> listTimer;
     183        ObjectList<JumpPlatformTimer>::iterator itTimer = listTimer.begin();
     184
     185        while (itTimer != listTimer.end())
    189186        {
    190187            if (!itTimer->isActive())
     
    201198        }
    202199
    203         ObjectList<JumpProjectile>::iterator beginProjectile = ObjectList<JumpProjectile>::begin();
    204         ObjectList<JumpProjectile>::iterator endProjectile = ObjectList<JumpProjectile>::end();
    205         ObjectList<JumpProjectile>::iterator itProjectile = beginProjectile;
     200        ObjectList<JumpProjectile> listProjectile;
     201        ObjectList<JumpProjectile>::iterator itProjectile = listProjectile.begin();
    206202        Vector3 projectilePosition;
    207203
    208         while (itProjectile != endProjectile)
     204        while (itProjectile != listProjectile.end())
    209205        {
    210206            projectilePosition = itProjectile->getPosition();
     
    222218        }
    223219
    224         ObjectList<JumpEnemy>::iterator beginEnemy = ObjectList<JumpEnemy>::begin();
    225         ObjectList<JumpEnemy>::iterator endEnemy = ObjectList<JumpEnemy>::end();
    226         ObjectList<JumpEnemy>::iterator itEnemy = beginEnemy;
     220        ObjectList<JumpEnemy> listEnemy;
     221        ObjectList<JumpEnemy>::iterator itEnemy = listEnemy.begin();
    227222        Vector3 enemyPosition;
    228223
    229         while (itEnemy != endEnemy)
     224        while (itEnemy != listEnemy.end())
    230225        {
    231226            enemyPosition = itEnemy->getPosition();
     
    243238        }
    244239
    245         ObjectList<JumpItem>::iterator beginItem = ObjectList<JumpItem>::begin();
    246         ObjectList<JumpItem>::iterator endItem = ObjectList<JumpItem>::end();
    247         ObjectList<JumpItem>::iterator itItem = beginItem;
     240        ObjectList<JumpItem> listItem;
     241        ObjectList<JumpItem>::iterator itItem = listItem.begin();
    248242        Vector3 itemPosition;
    249243
    250         while (itItem != endItem)
     244        while (itItem != listItem.end())
    251245        {
    252246            itemPosition = itItem->getPosition();
  • code/branches/cpp11_v2/src/modules/mini4dgame/Mini4Dgame.cc

    r10917 r10920  
    183183    void Mini4Dgame::undoStone()//Vector4 move, const int playerColor)
    184184    {
    185         ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin();
     185        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>().begin();
    186186        it->undoMove();
    187187    }
     
    191191    {
    192192        Mini4DgamePosition move = Mini4DgamePosition(x,y,z,w);
    193         ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin();
     193        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>().begin();
    194194        it->makeMove(move);
    195195    }
  • code/branches/cpp11_v2/src/modules/overlays/debugging/DebugPositionText.cc

    r9943 r10920  
    5252        SUPER(DebugPositionText, tick, dt);
    5353       
    54         ObjectList<NewHumanController>::iterator it = ObjectList<NewHumanController>::begin();
     54        ObjectList<NewHumanController>::iterator it = ObjectList<NewHumanController>().begin();
    5555        if (it && it->getControllableEntity() )
    5656        {
  • code/branches/cpp11_v2/src/orxonox/Radar.cc

    r10919 r10920  
    138138    void Radar::cycleFocus()
    139139    {
    140         if (ObjectList<RadarViewable>::begin() == ObjectList<RadarViewable>::end())
     140        ObjectList<RadarViewable> listRadarViewable;
     141        if (listRadarViewable.size() == 0)
    141142        {
    142143            // list is empty
     
    158159            ObjectList<RadarViewable>::iterator itFallback = nullptr;
    159160
    160             for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it)
     161            for (ObjectList<RadarViewable>::iterator it = listRadarViewable.begin(); it; ++it)
    161162            {
    162163                if (*it == static_cast<RadarViewable*>(HumanController::getLocalControllerEntityAsPawn()))
  • code/branches/cpp11_v2/src/orxonox/gamestates/GSLevel.cc

    r10919 r10920  
    215215    void GSLevel::unloadLevelAsClient()
    216216    {
    217         for (ObjectList<Level>::iterator it = ObjectList<Level>::begin(); it != ObjectList<Level>::end(); )
     217        ObjectList<Level> listLevel;
     218        for (ObjectList<Level>::iterator it = listLevel.begin(); it != listLevel.end(); )
    218219        {
    219220            StrongPtr<Level> level = *(it++); // StrongPtr prevents that the Level gets destroyed while we loop over it
    220             for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(level); it != ObjectList<BaseObject>::end(level); )
     221            ObjectList<BaseObject> listBaseObject(level);
     222            for (ObjectList<BaseObject>::iterator it = listBaseObject.begin(); it != listBaseObject.end(); )
    221223                (it++)->destroy();
    222224        }
    223225
    224         for (ObjectList<Synchronisable>::iterator it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); )
     226        ObjectList<Synchronisable> listSynchronisable;
     227        for (ObjectList<Synchronisable>::iterator it = listSynchronisable.begin(); it != listSynchronisable.end(); )
    225228        {
    226229            if (it->getSyncMode() != 0x0)
  • code/branches/cpp11_v2/src/orxonox/gamestates/GSRoot.cc

    r10919 r10920  
    113113        }
    114114
    115         for (ObjectList<Timer>::iterator it = ObjectList<Timer>::begin(); it; )
     115        ObjectList<Timer> listTimer;
     116        for (ObjectList<Timer>::iterator it = listTimer.begin(); it; )
    116117        {
    117118            Timer* object = *it;
     
    129130        }
    130131        float realdt = leveldt * TimeFactorListener::getTimeFactor();
    131         for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; )
     132        ObjectList<Tickable> listTickable;
     133        for (ObjectList<Tickable>::iterator it = listTickable.begin(); it; )
    132134        {
    133135            Tickable* object = *it;
  • code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.cc

    r10919 r10920  
    492492    {
    493493        unsigned int i = 0;
    494         for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); )
     494        ObjectList<Bot> list;
     495        for (ObjectList<Bot>::iterator it = list.begin(); (it != list.end()) && ((amount == 0) || (i < amount)); )
    495496        {
    496497            if (it->getGametype() == this)
Note: See TracChangeset for help on using the changeset viewer.