Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10344


Ignore:
Timestamp:
Apr 5, 2015, 5:29:21 PM (10 years ago)
Author:
landauf
Message:

remove and destroy StaticallyInitializedInstances

Location:
code/branches/core7/src/libraries/core/module
Files:
4 edited

Legend:

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

    r10342 r10344  
    3535    ModuleInstance* ModuleInstance::currentModuleInstance_s = NULL;
    3636
     37    ModuleInstance::~ModuleInstance()
     38    {
     39        std::list<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_);
     40        for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     41            delete (*it);
     42    }
     43
    3744    void ModuleInstance::addStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
    3845    {
     
    4249    void ModuleInstance::loadAllStaticallyInitializedInstances()
    4350    {
    44         for (size_t i = 0; i < this->staticallyInitializedInstances_.size(); ++i)
    45             this->staticallyInitializedInstances_[i]->load();
     51        for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     52            (*it)->load();
     53    }
     54
     55    void ModuleInstance::removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
     56    {
     57        this->staticallyInitializedInstances_.remove(instance);
    4658    }
    4759
  • code/branches/core7/src/libraries/core/module/ModuleInstance.h

    r10342 r10344  
    3232#include "core/CorePrereqs.h"
    3333
    34 #include <vector>
     34#include <list>
    3535
    3636namespace orxonox
     
    3939    {
    4040        public:
     41            ~ModuleInstance();
     42
    4143            void addStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
    4244            void loadAllStaticallyInitializedInstances();
     45            void removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
    4346
    4447            static void setCurrentModuleInstance(ModuleInstance* instance);
     
    4649
    4750        private:
    48             std::vector<StaticallyInitializedInstance*> staticallyInitializedInstances_;
     51            std::list<StaticallyInitializedInstance*> staticallyInitializedInstances_;
    4952
    5053            static ModuleInstance* currentModuleInstance_s;
  • code/branches/core7/src/libraries/core/module/StaticallyInitializedInstance.cc

    r10342 r10344  
    3737        ModuleInstance::getCurrentModuleInstance()->addStaticallyInitializedInstance(this);
    3838    }
     39
     40    StaticallyInitializedInstance::~StaticallyInitializedInstance()
     41    {
     42        ModuleInstance::getCurrentModuleInstance()->removeStaticallyInitializedInstance(this);
     43    }
    3944}
  • code/branches/core7/src/libraries/core/module/StaticallyInitializedInstance.h

    r10342 r10344  
    3838        public:
    3939            StaticallyInitializedInstance();
    40             virtual ~StaticallyInitializedInstance() {}
     40            virtual ~StaticallyInitializedInstance();
    4141
    4242            virtual void load() = 0;
Note: See TracChangeset for help on using the changeset viewer.