Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2015, 10:56:32 AM (9 years ago)
Author:
landauf
Message:

load modules AFTER core was initialized. load each module with a separate ModuleInstance. unloading is not yet implemented…

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

Legend:

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

    r10404 r10518  
    3535    ModuleInstance* ModuleInstance::currentModuleInstance_s = NULL;
    3636
     37    ModuleInstance::ModuleInstance(const std::string& name)
     38        : name_(name)
     39        , dynLib_(NULL)
     40    {
     41    }
     42
    3743    ModuleInstance::~ModuleInstance()
    3844    {
    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);
     45        this->deleteAllStaticallyInitializedInstances();
    4246    }
    4347
    4448    void ModuleInstance::addStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
    4549    {
    46         this->staticallyInitializedInstances_.push_back(instance);
     50        this->staticallyInitializedInstances_.insert(instance);
    4751    }
    4852
    4953    void ModuleInstance::loadAllStaticallyInitializedInstances()
    5054    {
    51         for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     55        for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
    5256            (*it)->load();
    5357    }
     
    5559    void ModuleInstance::unloadAllStaticallyInitializedInstances()
    5660    {
    57         for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     61        for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
    5862            (*it)->unload();
    5963    }
     
    6165    void ModuleInstance::removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
    6266    {
    63         this->staticallyInitializedInstances_.remove(instance);
     67        this->staticallyInitializedInstances_.erase(instance);
    6468    }
     69
     70    void ModuleInstance::deleteAllStaticallyInitializedInstances()
     71    {
     72        std::set<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_);
     73        this->staticallyInitializedInstances_.clear();
     74        for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     75            delete (*it);
     76    }
     77
    6578
    6679    /*static*/ void ModuleInstance::setCurrentModuleInstance(ModuleInstance* instance)
     
    7285    {
    7386        if (!ModuleInstance::currentModuleInstance_s)
    74             ModuleInstance::currentModuleInstance_s = new ModuleInstance();
     87            ModuleInstance::currentModuleInstance_s = new ModuleInstance("");
    7588        return ModuleInstance::currentModuleInstance_s;
    7689    }
  • code/branches/core7/src/libraries/core/module/ModuleInstance.h

    r10404 r10518  
    3232#include "core/CorePrereqs.h"
    3333
    34 #include <list>
     34#include <set>
     35#include <string>
    3536
    3637namespace orxonox
     
    3940    {
    4041        public:
     42            ModuleInstance(const std::string& name);
    4143            ~ModuleInstance();
    4244
     
    4547            void unloadAllStaticallyInitializedInstances();
    4648            void removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
     49            void deleteAllStaticallyInitializedInstances();
     50
     51            inline const std::string& getName() const
     52                { return this->name_; }
     53
     54            inline void setDynLib(DynLib* dynLib)
     55                { this->dynLib_ = dynLib; }
     56            inline DynLib* getDynLib() const
     57                { return this->dynLib_; }
    4758
    4859            static void setCurrentModuleInstance(ModuleInstance* instance);
     
    5061
    5162        private:
    52             std::list<StaticallyInitializedInstance*> staticallyInitializedInstances_;
     63            std::set<StaticallyInitializedInstance*> staticallyInitializedInstances_;
     64            std::string name_;
     65            DynLib* dynLib_;
    5366
    5467            static ModuleInstance* currentModuleInstance_s;
Note: See TracChangeset for help on using the changeset viewer.