Changeset 10736
- Timestamp:
- Oct 31, 2015, 11:50:17 PM (9 years ago)
- Location:
- code/branches/cpp11_v2
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/core/object/Iterator.h
r10624 r10736 79 79 80 80 /** 81 @brief Constructor: Sets this element to a given element82 @param element The element83 */84 inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {}85 86 /**87 81 @brief Constructor: Sets this element to the element of another Iterator. 88 82 @param other The other Iterator 89 83 */ 90 inline Iterator(const IteratorBase<T, Iterator<T> >& other) : IteratorBase<T, Iterator<T> >(other) {} 84 template <class OT, class OI> 85 inline Iterator(const IteratorBase<OT, OI>& other) : IteratorBase<T, Iterator<T> >(other) {} 91 86 92 87 /** -
code/branches/cpp11_v2/src/libraries/core/object/IteratorBase.h
r10624 r10736 54 54 BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value)); 55 55 56 p rotected:56 public: 57 57 /** 58 58 @brief Constructor: Sets the element, whereon the iterator points, to the given element. 59 This constructor is protected and only for internal usage (don't mess with the BaseElements directly). 60 */ 61 inline IteratorBase(ObjectListBaseElement* element = NULL) 59 */ 60 inline IteratorBase(ObjectListElement<T>* element = NULL) 62 61 { 63 62 this->element_ = element; … … 65 64 } 66 65 67 68 public:69 /**70 @brief Constructor: Sets the element, whereon the iterator points, to the given element.71 */72 inline IteratorBase(ObjectListElement<T>* element)73 {74 this->element_ = element;75 this->registerIterator();76 }77 78 66 /** 79 67 @brief Constructor: Sets the element, whereon the iterator points, to the given element of another type. 80 68 The element's type O must be a derivative of the Iterator's type T. 81 69 */ 82 template <class O> 83 inline IteratorBase(ObjectListElement<O>* element) 84 { 85 (void)static_cast<T*>((O*)NULL); // Check type: The element's type O must be a derivative of the Iterator's type T. 86 this->element_ = element; 87 this->registerIterator(); 88 } 89 90 /** 91 @brief Constructor: Sets this element to the element of another Iterator. 92 @param other The other Iterator 93 */ 94 inline IteratorBase(const IteratorBase& other) 95 { 96 this->element_ = other.element_; 70 template <class OT, class OI> 71 inline IteratorBase(const IteratorBase<OT, OI>& other) 72 { 73 this->element_ = other.getElement(); 97 74 this->registerIterator(); 98 75 } … … 205 182 if (this->element_ == element) 206 183 this->operator++(); 184 } 185 186 inline ObjectListBaseElement* getElement() const 187 { 188 return this->element_; 207 189 } 208 190 -
code/branches/cpp11_v2/src/libraries/core/object/ObjectList.h
r10624 r10736 84 84 85 85 /// Returns an Iterator to the first element in the list (for the root context). 86 inline static ObjectList Element<T>*begin()86 inline static ObjectListIterator<T> begin() 87 87 { return begin(Context::getRootContext()); } 88 88 /// Returns an Iterator to the first element in the list. 89 inline static ObjectList Element<T>*begin(Context* context)89 inline static ObjectListIterator<T> begin(Context* context) 90 90 { 91 91 ObjectListBase* list = context->getObjectList<T>(); … … 94 94 95 95 /// Returns an Iterator to the element after the last element in the list (for the root context). 96 inline static ObjectList Element<T>*end()96 inline static ObjectListIterator<T> end() 97 97 { return end(Context::getRootContext()); } 98 98 /// Returns an Iterator to the element after the last element in the list. 99 inline static ObjectList Element<T>*end(Context* context)99 inline static ObjectListIterator<T> end(Context* context) 100 100 { 101 101 ObjectListBase* list = context->getObjectList<T>(); … … 104 104 105 105 /// Returns an Iterator to the last element in the list (for the root context). 106 inline static ObjectList Element<T>*rbegin()106 inline static ObjectListIterator<T> rbegin() 107 107 { return rbegin(Context::getRootContext()); } 108 108 /// Returns an Iterator to the last element in the list. 109 inline static ObjectList Element<T>*rbegin(Context* context)109 inline static ObjectListIterator<T> rbegin(Context* context) 110 110 { 111 111 ObjectListBase* list = context->getObjectList<T>(); … … 114 114 115 115 /// Returns an Iterator to the element before the first element in the list (for the root context). 116 inline static ObjectList Element<T>*rend()116 inline static ObjectListIterator<T> rend() 117 117 { return rend(Context::getRootContext()); } 118 118 /// Returns an Iterator to the element before the first element in the list. 119 inline static ObjectList Element<T>*rend(Context* context)119 inline static ObjectListIterator<T> rend(Context* context) 120 120 { 121 121 ObjectListBase* list = context->getObjectList<T>(); -
code/branches/cpp11_v2/src/libraries/core/object/ObjectListBase.h
r10733 r10736 93 93 } 94 94 95 operator T*()96 {97 return object_;98 }99 100 95 T* object_; //!< The object 101 96 }; -
code/branches/cpp11_v2/src/libraries/core/object/ObjectListIterator.h
r10624 r10736 86 86 @param other The other ObjectListIterator 87 87 */ 88 inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {} 88 template <class OI> 89 inline ObjectListIterator(const IteratorBase<T, OI>& other) : IteratorBase<T, ObjectListIterator<T> >(other) {} 89 90 90 91 /** -
code/branches/cpp11_v2/test/core/CMakeLists.txt
r10624 r10736 25 25 object/ListableTest.cc 26 26 object/ObjectListBaseTest.cc 27 object/ObjectListTest.cc 27 28 object/ObjectListIteratorTest.cc 28 29 object/StrongPtrTest.cc -
code/branches/cpp11_v2/test/core/object/IteratorTest.cc
r10624 r10736 80 80 it->test(); 81 81 } 82 83 TEST_F(IteratorTest, CanIterateOverInterfaceListWithInterfaceIterator) 84 { 85 TestClass testClass; 86 TestInterface testInterface; 87 88 size_t i = 0; 89 for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) 90 { 91 ++i; 92 if (i == 1u) EXPECT_EQ(&testClass, *it); 93 if (i == 2u) EXPECT_EQ(&testInterface, *it); 94 } 95 EXPECT_EQ(2u, i); 96 } 97 98 TEST_F(IteratorTest, CanIterateOverClassListWithClassIterator) 99 { 100 TestClass testClass; 101 TestInterface testInterface; 102 103 size_t i = 0; 104 for (Iterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it) 105 { 106 ++i; 107 if (i == 1u) EXPECT_EQ(&testClass, *it); 108 } 109 EXPECT_EQ(1u, i); 110 } 111 112 TEST_F(IteratorTest, CanIterateOverInterfaceListWithClassIterator) 113 { 114 TestClass testClass; 115 TestInterface testInterface; 116 117 size_t i = 0; 118 for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) 119 { 120 ++i; 121 if (i == 1u) EXPECT_EQ(&testClass, *it); 122 if (i == 2u) EXPECT_EQ(NULL, *it); 123 } 124 EXPECT_EQ(2u, i); 125 } 126 127 TEST_F(IteratorTest, CanIterateOverClassListWithInterfaceIterator) 128 { 129 TestClass testClass; 130 TestInterface testInterface; 131 132 size_t i = 0; 133 for (Iterator<TestInterface> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it) 134 { 135 ++i; 136 if (i == 1u) EXPECT_EQ(&testClass, *it); 137 } 138 EXPECT_EQ(1u, i); 139 } 82 140 } -
code/branches/cpp11_v2/test/core/object/ObjectListIteratorTest.cc
r10624 r10736 3 3 4 4 #include "core/object/ObjectListIterator.h" 5 #include "core/object/Listable.h" 5 #include "core/class/OrxonoxClass.h" 6 #include "core/class/OrxonoxInterface.h" 6 7 #include "core/CoreIncludes.h" 7 8 #include "core/module/ModuleInstance.h" … … 11 12 namespace 12 13 { 13 class ListableTest : public Listable14 class TestInterface : virtual public OrxonoxInterface 14 15 { 15 16 public: 16 ListableTest() { RegisterObject(ListableTest); } 17 TestInterface() { RegisterObject(TestInterface); } 18 }; 19 20 class TestClass : public OrxonoxClass, public TestInterface 21 { 22 public: 23 TestClass() { RegisterObject(TestClass); } 17 24 MOCK_METHOD0(test, void()); 18 25 }; 19 26 20 RegisterClassNoArgs(ListableTest); 27 RegisterClassNoArgs(TestInterface); 28 RegisterClassNoArgs(TestClass); 21 29 22 30 // Fixture … … 42 50 TEST_F(ObjectListIteratorTest, CanCreateIterator) 43 51 { 44 ObjectListIterator< ListableTest> it;52 ObjectListIterator<TestClass> it; 45 53 } 46 54 47 55 TEST_F(ObjectListIteratorTest, CanAssignIterator) 48 56 { 49 ObjectListIterator< ListableTest> it = ObjectList<ListableTest>::begin();57 ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); 50 58 } 51 59 … … 53 61 { 54 62 size_t i = 0; 55 for (ObjectListIterator< ListableTest> it = ObjectList<ListableTest>::begin(); it != ObjectList<ListableTest>::end(); ++it)63 for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it) 56 64 ++i; 57 65 EXPECT_EQ(0u, i); … … 60 68 TEST_F(ObjectListIteratorTest, CanIterateOverFullList) 61 69 { 62 ListableTest test1; 63 ListableTest test2; 64 ListableTest test3; 70 TestClass test1; 71 TestClass test2; 72 TestClass test3; 73 TestInterface interface; 65 74 66 75 size_t i = 0; 67 for (ObjectListIterator< ListableTest> it = ObjectList<ListableTest>::begin(); it != ObjectList<ListableTest>::end(); ++it)76 for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it) 68 77 { 69 78 ++i; … … 77 86 TEST_F(ObjectListIteratorTest, CanIterateReverseOverFullList) 78 87 { 79 ListableTest test1; 80 ListableTest test2; 81 ListableTest test3; 88 TestClass test1; 89 TestClass test2; 90 TestClass test3; 91 TestInterface interface; 82 92 83 93 size_t i = 0; 84 for (ObjectListIterator< ListableTest> it = ObjectList<ListableTest>::rbegin(); it != ObjectList<ListableTest>::rend(); --it)94 for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::rbegin(); it != ObjectList<TestClass>::rend(); --it) 85 95 { 86 96 ++i; … … 94 104 TEST_F(ObjectListIteratorTest, CanCallObjects) 95 105 { 96 ListableTest test1; 97 ListableTest test2; 98 ListableTest test3; 106 TestClass test1; 107 TestClass test2; 108 TestClass test3; 109 TestInterface interface; 99 110 100 111 EXPECT_CALL(test1, test()); … … 102 113 EXPECT_CALL(test3, test()); 103 114 104 for (ObjectListIterator< ListableTest> it = ObjectList<ListableTest>::begin(); it != ObjectList<ListableTest>::end(); ++it)115 for (ObjectListIterator<TestClass> it = ObjectList<TestClass>::begin(); it != ObjectList<TestClass>::end(); ++it) 105 116 it->test(); 106 117 }
Note: See TracChangeset
for help on using the changeset viewer.