Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10361


Ignore:
Timestamp:
Apr 12, 2015, 11:05:10 PM (10 years ago)
Author:
landauf
Message:

added run-time check for class hierarchy

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

Legend:

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

    r9667 r10361  
    223223            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    224224
     225            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) = 0;
    225226
    226227        protected:
     
    288289            virtual const std::string& getTypeidName()
    289290                { return this->typeidName_; }
     291
     292            virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object)
     293                { return dynamic_cast<T*>(object) != 0; }
    290294
    291295        private:
  • code/branches/core7/src/libraries/core/class/IdentifierManager.cc

    r9667 r10361  
    146146        }
    147147
     148        this->verifyClassHierarchy();
     149
    148150        this->stopCreatingHierarchy();
    149151        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
     152    }
     153
     154    /**
     155     * Verifies if the class hierarchy is consistent with the RTTI.
     156     */
     157    void IdentifierManager::verifyClassHierarchy()
     158    {
     159        Context temporaryContext(NULL);
     160        for (std::map<std::string, Identifier*>::const_iterator it1 = this->identifierByTypeidName_.begin(); it1 != this->identifierByTypeidName_.end(); ++it1)
     161        {
     162            if (!it1->second->hasFactory())
     163                continue;
     164
     165            Identifiable* temp = it1->second->fabricate(&temporaryContext);
     166
     167            for (std::map<std::string, Identifier*>::const_iterator it2 = this->identifierByTypeidName_.begin(); it2 != this->identifierByTypeidName_.end(); ++it2)
     168            {
     169                bool isA_AccordingToRtti = it2->second->canDynamicCastObjectToIdentifierClass(temp);
     170                bool isA_AccordingToClassHierarchy = temp->isA(it2->second);
     171
     172                if (isA_AccordingToRtti != isA_AccordingToClassHierarchy)
     173                {
     174                    orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << it1->second->getName() <<
     175                        (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << it2->second->getName() << " but RTTI says the opposite." << endl;
     176                }
     177            }
     178
     179            delete temp;
     180        }
     181
     182        size_t numberOfObjects = temporaryContext.getObjectList<Listable>()->size();
     183        if (numberOfObjects > 0)
     184            orxout(internal_warning) << "There are still " << numberOfObjects << " listables left after creating the class hierarchy" << endl;
    150185    }
    151186
  • code/branches/core7/src/libraries/core/class/IdentifierManager.h

    r9667 r10361  
    5959            /////////////////////////////
    6060            void createClassHierarchy();
     61            void verifyClassHierarchy();
    6162            void destroyAllIdentifiers();
    6263
Note: See TracChangeset for help on using the changeset viewer.