[Orxonox-commit 5712] r10372 - in code/branches/core7: src/libraries/core/class test/core/class

landauf at orxonox.net landauf at orxonox.net
Sat Apr 18 13:07:09 CEST 2015


Author: landauf
Date: 2015-04-18 13:07:08 +0200 (Sat, 18 Apr 2015)
New Revision: 10372

Modified:
   code/branches/core7/src/libraries/core/class/Identifier.cc
   code/branches/core7/src/libraries/core/class/Identifier.h
   code/branches/core7/src/libraries/core/class/IdentifierManager.cc
   code/branches/core7/src/libraries/core/class/IdentifierManager.h
   code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc
   code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc
   code/branches/core7/test/core/class/IdentifierNestedClassHierarchyTest.cc
   code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc
   code/branches/core7/test/core/class/SuperTest.cc
Log:
use lists instead of sets to store parent identifiers. this allows to store the exact order of initialization of parent classes.

Modified: code/branches/core7/src/libraries/core/class/Identifier.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/src/libraries/core/class/Identifier.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -134,7 +134,7 @@
     Identifier& Identifier::inheritsFrom(Identifier* directParent)
     {
         if (this->parents_.empty())
-            this->directParents_.insert(directParent);
+            this->directParents_.push_back(directParent);
         else
             orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl;
 
@@ -145,7 +145,7 @@
      * @brief Initializes the parents of this Identifier while creating the class hierarchy.
      * @param initializationTrace All identifiers that were recorded while creating an instance of this class (including nested classes and this identifier itself)
      */
-    void Identifier::initializeParents(const std::set<const Identifier*>& initializationTrace)
+    void Identifier::initializeParents(const std::list<const Identifier*>& initializationTrace)
     {
         if (!IdentifierManager::getInstance().isCreatingHierarchy())
         {
@@ -155,9 +155,9 @@
 
         if (this->directParents_.empty())
         {
-            for (std::set<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)
+            for (std::list<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)
                 if (*it != this)
-                    this->parents_.insert(*it);
+                    this->parents_.push_back(*it);
         }
         else
             orxout(internal_error) << "Trying to add parents to " << this->getName() << " after it was already initialized with manual calls to inheritsFrom<Class>()." << endl;
@@ -182,29 +182,29 @@
             // parents defined -> this class was initialized by creating a sample instance and recording the trace of identifiers
 
             // initialize all parents
-            for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
+            for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
                 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
 
             // parents of parents are no direct parents of this identifier
             this->directParents_ = this->parents_;
-            for (std::set<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
-                for (std::set<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
-                    this->directParents_.erase(*it_parent_parent);
+            for (std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)
+                for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
+                    this->directParents_.remove(*it_parent_parent);
         }
         else if (!this->directParents_.empty())
         {
             // no parents defined -> this class was manually initialized by calling inheritsFrom<Class>()
 
             // initialize all direct parents
-            for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
+            for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
                 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
 
             // direct parents and their parents are also parents of this identifier (but only add them once)
             this->parents_ = this->directParents_;
-            for (std::set<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
-                for (std::set<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
+            for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
+                for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
                     if (std::find(this->parents_.begin(), this->parents_.end(), *it_parent_parent) == this->parents_.end())
-                        this->parents_.insert(*it_parent_parent);
+                        this->parents_.push_back(*it_parent_parent);
         }
         else if (!this->isExactlyA(Class(Identifiable)))
         {
@@ -215,11 +215,11 @@
         }
 
         // tell all parents that this identifier is a child
-        for (std::set<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
+        for (std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)
             const_cast<Identifier*>(*it)->children_.insert(this);
 
         // tell all direct parents that this identifier is a direct child
-        for (std::set<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
+        for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
         {
             const_cast<Identifier*>(*it)->directChildren_.insert(this);
 
@@ -254,7 +254,7 @@
     */
     bool Identifier::isChildOf(const Identifier* identifier) const
     {
-        return (this->parents_.find(identifier) != this->parents_.end());
+        return (std::find(this->parents_.begin(), this->parents_.end(),  identifier) != this->parents_.end());
     }
 
     /**
@@ -263,7 +263,7 @@
     */
     bool Identifier::isDirectChildOf(const Identifier* identifier) const
     {
-        return (this->directParents_.find(identifier) != this->directParents_.end());
+        return (std::find(this->directParents_.begin(), this->directParents_.end(), identifier) != this->directParents_.end());
     }
 
     /**

Modified: code/branches/core7/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.h	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/src/libraries/core/class/Identifier.h	2015-04-18 11:07:08 UTC (rev 10372)
@@ -147,7 +147,7 @@
             /////////////////////////////
             Identifier& inheritsFrom(Identifier* directParent);
 
-            void initializeParents(const std::set<const Identifier*>& initializationTrace);
+            void initializeParents(const std::list<const Identifier*>& initializationTrace);
             void finishInitialization();
 
             bool isA(const Identifier* identifier) const;
@@ -158,11 +158,11 @@
             bool isDirectParentOf(const Identifier* identifier) const;
 
             /// Returns the parents of the class the Identifier belongs to.
-            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
+            inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
             /// Returns the children of the class the Identifier belongs to.
             inline const std::set<const Identifier*>& getChildren() const { return this->children_; }
             /// Returns the direct parents of the class the Identifier belongs to.
-            inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
+            inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
             /// Returns the direct children the class the Identifier belongs to.
             inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; }
 
@@ -208,10 +208,10 @@
             virtual void createSuperFunctionCaller() const = 0;
 
         private:
-            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
+            std::list<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to (sorted by their order of initialization)
             std::set<const Identifier*> children_;                         //!< The children of the class the Identifier belongs to
 
-            std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
+            std::list<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to (sorted by their order of initialization)
             std::set<const Identifier*> directChildren_;                   //!< The direct children of the class the Identifier belongs to
 
             bool bInitialized_;                                            //!< Is true if the Identifier was completely initialized

Modified: code/branches/core7/src/libraries/core/class/IdentifierManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/IdentifierManager.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/src/libraries/core/class/IdentifierManager.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -215,11 +215,13 @@
         {
             if (this->recordTraceForIdentifier_)
             {
-                if (this->identifierTraceOfNewObject_[identifiable].insert(identifiable->getIdentifier()).second == false)
+                std::list<const Identifier*>& traceForObject = this->identifierTraceOfNewObject_[identifiable];
+                if (std::find(traceForObject.begin(), traceForObject.end(), identifiable->getIdentifier()) != traceForObject.end())
                 {
                     orxout(internal_warning) << this->recordTraceForIdentifier_->getName() << " inherits two times from " <<
                         identifiable->getIdentifier()->getName() << ". Did you forget to use virtual inheritance?" << endl;
                 }
+                traceForObject.push_back(identifiable->getIdentifier());
             }
         }
         else

Modified: code/branches/core7/src/libraries/core/class/IdentifierManager.h
===================================================================
--- code/branches/core7/src/libraries/core/class/IdentifierManager.h	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/src/libraries/core/class/IdentifierManager.h	2015-04-18 11:07:08 UTC (rev 10372)
@@ -37,7 +37,7 @@
 #include "core/CorePrereqs.h"
 
 #include <map>
-#include <set>
+#include <list>
 #include <string>
 
 namespace orxonox
@@ -110,7 +110,7 @@
 
             /// Used while creating the object hierarchy to keep track of the identifiers of a newly created object (and all other objects that get created as
             /// a consequence of this, e.g. nested member objects).
-            std::map<Identifiable*, std::set<const Identifier*> > identifierTraceOfNewObject_;
+            std::map<Identifiable*, std::list<const Identifier*> > identifierTraceOfNewObject_;
             Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded.
     };
 }

Modified: code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/test/core/class/IdentifierClassHierarchyTest.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -18,7 +18,7 @@
 
     namespace
     {
-        class BaseInterface1 : public OrxonoxInterface
+        class BaseInterface1 : virtual public OrxonoxInterface
         {
             public:
                 BaseInterface1()
@@ -29,7 +29,7 @@
                 virtual void test1() = 0;
         };
 
-        class BaseInterface2 : public OrxonoxInterface
+        class BaseInterface2 : virtual public OrxonoxInterface
         {
             public:
                 BaseInterface2()
@@ -154,6 +154,11 @@
                 }
         };
 
+        bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier)
+        {
+            return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end();
+        }
+
         bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier)
         {
             return identifiers.find(identifier) != identifiers.end();

Modified: code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/test/core/class/IdentifierExternalClassHierarchyTest.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -58,6 +58,11 @@
                 }
         };
 
+        bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier)
+        {
+            return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end();
+        }
+
         bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier)
         {
             return identifiers.find(identifier) != identifiers.end();

Modified: code/branches/core7/test/core/class/IdentifierNestedClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierNestedClassHierarchyTest.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/test/core/class/IdentifierNestedClassHierarchyTest.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -120,6 +120,11 @@
                 }
         };
 
+        bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier)
+        {
+            return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end();
+        }
+
         bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier)
         {
             return identifiers.find(identifier) != identifiers.end();

Modified: code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc
===================================================================
--- code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/test/core/class/IdentifierSimpleClassHierarchyTest.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -63,6 +63,11 @@
                 }
         };
 
+        bool contains(const std::list<const Identifier*> identifiers, Identifier* identifier)
+        {
+            return std::find(identifiers.begin(), identifiers.end(), identifier) != identifiers.end();
+        }
+
         bool contains(const std::set<const Identifier*> identifiers, Identifier* identifier)
         {
             return identifiers.find(identifier) != identifiers.end();

Modified: code/branches/core7/test/core/class/SuperTest.cc
===================================================================
--- code/branches/core7/test/core/class/SuperTest.cc	2015-04-18 10:46:57 UTC (rev 10371)
+++ code/branches/core7/test/core/class/SuperTest.cc	2015-04-18 11:07:08 UTC (rev 10372)
@@ -96,7 +96,7 @@
             EXPECT_EQ(0u, identifier->getDirectChildren().size());
 
             EXPECT_EQ(1u, identifier->getDirectParents().size());
-            EXPECT_TRUE(identifier->getDirectParents().find(Class(TestClass)) != identifier->getDirectParents().end());
+            EXPECT_TRUE(std::find(identifier->getDirectParents().begin(), identifier->getDirectParents().end(), Class(TestClass)) != identifier->getDirectParents().end());
         }
         {
             Identifier* identifier = Class(TestClass);
@@ -105,7 +105,7 @@
             EXPECT_TRUE(identifier->getDirectChildren().find(Class(TestSubclass)) != identifier->getDirectChildren().end());
 
             EXPECT_EQ(1u, identifier->getDirectParents().size());
-            EXPECT_TRUE(identifier->getDirectParents().find(Class(BaseObject)) != identifier->getDirectParents().end());
+            EXPECT_TRUE(std::find(identifier->getDirectParents().begin(), identifier->getDirectParents().end(), Class(BaseObject)) != identifier->getDirectParents().end());
         }
     }
 




More information about the Orxonox-commit mailing list