Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

use static identifier initializer to store the inheritance definition of abstract classes. this prevents that identifiers are used (via Class(Name)) before they are properly initialized.

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

Legend:

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

    r10352 r10362  
    9494
    9595    // register Core as an abstract class to avoid problems if the class hierarchy is created within Core-constructor
    96     RegisterAbstractClass(Core).inheritsFrom(Class(Configurable));
     96    RegisterAbstractClass(Core).inheritsFrom<Configurable>();
    9797
    9898    Core::Core(const std::string& cmdLine)
     
    517517
    518518
    519     RegisterAbstractClass(DevModeListener).inheritsFrom(Class(Listable));
     519    RegisterAbstractClass(DevModeListener).inheritsFrom<Listable>();
    520520
    521521    DevModeListener::DevModeListener()
  • code/branches/core7/src/libraries/core/CoreIncludes.h

    r10360 r10362  
    127127*/
    128128#define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \
    129     Identifier& _##ClassName##Identifier = (new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))->getIdentifier()
     129    orxonox::SI_I& _##ClassName##Identifier = (*new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)))
    130130
    131131/**
     
    213213    }
    214214
     215
     216
     217
     218    /**
     219     * The static initializer stores the parent classes of this identifier. The corresponding identifiers are later loaded. This prevents identifiers from
     220     * being used before they are completely initialized.
     221     */
    215222    class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance
    216223    {
     224        struct InheritsFrom
     225        {
     226            virtual ~InheritsFrom() {}
     227            virtual Identifier* getParent() = 0;
     228        };
     229
     230        template <class T>
     231        struct InheritsFromClass : public InheritsFrom
     232        {
     233            virtual Identifier* getParent() { return Class(T); }
     234        };
     235
    217236        public:
    218237            StaticallyInitializedIdentifier(Identifier* identifier) : identifier_(identifier) {}
    219 
    220             virtual void load() {}
     238            ~StaticallyInitializedIdentifier()
     239            {
     240                for (size_t i = 0; i < this->parents_.size(); ++i)
     241                    delete parents_[i];
     242            }
     243
     244            virtual void load()
     245            {
     246                for (size_t i = 0; i < this->parents_.size(); ++i)
     247                    this->identifier_->inheritsFrom(this->parents_[i]->getParent());
     248            }
    221249
    222250            inline Identifier& getIdentifier()
    223251                { return *this->identifier_; }
    224252
     253            template <class T>
     254            inline StaticallyInitializedIdentifier& inheritsFrom()
     255                { this->parents_.push_back(new InheritsFromClass<T>()); return *this; }
     256
    225257        private:
    226258            Identifier* identifier_;
     259            std::vector<InheritsFrom*> parents_;
    227260    };
    228261
  • code/branches/core7/src/libraries/core/ViewportEventListener.cc

    r9667 r10362  
    3232namespace orxonox
    3333{
    34     RegisterAbstractClass(ViewportEventListener).inheritsFrom(Class(Listable));
     34    RegisterAbstractClass(ViewportEventListener).inheritsFrom<Listable>();
    3535
    3636    ViewportEventListener::ViewportEventListener()
  • code/branches/core7/src/libraries/core/WindowEventListener.cc

    r9667 r10362  
    3535    unsigned int WindowEventListener::windowHeight_s = 0;
    3636
    37     RegisterAbstractClass(WindowEventListener).inheritsFrom(Class(Listable));
     37    RegisterAbstractClass(WindowEventListener).inheritsFrom<Listable>();
    3838
    3939    WindowEventListener::WindowEventListener()
  • code/branches/core7/src/libraries/core/XMLNameListener.cc

    r9667 r10362  
    3232namespace orxonox
    3333{
    34     RegisterAbstractClass(XMLNameListener).inheritsFrom(Class(Listable));
     34    RegisterAbstractClass(XMLNameListener).inheritsFrom<Listable>();
    3535
    3636    XMLNameListener::XMLNameListener()
Note: See TracChangeset for help on using the changeset viewer.