Changeset 9651 for code/branches
- Timestamp:
- Aug 16, 2013, 9:20:59 PM (11 years ago)
- Location:
- code/branches/core6
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/class/Identifier.h
r9646 r9651 409 409 void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable) 410 410 { 411 listable->getContext()->addObject(object); 411 if (listable->getContext()) 412 listable->getContext()->addObject(object); 412 413 } 413 414 -
code/branches/core6/src/libraries/core/class/IdentifierManager.cc
r9646 r9651 127 127 initializedIdentifiers.insert(it->second); 128 128 } 129 130 size_t numberOfObjects = temporaryContext.getObjectList<Listable>()->size(); 131 if (numberOfObjects > 0) 132 orxout(internal_warning) << "There are still " << numberOfObjects << " listables left after creating the class hierarchy" << endl; 129 133 } 130 134 -
code/branches/core6/src/libraries/core/object/Context.cc
r9650 r9651 42 42 Context* Context::rootContext_s = 0; 43 43 44 Context ::Context(Context* context) : Listable(this), parentContext_(context)44 Context* getContextForInitializationOfOtherContexts() 45 45 { 46 // we have to call Listable(this) to avoid circular initialization when creating a Context because Listable calls Context::getRootContext() by 47 // default AND we have to set the context again in the constructor because of other classes inheriting from Context (Listable is a virtual base 48 // and each subclass must call its constructor individually, so either all subclasses add Listable(this) to their initialization list or we call 49 // setContext(this) here). 46 static size_t count = 0; 47 // the first time this is called, ++count returns 1 and the context is created 48 // the second time this is called, ++count returns 2 and NULL is returned because we're in the constructor of the context itself 49 // for each future call the context (now completely created) is returned 50 if (++count == 2) 51 return NULL; 52 else 53 { 54 static Context context(NULL); 55 return &context; 56 } 57 } 58 59 // Initialize Listable(*) with a special context, only used to initialize other contexts. Later in the constructor we change the context 60 Context::Context(Context* context) : Listable(getContextForInitializationOfOtherContexts()), parentContext_(context) 61 { 62 RegisterObject(Context); 63 64 // the context is its own context 50 65 this->setContext(this); 51 52 RegisterObject(Context);53 66 } 54 67 -
code/branches/core6/src/libraries/core/object/Listable.cc
r9627 r9651 33 33 34 34 #include "Listable.h" 35 #include "core/CoreIncludes.h" 35 36 #include "ObjectListBase.h" 36 37 #include "Context.h" … … 38 39 namespace orxonox 39 40 { 41 RegisterClass(Listable); 42 40 43 /** 41 44 @brief Constructor: Allocates space in the element list. … … 45 48 this->context_ = Context::getRootContext(); 46 49 this->elements_.reserve(6); 50 51 RegisterObject(Listable); 47 52 } 48 53 49 54 /** 50 @brief Constructor: Allocates space in the element list and assign es the context55 @brief Constructor: Allocates space in the element list and assigns the context 51 56 */ 52 57 Listable::Listable(Context* context) … … 54 59 this->context_ = context; 55 60 this->elements_.reserve(6); 61 62 RegisterObject(Listable); 56 63 } 57 64 … … 80 87 void Listable::setContext(Context* context) 81 88 { 89 assert(context); 82 90 std::vector<ObjectListBaseElement*> copy = this->elements_; 83 91 this->elements_.clear(); -
code/branches/core6/test/core/class/IdentifierClassHierarchyTest.cc
r9646 r9651 130 130 virtual void SetUp() 131 131 { 132 registerClass("Context", new ClassFactoryWithContext<Context>()); 133 registerClass("Listable", new ClassFactoryWithContext<Listable>()); 132 134 registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>()); 133 135 registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>()); … … 230 232 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface))); 231 233 232 EXPECT_EQ(2u, identifier->getParents().size()); 233 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 234 EXPECT_EQ(3u, identifier->getParents().size()); 235 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 236 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 234 237 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); 235 238 } … … 252 255 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface))); 253 256 254 EXPECT_EQ(2u, identifier->getParents().size()); 255 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 257 EXPECT_EQ(3u, identifier->getParents().size()); 258 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 259 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 256 260 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); 257 261 } … … 274 278 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseInterface1))); 275 279 276 EXPECT_EQ(3u, identifier->getParents().size()); 277 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 280 EXPECT_EQ(4u, identifier->getParents().size()); 281 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 282 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 278 283 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); 279 284 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseInterface1))); … … 295 300 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseInterface2))); 296 301 297 EXPECT_EQ(3u, identifier->getParents().size()); 298 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 302 EXPECT_EQ(4u, identifier->getParents().size()); 303 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 304 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 299 305 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); 300 306 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseInterface2))); … … 322 328 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); 323 329 324 EXPECT_EQ(2u, identifier->getParents().size()); 325 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 330 EXPECT_EQ(3u, identifier->getParents().size()); 331 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 332 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 326 333 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 327 334 } … … 338 345 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); 339 346 340 EXPECT_EQ(3u, identifier->getParents().size()); 341 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 347 EXPECT_EQ(4u, identifier->getParents().size()); 348 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 349 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 342 350 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 343 351 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); … … 356 364 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface1))); 357 365 358 EXPECT_EQ(6u, identifier->getParents().size()); 359 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 366 EXPECT_EQ(7u, identifier->getParents().size()); 367 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 368 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 360 369 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 361 370 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); … … 378 387 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface2))); 379 388 380 EXPECT_EQ(8u, identifier->getParents().size()); 381 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 389 EXPECT_EQ(9u, identifier->getParents().size()); 390 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 391 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 382 392 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 383 393 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); … … 402 412 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(Interface2))); 403 413 404 EXPECT_EQ(8u, identifier->getParents().size()); 405 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 414 EXPECT_EQ(9u, identifier->getParents().size()); 415 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 416 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 406 417 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 407 418 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); … … 426 437 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseInterface2))); 427 438 428 EXPECT_EQ(6u, identifier->getParents().size()); 429 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 439 EXPECT_EQ(7u, identifier->getParents().size()); 440 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 441 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 430 442 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 431 443 EXPECT_TRUE(contains(identifier->getParents(), Class(BaseClass))); -
code/branches/core6/test/core/class/IdentifierSimpleClassHierarchyTest.cc
r9646 r9651 46 46 virtual void SetUp() 47 47 { 48 registerClass("Context", new ClassFactoryWithContext<Context>()); 49 registerClass("Listable", new ClassFactoryWithContext<Listable>()); 48 50 registerClass("OrxonoxInterface", new ClassFactoryNoArgs<OrxonoxInterface>()); 49 51 registerClass("OrxonoxClass", new ClassFactoryNoArgs<OrxonoxClass>()); … … 99 101 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxInterface))); 100 102 101 EXPECT_EQ( 2u, identifier->getParents().size());103 EXPECT_EQ(3u, identifier->getParents().size()); 102 104 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 105 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 103 106 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); 104 107 } … … 117 120 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(OrxonoxClass))); 118 121 119 EXPECT_EQ( 2u, identifier->getParents().size());122 EXPECT_EQ(3u, identifier->getParents().size()); 120 123 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 124 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 121 125 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass))); 122 126 } … … 134 138 EXPECT_TRUE(contains(identifier->getDirectParents(), Class(BaseClass))); 135 139 136 EXPECT_EQ( 5u, identifier->getParents().size());140 EXPECT_EQ(6u, identifier->getParents().size()); 137 141 EXPECT_TRUE(contains(identifier->getParents(), Class(Identifiable))); 142 EXPECT_TRUE(contains(identifier->getParents(), Class(Listable))); 138 143 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxInterface))); 139 144 EXPECT_TRUE(contains(identifier->getParents(), Class(OrxonoxClass)));
Note: See TracChangeset
for help on using the changeset viewer.