[Orxonox-commit 5706] r10366 - code/branches/core7/src/libraries/core/class

landauf at orxonox.net landauf at orxonox.net
Wed Apr 15 22:11:16 CEST 2015


Author: landauf
Date: 2015-04-15 22:11:15 +0200 (Wed, 15 Apr 2015)
New Revision: 10366

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
Log:
found a better solution to find identifiers that don't belong to the parents of a newly created instance.

Modified: code/branches/core7/src/libraries/core/class/Identifier.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.cc	2015-04-14 20:29:05 UTC (rev 10365)
+++ code/branches/core7/src/libraries/core/class/Identifier.cc	2015-04-15 20:11:15 UTC (rev 10366)
@@ -143,10 +143,9 @@
 
     /**
      * @brief Initializes the parents of this Identifier while creating the class hierarchy.
-     * @param instance The instance that was used to determine the class hierarchy of this identifier.
-     * @param identifiers All identifiers that were used to create the instance of this class (including this identifier itself)
+     * @param initializationTrace All identifiers that were recorded while creating an instance of this class (including nested classes and this identifier itself)
      */
-    void Identifier::initializeParents(Identifiable* instance, const std::set<const Identifier*>& identifiers)
+    void Identifier::initializeParents(const std::set<const Identifier*>& initializationTrace)
     {
         if (!IdentifierManager::getInstance().isCreatingHierarchy())
         {
@@ -154,11 +153,8 @@
             return;
         }
 
-        // Add all identifiers which are real parents (dynamic_cast is possible) and that are not equal to THIS identifier.
-        // Checking for dynamic_cast is necessary because some classes may have other classes as nested members. This means that the Identifiers of the nested
-        // classes are also added to the set of potential parents. The only way to distinguish them is to use RTTI (i.e. dynamic_cast).
-        for (std::set<const Identifier*>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it)
-            if (*it != this && (*it)->canDynamicCastObjectToIdentifierClass(instance))
+        for (std::set<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)
+            if (*it != this)
                 this->parents_.insert(*it);
     }
 

Modified: code/branches/core7/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.h	2015-04-14 20:29:05 UTC (rev 10365)
+++ code/branches/core7/src/libraries/core/class/Identifier.h	2015-04-15 20:11:15 UTC (rev 10366)
@@ -147,7 +147,7 @@
             /////////////////////////////
             Identifier& inheritsFrom(Identifier* directParent);
 
-            void initializeParents(Identifiable* instance, const std::set<const Identifier*>& identifiers);
+            void initializeParents(const std::set<const Identifier*>& initializationTrace);
             void initializeDirectParentsOfAbstractClass();
             void finishInitialization();
 

Modified: code/branches/core7/src/libraries/core/class/IdentifierManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/IdentifierManager.cc	2015-04-14 20:29:05 UTC (rev 10365)
+++ code/branches/core7/src/libraries/core/class/IdentifierManager.cc	2015-04-15 20:11:15 UTC (rev 10366)
@@ -117,12 +117,12 @@
                 // To initialize the identifier, we create a new object and delete it afterwards.
                 if (it->second->hasFactory())
                 {
-                    this->identifiersOfNewObject_.clear();
+                    this->identifierTraceOfNewObject_.clear();
                     Identifiable* temp = it->second->fabricate(&temporaryContext);
                     if (temp->getIdentifier() != it->second)
                         orxout(internal_error) << "Newly created object of type " << it->second->getName() << " has unexpected identifier. Did you forget to use RegisterObject(classname)?" << endl;
 
-                    it->second->initializeParents(temp, this->identifiersOfNewObject_);
+                    it->second->initializeParents(this->identifierTraceOfNewObject_[temp]);
 
                     delete temp;
                 }
@@ -208,7 +208,7 @@
     void IdentifierManager::createdObject(Identifiable* identifiable)
     {
         if (this->isCreatingHierarchy())
-            this->identifiersOfNewObject_.insert(identifiable->getIdentifier());
+            this->identifierTraceOfNewObject_[identifiable].insert(identifiable->getIdentifier());
         else
             orxout(internal_warning) << "createdObject() called outside of class hierarchy creation" << endl;
     }

Modified: code/branches/core7/src/libraries/core/class/IdentifierManager.h
===================================================================
--- code/branches/core7/src/libraries/core/class/IdentifierManager.h	2015-04-14 20:29:05 UTC (rev 10365)
+++ code/branches/core7/src/libraries/core/class/IdentifierManager.h	2015-04-15 20:11:15 UTC (rev 10366)
@@ -106,8 +106,11 @@
             std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
 
             int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
-            std::set<const Identifier*> identifiersOfNewObject_;    //!< Used while creating the object hierarchy to keep track of the identifiers of a newly created object
             unsigned int classIDCounter_s;                          //!< counter for the unique classIDs
+
+            /// 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_;
     };
 }
 




More information about the Orxonox-commit mailing list