Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10512 for code


Ignore:
Timestamp:
May 30, 2015, 10:59:13 PM (9 years ago)
Author:
landauf
Message:

fixed issue: Class(T) may not be allowed in StaticallyInitializedIdentifier::load() because T may not yet be initialized.
now the inheritance is resolved in Identifier::finishInitialization()

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

Legend:

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

    r10481 r10512  
    218218    class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance
    219219    {
    220         struct InheritsFrom
     220        template <class T>
     221        struct InheritsFromClass : public Identifier::InheritsFrom
    221222        {
    222             virtual ~InheritsFrom() {}
    223             virtual Identifier* getParent() = 0;
    224         };
    225 
    226         template <class T>
    227         struct InheritsFromClass : public InheritsFrom
    228         {
    229             virtual Identifier* getParent() { return Class(T); }
     223            virtual Identifier* getParent() const { return Class(T); }
    230224        };
    231225
    232226        public:
    233227            StaticallyInitializedIdentifier(Identifier* identifier) : identifier_(identifier) {}
    234             ~StaticallyInitializedIdentifier()
    235             {
    236                 for (size_t i = 0; i < this->parents_.size(); ++i)
    237                     delete parents_[i];
    238             }
    239228
    240229            virtual void load()
    241230            {
    242231                IdentifierManager::getInstance().addIdentifier(this->identifier_);
    243                 for (size_t i = 0; i < this->parents_.size(); ++i)
    244                     this->identifier_->inheritsFrom(this->parents_[i]->getParent());
    245232            }
    246233
     
    255242            template <class T>
    256243            inline StaticallyInitializedIdentifier& inheritsFrom()
    257                 { this->parents_.push_back(new InheritsFromClass<T>()); return *this; }
     244                { this->identifier_->inheritsFrom(new InheritsFromClass<T>()); return *this; }
    258245
    259246            inline StaticallyInitializedIdentifier& virtualBase()
     
    262249        private:
    263250            Identifier* identifier_;
    264             std::vector<InheritsFrom*> parents_;
    265251    };
    266252
  • code/branches/core7/src/libraries/core/class/Identifier.cc

    r10483 r10512  
    7979            delete this->factory_;
    8080
     81        for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)
     82            delete (*it);
     83
    8184        for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
    8285            delete (it->second);
     
    121124     * @brief Used to define the direct parents of an Identifier of an abstract class.
    122125     */
    123     Identifier& Identifier::inheritsFrom(Identifier* directParent)
    124     {
    125         if (this->parents_.empty())
    126             this->directParents_.push_back(directParent);
    127         else
    128             orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl;
     126    Identifier& Identifier::inheritsFrom(InheritsFrom* directParent)
     127    {
     128        if (this->directParents_.empty())
     129            this->manualDirectParents_.push_back(directParent);
     130        else
     131            orxout(internal_error) << "Trying to manually add direct parent of " << this->getName() << " after the latter was already initialized" << endl;
    129132
    130133        return *this;
     
    183186            this->verifyIdentifierTrace();
    184187        }
    185         else if (!this->directParents_.empty())
     188        else if (!this->manualDirectParents_.empty())
    186189        {
    187190            // no parents defined -> this class was manually initialized by calling inheritsFrom<Class>()
    188191
    189192            // initialize all direct parents
    190             for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    191                 const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
     193            for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)
     194            {
     195                Identifier* directParent = (*it)->getParent();
     196                this->directParents_.push_back(directParent);
     197                directParent->finishInitialization(); // initialize parent
     198            }
    192199
    193200            // direct parents and their parents are also parents of this identifier (but only add them once)
  • code/branches/core7/src/libraries/core/class/Identifier.h

    r10483 r10512  
    112112    {
    113113        public:
     114            struct InheritsFrom //! helper class to manually define inheritance
     115            {
     116                virtual ~InheritsFrom() {}
     117                virtual Identifier* getParent() const = 0;
     118            };
     119
     120        public:
    114121            Identifier(const std::string& name, Factory* factory, bool bLoadable);
    115122            Identifier(const Identifier& identifier); // don't copy
     
    149156            ////// Class Hierarchy //////
    150157            /////////////////////////////
    151             Identifier& inheritsFrom(Identifier* directParent);
     158            Identifier& inheritsFrom(InheritsFrom* directParent);
    152159
    153160            void initializeParents(const std::list<const Identifier*>& initializationTrace);
     
    219226            void addIfNotExists(std::list<const Identifier*>& list, const Identifier* identifierToAdd) const;
    220227
     228            std::list<const InheritsFrom*> manualDirectParents_;            //!< Manually defined direct parents
    221229            std::list<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to (sorted by their order of initialization)
    222230            std::list<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to (sorted by their order of initialization)
Note: See TracChangeset for help on using the changeset viewer.