Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/CoreIncludes.h

    r10208 r10624  
    8484#include "object/ClassFactory.h"
    8585#include "object/ObjectList.h"
     86#include "module/StaticallyInitializedInstance.h"
    8687
    8788// resolve macro conflict on windows
     
    126127*/
    127128#define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \
    128     Identifier& _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)
     129    orxonox::SI_I& _##ClassName##Identifier = (*new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))
    129130
    130131/**
     
    133134*/
    134135#define RegisterObject(ClassName) \
    135     if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeObject(this)) \
     136    if (ClassIdentifier<ClassName>::getIdentifier()->initializeObject(this)) \
    136137        return; \
    137138    else \
     
    152153     */
    153154    template <class T>
    154     inline Identifier& registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
     155    inline Identifier* registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
    155156    {
    156157        return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable);
     
    164165     */
    165166    template <class T>
    166     inline Identifier& registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
    167     {
    168         orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
    169         Identifier* identifier = ClassIdentifier<T>::getIdentifier(name);
    170         identifier->setFactory(factory);
    171         identifier->setLoadable(bLoadable);
    172         return *identifier;
     167    inline Identifier* registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
     168    {
     169        return new ClassIdentifier<T>(name, factory, bLoadable);
    173170    }
    174171
     
    211208        return ClassIdentifier<T>::getIdentifier();
    212209    }
     210
     211
     212
     213
     214    /**
     215     * The static initializer stores the parent classes of this identifier. The corresponding identifiers are later loaded. This prevents identifiers from
     216     * being used before they are completely initialized.
     217     */
     218    class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance
     219    {
     220        template <class T>
     221        struct InheritsFromClass : public Identifier::InheritsFrom
     222        {
     223            virtual Identifier* getParent() const { return Class(T); }
     224        };
     225
     226        public:
     227            StaticallyInitializedIdentifier(Identifier* identifier)
     228                : StaticallyInitializedInstance(StaticInitialization::IDENTIFIER)
     229                , identifier_(identifier)
     230            {}
     231            ~StaticallyInitializedIdentifier() { delete identifier_; }
     232
     233            virtual void load()
     234            {
     235                IdentifierManager::getInstance().addIdentifier(this->identifier_);
     236            }
     237
     238            virtual void unload()
     239            {
     240                IdentifierManager::getInstance().removeIdentifier(this->identifier_);
     241            }
     242
     243            inline Identifier& getIdentifier()
     244                { return *this->identifier_; }
     245
     246            template <class T>
     247            inline StaticallyInitializedIdentifier& inheritsFrom()
     248                { this->identifier_->inheritsFrom(new InheritsFromClass<T>()); return *this; }
     249
     250            inline StaticallyInitializedIdentifier& virtualBase()
     251                { this->identifier_->setVirtualBase(true); return *this; }
     252
     253        private:
     254            Identifier* identifier_;
     255    };
     256
     257    typedef StaticallyInitializedIdentifier SI_I;
    213258}
    214259
Note: See TracChangeset for help on using the changeset viewer.