Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10920


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
Files:
18 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)
  • code/branches/cpp11_v2/test/core/object/IteratorTest.cc

    r10846 r10920  
    5555    TEST_F(IteratorTest, CanAssignIterator)
    5656    {
    57         Iterator<TestInterface> it = ObjectList<TestInterface>::begin();
     57        ObjectList<TestInterface> list;
     58        Iterator<TestInterface> it = list.begin();
    5859    }
    5960
     
    6162    {
    6263        size_t i = 0;
    63         for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
     64        ObjectList<TestInterface> list;
     65        for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it)
    6466            ++i;
    6567        EXPECT_EQ(0u, i);
     
    7779
    7880        // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test()
    79         for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
     81        ObjectList<TestInterface> list;
     82        for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it)
    8083            it->test();
    8184    }
     
    8790
    8891        size_t i = 0;
    89         for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
     92        ObjectList<TestInterface> list;
     93        for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it)
    9094        {
    9195            ++i;
     
    102106
    103107        size_t i = 0;
    104         for (Iterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it)
     108        ObjectList<TestClass> list;
     109        for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it)
    105110        {
    106111            ++i;
     
    116121
    117122        size_t i = 0;
    118         for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it)
     123        ObjectList<TestInterface> list;
     124        for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it)
    119125        {
    120126            ++i;
     
    131137
    132138        size_t i = 0;
    133         for (Iterator<TestInterface> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it)
     139        ObjectList<TestClass> list;
     140        for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it)
    134141        {
    135142            ++i;
  • code/branches/cpp11_v2/test/core/object/ListableTest.cc

    r10846 r10920  
    6363    {
    6464        ListableClassTest test;
    65         EXPECT_EQ(1u, ObjectList<ListableClassTest>::size());
     65        EXPECT_EQ(1u, ObjectList<ListableClassTest>().size());
    6666        EXPECT_TRUE(objectListContains<ListableClassTest>(&test));
    6767    }
     
    7070    {
    7171        ListableSubclassTest test;
    72         EXPECT_EQ(1u, ObjectList<ListableClassTest>::size());
     72        EXPECT_EQ(1u, ObjectList<ListableClassTest>().size());
    7373        EXPECT_TRUE(objectListContains<ListableClassTest>(&test));
    74         EXPECT_EQ(1u, ObjectList<ListableSubclassTest>::size());
     74        EXPECT_EQ(1u, ObjectList<ListableSubclassTest>().size());
    7575        EXPECT_TRUE(objectListContains<ListableSubclassTest>(&test));
    7676    }
     
    7878    TEST_F(ListableTest, RemovesFromObjectList)
    7979    {
    80         EXPECT_EQ(0u, ObjectList<ListableClassTest>::size());
     80        EXPECT_EQ(0u, ObjectList<ListableClassTest>().size());
    8181        {
    8282            ListableClassTest test;
    83             EXPECT_EQ(1u, ObjectList<ListableClassTest>::size());
     83            EXPECT_EQ(1u, ObjectList<ListableClassTest>().size());
    8484            EXPECT_TRUE(objectListContains<ListableClassTest>(&test));
    8585        }
    86         EXPECT_EQ(0u, ObjectList<ListableClassTest>::size());
     86        EXPECT_EQ(0u, ObjectList<ListableClassTest>().size());
    8787    }
    8888
    8989    TEST_F(ListableTest, RemovesFromAllObjectLists)
    9090    {
    91         EXPECT_EQ(0u, ObjectList<ListableClassTest>::size());
    92         EXPECT_EQ(0u, ObjectList<ListableSubclassTest>::size());
     91        EXPECT_EQ(0u, ObjectList<ListableClassTest>().size());
     92        EXPECT_EQ(0u, ObjectList<ListableSubclassTest>().size());
    9393        {
    9494            ListableSubclassTest test;
    95             EXPECT_EQ(1u, ObjectList<ListableClassTest>::size());
     95            EXPECT_EQ(1u, ObjectList<ListableClassTest>().size());
    9696            EXPECT_TRUE(objectListContains<ListableClassTest>(&test));
    97             EXPECT_EQ(1u, ObjectList<ListableSubclassTest>::size());
     97            EXPECT_EQ(1u, ObjectList<ListableSubclassTest>().size());
    9898            EXPECT_TRUE(objectListContains<ListableSubclassTest>(&test));
    9999        }
    100         EXPECT_EQ(0u, ObjectList<ListableClassTest>::size());
    101         EXPECT_EQ(0u, ObjectList<ListableSubclassTest>::size());
     100        EXPECT_EQ(0u, ObjectList<ListableClassTest>().size());
     101        EXPECT_EQ(0u, ObjectList<ListableSubclassTest>().size());
    102102    }
    103103
  • code/branches/cpp11_v2/test/core/object/ObjectListIteratorTest.cc

    r10846 r10920  
    5555    TEST_F(ObjectListIteratorTest, CanAssignIterator)
    5656    {
    57         ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin();
     57        ObjectList<TestClass> list;
     58        ObjectListIterator<TestClass> it = list.begin();
    5859    }
    5960
     
    6162    {
    6263        size_t i = 0;
    63         for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it)
     64        ObjectList<TestClass> list;
     65        for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
    6466            ++i;
    6567        EXPECT_EQ(0u, i);
     
    7476
    7577        size_t i = 0;
    76         for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it)
     78        ObjectList<TestClass> list;
     79        for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
    7780        {
    7881            ++i;
     
    9295
    9396        size_t i = 0;
    94         for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::rbegin(); it != ObjectList<TestClass>::rend(); --it)
     97        ObjectList<TestClass> list;
     98        for (ObjectListIterator<TestClass> it = list.rbegin(); it != list.rend(); --it)
    9599        {
    96100            ++i;
     
    113117        EXPECT_CALL(test3, test());
    114118
    115         for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it)
     119        ObjectList<TestClass> list;
     120        for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it)
    116121            it->test();
    117122    }
  • code/branches/cpp11_v2/test/core/object/ObjectListTest.cc

    r10846 r10920  
    1515            public:
    1616                ListableTest() { RegisterObject(ListableTest); }
     17                ListableTest(Context* context) : Listable(context) { RegisterObject(ListableTest); }
    1718                MOCK_METHOD0(test, void());
    1819        };
     
    103104            object->test();
    104105    }
     106
     107    TEST_F(ObjectListTest, UsesCorrectContext)
     108    {
     109        Context context1(Context::getRootContext());
     110        Context context2(Context::getRootContext());
     111
     112        ListableTest test1(&context1);
     113        ListableTest test2(&context1);
     114        ListableTest test3(&context2);
     115
     116        EXPECT_EQ(3, ObjectList<ListableTest>().size());
     117        EXPECT_EQ(2, ObjectList<ListableTest>(&context1).size());
     118        EXPECT_EQ(1, ObjectList<ListableTest>(&context2).size());
     119    }
     120
     121    TEST_F(ObjectListTest, CanIterateOverCorrectContext)
     122    {
     123        Context context1(Context::getRootContext());
     124        Context context2(Context::getRootContext());
     125
     126        ListableTest test1(&context1);
     127        ListableTest test2(&context1);
     128        ListableTest test3(&context2);
     129
     130        {
     131            size_t i = 0;
     132            for (ListableTest* object : ObjectList<ListableTest>(&context1))
     133            {
     134                ++i;
     135                if (i == 1u) EXPECT_EQ(&test1, object);
     136                if (i == 2u) EXPECT_EQ(&test2, object);
     137            }
     138            EXPECT_EQ(2u, i);
     139        }
     140        {
     141            size_t i = 0;
     142            for (ListableTest* object : ObjectList<ListableTest>(&context2))
     143            {
     144                ++i;
     145                if (i == 1u) EXPECT_EQ(&test3, object);
     146            }
     147            EXPECT_EQ(1u, i);
     148        }
     149    }
    105150}
Note: See TracChangeset for help on using the changeset viewer.