Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 13, 2015, 11:15:04 PM (9 years ago)
Author:
landauf
Message:

bugfix: class hierarchy wrongly considered the classes of nested members as base classes of the surrounding class. this is now fixed by using RTTI (i.e. dynamic_cast). also added some tests.

Location:
code/branches/core7/src/libraries/core/class
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/class/Identifier.cc

    r9667 r10363  
    144144    /**
    145145     * @brief Initializes the parents of this Identifier while creating the class hierarchy.
    146      * @param identifiers All identifiers that were used to create an instance of this class (including this identifier itself)
     146     * @param instance The instance that was used to determine the class hierarchy of this identifier.
     147     * @param identifiers All identifiers that were used to create the instance of this class (including this identifier itself)
    147148     */
    148     void Identifier::initializeParents(const std::set<const Identifier*>& identifiers)
     149    void Identifier::initializeParents(Identifiable* instance, const std::set<const Identifier*>& identifiers)
    149150    {
    150151        if (!IdentifierManager::getInstance().isCreatingHierarchy())
     
    154155        }
    155156
     157        // Add all identifiers which are real parents (dynamic_cast is possible) and that are not equal to THIS identifier.
     158        // Checking for dynamic_cast is necessary because some classes may have other classes as nested members. This means that the Identifiers of the nested
     159        // classes are also added to the set of potential parents. The only way to distinguish them is to use RTTI (i.e. dynamic_cast).
    156160        for (std::set<const Identifier*>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it)
    157             if (*it != this)
     161            if (*it != this && (*it)->canDynamicCastObjectToIdentifierClass(instance))
    158162                this->parents_.insert(*it);
    159163    }
  • code/branches/core7/src/libraries/core/class/Identifier.h

    r10361 r10363  
    148148            Identifier& inheritsFrom(Identifier* directParent);
    149149
    150             void initializeParents(const std::set<const Identifier*>& identifiers);
     150            void initializeParents(Identifiable* instance, const std::set<const Identifier*>& identifiers);
    151151            void initializeDirectParentsOfAbstractClass();
    152152            void finishInitialization();
     
    223223            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    224224
    225             virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) = 0;
     225            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const = 0;
    226226
    227227        protected:
     
    290290                { return this->typeidName_; }
    291291
    292             virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object)
     292            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const
    293293                { return dynamic_cast<T*>(object) != 0; }
    294294
  • code/branches/core7/src/libraries/core/class/IdentifierManager.cc

    r10361 r10363  
    122122                    if (temp->getIdentifier() != it->second)
    123123                        orxout(internal_error) << "Newly created object of type " << it->second->getName() << " has unexpected identifier. Did you forget to use RegisterObject(classname)?" << endl;
     124
     125                    it->second->initializeParents(temp, this->identifiersOfNewObject_);
     126
    124127                    delete temp;
    125 
    126                     it->second->initializeParents(this->identifiersOfNewObject_);
    127128                }
    128129                else
Note: See TracChangeset for help on using the changeset viewer.