Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10362 for code/branches


Ignore:
Timestamp:
Apr 12, 2015, 11:07:14 PM (9 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
Files:
27 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()
  • code/branches/core7/src/libraries/network/ClientConnectionListener.cc

    r9667 r10362  
    3535namespace orxonox
    3636{
    37     RegisterAbstractClass(ClientConnectionListener).inheritsFrom(Class(Listable));
     37    RegisterAbstractClass(ClientConnectionListener).inheritsFrom<Listable>();
    3838
    3939    ClientConnectionListener::ClientConnectionListener()
  • code/branches/core7/src/libraries/network/NetworkFunction.cc

    r9667 r10362  
    3838
    3939  // no suitable factory for NetworkFunctionBase (and children), so we declare it abstract
    40   RegisterAbstractClass(NetworkFunctionBase).inheritsFrom(Class(Listable));
    41   RegisterAbstractClass(NetworkFunctionStatic).inheritsFrom(Class(NetworkFunctionBase));
    42   RegisterAbstractClass(NetworkMemberFunctionBase).inheritsFrom(Class(NetworkFunctionBase));
     40  RegisterAbstractClass(NetworkFunctionBase).inheritsFrom<Listable>();
     41  RegisterAbstractClass(NetworkFunctionStatic).inheritsFrom<NetworkFunctionBase>();
     42  RegisterAbstractClass(NetworkMemberFunctionBase).inheritsFrom<NetworkFunctionBase>();
    4343
    4444  NetworkFunctionBase::NetworkFunctionBase(const std::string& name)
  • code/branches/core7/src/libraries/network/synchronisable/Synchronisable.cc

    r9667 r10362  
    4545  uint8_t Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
    4646
    47   RegisterAbstractClass(Synchronisable).inheritsFrom(Class(OrxonoxInterface));
     47  RegisterAbstractClass(Synchronisable).inheritsFrom<OrxonoxInterface>();
    4848
    4949  /**
  • code/branches/core7/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc

    r9667 r10362  
    4646    float TimeFactorListener::timefactor_s = 1.0f;
    4747
    48     RegisterAbstractClass(TimeFactorListener).inheritsFrom(Class(Listable));
     48    RegisterAbstractClass(TimeFactorListener).inheritsFrom<Listable>();
    4949
    5050    TimeFactorListener::TimeFactorListener()
     
    6767    // Tickable
    6868    //----------------------------
    69     RegisterAbstractClass(Tickable).inheritsFrom(Class(OrxonoxInterface));
     69    RegisterAbstractClass(Tickable).inheritsFrom<OrxonoxInterface>();
    7070
    7171    /**
  • code/branches/core7/src/modules/docking/DockingAnimation.cc

    r9667 r10362  
    3939namespace orxonox
    4040{
    41     RegisterAbstractClass(DockingAnimation).inheritsFrom(Class(BaseObject));
     41    RegisterAbstractClass(DockingAnimation).inheritsFrom<BaseObject>();
    4242
    4343    DockingAnimation::DockingAnimation(Context* context) : BaseObject(context)
  • code/branches/core7/src/modules/docking/DockingEffect.cc

    r9667 r10362  
    3737namespace orxonox
    3838{
    39     RegisterAbstractClass(DockingEffect).inheritsFrom(Class(BaseObject));
     39    RegisterAbstractClass(DockingEffect).inheritsFrom<BaseObject>();
    4040
    4141    DockingEffect::DockingEffect(Context* context) : BaseObject(context)
  • code/branches/core7/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.cc

    r10189 r10362  
    4040namespace orxonox
    4141{
    42     RegisterAbstractClass(AbstractRadiusHeightCollisionShape).inheritsFrom(Class(CollisionShape));
     42    RegisterAbstractClass(AbstractRadiusHeightCollisionShape).inheritsFrom<CollisionShape>();
    4343
    4444    /**
  • code/branches/core7/src/modules/pickup/CollectiblePickup.cc

    r9667 r10362  
    4040namespace orxonox
    4141{
    42     RegisterAbstractClass(CollectiblePickup).inheritsFrom(Class(Pickupable));
     42    RegisterAbstractClass(CollectiblePickup).inheritsFrom<Pickupable>();
    4343
    4444    /**
  • code/branches/core7/src/modules/questsystem/Quest.cc

    r9667 r10362  
    4545namespace orxonox
    4646{
    47     RegisterAbstractClass(Quest).inheritsFrom(Class(QuestItem));
     47    RegisterAbstractClass(Quest).inheritsFrom<QuestItem>();
    4848
    4949    /**
  • code/branches/core7/src/modules/questsystem/QuestEffect.cc

    r9667 r10362  
    3737namespace orxonox
    3838{
    39     RegisterAbstractClass(QuestEffect).inheritsFrom(Class(BaseObject));
     39    RegisterAbstractClass(QuestEffect).inheritsFrom<BaseObject>();
    4040
    4141    /**
  • code/branches/core7/src/modules/questsystem/effects/ChangeQuestStatus.cc

    r9667 r10362  
    4242namespace orxonox
    4343{
    44     RegisterAbstractClass(ChangeQuestStatus).inheritsFrom(Class(QuestEffect));
     44    RegisterAbstractClass(ChangeQuestStatus).inheritsFrom<QuestEffect>();
    4545
    4646    /**
  • code/branches/core7/src/orxonox/chat/ChatManager.cc

    r10347 r10362  
    113113    // ChatListener                                                         //
    114114    //////////////////////////////////////////////////////////////////////////
    115     RegisterAbstractClass(ChatListener).inheritsFrom(Class(Listable));
     115    RegisterAbstractClass(ChatListener).inheritsFrom<Listable>();
    116116
    117117    ChatListener::ChatListener()
  • code/branches/core7/src/orxonox/collisionshapes/CollisionShape.cc

    r10216 r10362  
    4444namespace orxonox
    4545{
    46     RegisterAbstractClass(CollisionShape).inheritsFrom(Class(BaseObject)).inheritsFrom(Class(Synchronisable));
     46    RegisterAbstractClass(CollisionShape).inheritsFrom<BaseObject>().inheritsFrom<Synchronisable>();
    4747
    4848    /**
  • code/branches/core7/src/orxonox/gamestates/GSLevel.cc

    r10347 r10362  
    252252    ///////////////////////////////////////////////////////////////////////////
    253253
    254     RegisterAbstractClass(GSLevelMemento).inheritsFrom(Class(OrxonoxInterface));
     254    RegisterAbstractClass(GSLevelMemento).inheritsFrom<OrxonoxInterface>();
    255255
    256256    GSLevelMemento::GSLevelMemento()
  • code/branches/core7/src/orxonox/infos/PlayerInfo.cc

    r9945 r10362  
    4040namespace orxonox
    4141{
    42     RegisterAbstractClass(PlayerInfo).inheritsFrom(Class(Info));
     42    RegisterAbstractClass(PlayerInfo).inheritsFrom<Info>();
    4343
    4444    PlayerInfo::PlayerInfo(Context* context) : Info(context)
  • code/branches/core7/src/orxonox/interfaces/InterfaceCompilation.cc

    r9667 r10362  
    5050    // GametypeMessageListener
    5151    //----------------------------
    52     RegisterAbstractClass(GametypeMessageListener).inheritsFrom(Class(OrxonoxInterface));
     52    RegisterAbstractClass(GametypeMessageListener).inheritsFrom<OrxonoxInterface>();
    5353
    5454    GametypeMessageListener::GametypeMessageListener()
     
    6060    // PlayerTrigger
    6161    //----------------------------
    62     RegisterAbstractClass(PlayerTrigger).inheritsFrom(Class(OrxonoxInterface));
     62    RegisterAbstractClass(PlayerTrigger).inheritsFrom<OrxonoxInterface>();
    6363
    6464    PlayerTrigger::PlayerTrigger()
     
    8080    // RadarListener
    8181    //----------------------------
    82     RegisterAbstractClass(RadarListener).inheritsFrom(Class(OrxonoxInterface));
     82    RegisterAbstractClass(RadarListener).inheritsFrom<OrxonoxInterface>();
    8383
    8484    RadarListener::RadarListener()
     
    9090    // TeamColourable
    9191    //----------------------------
    92     RegisterAbstractClass(TeamColourable).inheritsFrom(Class(OrxonoxInterface));
     92    RegisterAbstractClass(TeamColourable).inheritsFrom<OrxonoxInterface>();
    9393
    9494    TeamColourable::TeamColourable()
     
    100100    // Rewardable
    101101    //----------------------------
    102     RegisterAbstractClass(Rewardable).inheritsFrom(Class(OrxonoxInterface));
     102    RegisterAbstractClass(Rewardable).inheritsFrom<OrxonoxInterface>();
    103103
    104104    Rewardable::Rewardable()
  • code/branches/core7/src/orxonox/interfaces/PickupCarrier.cc

    r9667 r10362  
    4141namespace orxonox
    4242{
    43     RegisterAbstractClass(PickupCarrier).inheritsFrom(Class(OrxonoxInterface));
     43    RegisterAbstractClass(PickupCarrier).inheritsFrom<OrxonoxInterface>();
    4444
    4545    /**
  • code/branches/core7/src/orxonox/interfaces/Pickupable.cc

    r9667 r10362  
    4646namespace orxonox
    4747{
    48     RegisterAbstractClass(Pickupable).inheritsFrom(Class(OrxonoxInterface)).inheritsFrom(Class(Rewardable));
     48    RegisterAbstractClass(Pickupable).inheritsFrom<OrxonoxInterface>().inheritsFrom<Rewardable>();
    4949
    5050    /**
  • code/branches/core7/src/orxonox/interfaces/RadarViewable.cc

    r9667 r10362  
    3838namespace orxonox
    3939{
    40     RegisterAbstractClass(RadarViewable).inheritsFrom(Class(OrxonoxInterface));
     40    RegisterAbstractClass(RadarViewable).inheritsFrom<OrxonoxInterface>();
    4141
    4242    /**
  • code/branches/core7/src/orxonox/sound/BaseSound.cc

    r9939 r10362  
    4343namespace orxonox
    4444{
    45     RegisterAbstractClass(BaseSound).inheritsFrom(Class(Listable));
     45    RegisterAbstractClass(BaseSound).inheritsFrom<Listable>();
    4646
    4747    BaseSound::BaseSound()
  • code/branches/core7/src/orxonox/weaponsystem/WeaponMode.cc

    r9939 r10362  
    4545namespace orxonox
    4646{
    47     RegisterAbstractClass(WeaponMode).inheritsFrom(Class(BaseObject));
     47    RegisterAbstractClass(WeaponMode).inheritsFrom<BaseObject>();
    4848
    4949    WeaponMode::WeaponMode(Context* context) : BaseObject(context)
  • code/branches/core7/src/orxonox/worldentities/WorldEntity.cc

    r10288 r10362  
    6161    BOOST_STATIC_ASSERT((int)Ogre::Node::TS_WORLD  == (int)WorldEntity::World);
    6262
    63     RegisterAbstractClass(WorldEntity).inheritsFrom(Class(BaseObject)).inheritsFrom(Class(Synchronisable));
     63    RegisterAbstractClass(WorldEntity).inheritsFrom<BaseObject>().inheritsFrom<Synchronisable>();
    6464
    6565    /**
Note: See TracChangeset for help on using the changeset viewer.