Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10542 for code/branches/core7


Ignore:
Timestamp:
Jun 7, 2015, 2:16:55 PM (9 years ago)
Author:
landauf
Message:

clean and explicit setup/shutdown of singletons that are used by statically initialized instances

Location:
code/branches/core7/src/libraries
Files:
15 edited

Legend:

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

    r10540 r10542  
    5858#include "util/output/OutputManager.h"
    5959#include "core/singleton/Scope.h"
    60 #include "core/singleton/ScopedSingletonIncludes.h"
    6160#include "ApplicationPaths.h"
    6261#include "ConfigurablePaths.h"
     
    6665#include "GraphicsManager.h"
    6766#include "GUIManager.h"
    68 #include "class/Identifier.h"
    6967#include "Language.h"
    7068#include "Loader.h"
    7169#include "LuaState.h"
    72 #include "command/ConsoleCommandManager.h"
    7370#include "command/IOConsole.h"
    7471#include "command/TclBind.h"
     
    127124
    128125        // TODO: initialize Root-Context
    129         // TODO: initialize IdentifierManager here
    130         // TODO: initialize ScopeManager here
    131         // TODO: initialize CommandLineParser here
    132         // TODO: initialize ConsoleCommandManager here
    133         // TODO: initialize NetworkFunctionManager here
    134         // TODO: initialize StaticInitializationManager
     126        new StaticInitializationManager(); // create singleton
    135127        this->staticInitHandler_ = new CoreStaticInitializationHandler();
    136128        StaticInitializationManager::getInstance().addHandler(this->staticInitHandler_);
     
    262254        safeObjectDelete(&rootModule_);
    263255        safeObjectDelete(&staticInitHandler_);
     256        delete &StaticInitializationManager::getInstance();
    264257        safeObjectDelete(&dynLibManager_);
    265258        safeObjectDelete(&configurablePaths_);
  • code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc

    r10539 r10542  
    3131#include "CoreIncludes.h"
    3232#include "module/ModuleInstance.h"
     33#include "object/Iterator.h"
    3334#include "class/IdentifierManager.h"
    34 #include "object/Iterator.h"
     35#include "singleton/ScopeManager.h"
     36#include "command/ConsoleCommandManager.h"
     37#include "commandline/CommandLineParser.h"
    3538
    3639namespace orxonox
     
    3841    void CoreStaticInitializationHandler::setupHandler()
    3942    {
    40         // TODO
     43        // initialize singletons
     44        new IdentifierManager();
     45        new ScopeManager();
     46        new CommandLineParser();
     47        new ConsoleCommandManager();
    4148    }
    4249
    4350    void CoreStaticInitializationHandler::shutdownHandler()
    4451    {
    45         // TODO
     52        delete &ConsoleCommandManager::getInstance();
     53        delete &CommandLineParser::getInstance();
     54        delete &ScopeManager::getInstance();
     55        delete &IdentifierManager::getInstance();
    4656    }
    4757
  • code/branches/core7/src/libraries/core/class/IdentifierManager.cc

    r10520 r10542  
    4444namespace orxonox
    4545{
    46     /* static */ IdentifierManager& IdentifierManager::getInstance()
    47     {
    48         static IdentifierManager instance;
    49         return instance;
    50     }
     46    IdentifierManager* IdentifierManager::singletonPtr_s = 0;
    5147
    5248    IdentifierManager::IdentifierManager()
  • code/branches/core7/src/libraries/core/class/IdentifierManager.h

    r10520 r10542  
    4242#include <string>
    4343
     44#include "util/Singleton.h"
     45
    4446namespace orxonox
    4547{
    46     class _CoreExport IdentifierManager
     48    class _CoreExport IdentifierManager : public Singleton<IdentifierManager>
    4749    {
     50        friend class Singleton<IdentifierManager>;
     51
    4852        public:
    49             static IdentifierManager& getInstance();
     53            IdentifierManager();
     54            ~IdentifierManager() {}
    5055
    5156            void addIdentifier(Identifier* identifier);
     
    8893
    8994        private:
    90             IdentifierManager();
    91             IdentifierManager(const IdentifierManager&);
    92             ~IdentifierManager() {}
     95            IdentifierManager(const IdentifierManager&); // not implemented
    9396
    9497            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
     
    110113            std::map<Identifiable*, std::list<const Identifier*> > identifierTraceOfNewObject_;
    111114            Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded.
     115
     116            static IdentifierManager* singletonPtr_s;
    112117    };
    113118}
  • code/branches/core7/src/libraries/core/command/ConsoleCommandManager.cc

    r10520 r10542  
    3939namespace orxonox
    4040{
    41     /* static */ ConsoleCommandManager& ConsoleCommandManager::getInstance()
    42     {
    43         static ConsoleCommandManager instance;
    44         return instance;
    45     }
     41    ConsoleCommandManager* ConsoleCommandManager::singletonPtr_s = 0;
    4642
    4743    /**
  • code/branches/core7/src/libraries/core/command/ConsoleCommandManager.h

    r10520 r10542  
    3737#include "core/CorePrereqs.h"
    3838
     39#include "util/Singleton.h"
     40
    3941namespace orxonox
    4042{
     
    4244     * A singleton that stores all existing ConsoleCommands.
    4345     */
    44     class _CoreExport ConsoleCommandManager
     46    class _CoreExport ConsoleCommandManager : public Singleton<ConsoleCommandManager>
    4547    {
     48        friend class Singleton<ConsoleCommandManager>;
     49
    4650        public:
    47             static ConsoleCommandManager& getInstance();
    48 
    4951            void registerCommand(ConsoleCommand* command);
    5052            void registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command);
     
    7173            std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap_;
    7274            std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC_;
     75
     76            static ConsoleCommandManager* singletonPtr_s;
    7377    };
    7478}
  • code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc

    r10520 r10542  
    4040namespace orxonox
    4141{
     42    CommandLineParser* CommandLineParser::singletonPtr_s = 0;
     43
    4244    /**
    4345    @brief
     
    8587    CommandLineParser::~CommandLineParser()
    8688    {
    87     }
    88 
    89     /**
    90     @brief
    91         Returns a unique instance (Meyers Singleton).
    92     */
    93     CommandLineParser& CommandLineParser::_getInstance()
    94     {
    95         static CommandLineParser instance;
    96         return instance;
    9789    }
    9890
     
    260252    std::string CommandLineParser::getUsageInformation()
    261253    {
    262         CommandLineParser& inst = _getInstance();
     254        CommandLineParser& inst = getInstance();
    263255        std::ostringstream infoStr;
    264256
     
    313305    const CommandLineArgument* CommandLineParser::getArgument(const std::string& name)
    314306    {
    315         std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
    316         if (it == _getInstance().cmdLineArgs_.end())
     307        std::map<std::string, CommandLineArgument*>::const_iterator it = getInstance().cmdLineArgs_.find(name);
     308        if (it == getInstance().cmdLineArgs_.end())
    317309        {
    318310            ThrowException(Argument, "Could find command line argument '" + name + "'.");
     
    331323    void CommandLineParser::addArgument(CommandLineArgument* argument)
    332324    {
    333         OrxAssert(!_getInstance().existsArgument(argument->getName()),
     325        OrxAssert(!getInstance().existsArgument(argument->getName()),
    334326            "Cannot add a command line argument with name '" + argument->getName() + "' twice.");
    335327        OrxAssert(!argument->getDefaultValue().isType<bool>() || argument->getDefaultValue().get<bool>() != true,
     
    337329            << "Please use SetCommandLineSwitch and adjust your argument: " << argument->getName());
    338330
    339         _getInstance().cmdLineArgs_[argument->getName()] = argument;
     331        getInstance().cmdLineArgs_[argument->getName()] = argument;
    340332    }
    341333
     
    345337    void CommandLineParser::removeArgument(CommandLineArgument* argument)
    346338    {
    347         _getInstance().cmdLineArgs_.erase(argument->getName());
     339        getInstance().cmdLineArgs_.erase(argument->getName());
    348340    }
    349341}
  • code/branches/core7/src/libraries/core/commandline/CommandLineParser.h

    r10520 r10542  
    4848#include "util/OrxAssert.h"
    4949#include "util/MultiType.h"
     50#include "util/Singleton.h"
    5051
    5152namespace orxonox
     
    134135        CommandLineArgument
    135136    */
    136     class _CoreExport CommandLineParser
     137    class _CoreExport CommandLineParser : public Singleton<CommandLineParser>
    137138    {
     139        friend class Singleton<CommandLineParser>;
     140
    138141    public:
     142        //! Constructor initialises bFirstTimeParse_ with true.
     143        CommandLineParser() : bFirstTimeParse_(true) { }
     144        ~CommandLineParser();
    139145
    140146        //! Parse redirection to internal member method.
    141147        static void parse(const std::string& cmdLine)
    142         { _getInstance()._parse(cmdLine); }
     148        { getInstance()._parse(cmdLine); }
    143149
    144150        static std::string getUsageInformation();
     
    157163        static bool existsArgument(const std::string& name)
    158164        {
    159             std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);
    160             return !(it == _getInstance().cmdLineArgs_.end());
     165            std::map<std::string, CommandLineArgument*>::const_iterator it = getInstance().cmdLineArgs_.find(name);
     166            return !(it == getInstance().cmdLineArgs_.end());
    161167        }
    162168
     
    164170
    165171    private:
    166         //! Constructor initialises bFirstTimeParse_ with true.
    167         CommandLineParser() : bFirstTimeParse_(true) { }
    168172        //! Undefined copy constructor
    169173        CommandLineParser(const CommandLineParser& instance);
    170         ~CommandLineParser();
    171 
    172         static CommandLineParser& _getInstance();
    173174
    174175        void _parse(const std::string& cmdLine);
     
    187188        //! Search map by shortcut for the arguments.
    188189        std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
     190
     191        static CommandLineParser* singletonPtr_s;
    189192    };
    190193
  • code/branches/core7/src/libraries/core/module/StaticInitializationManager.cc

    r10536 r10542  
    3333namespace orxonox
    3434{
    35     /* static */ StaticInitializationManager& StaticInitializationManager::getInstance()
    36     {
    37         static StaticInitializationManager instance;
    38         return instance;
    39     }
     35    StaticInitializationManager* StaticInitializationManager::singletonPtr_s = 0;
    4036
    4137    void StaticInitializationManager::addHandler(StaticInitializationHandler* handler)
    4238    {
     39        handler->setupHandler();
    4340        this->handlers_.push_back(handler);
    4441    }
     
    4744    {
    4845        this->handlers_.remove(handler);
     46        handler->shutdownHandler();
    4947    }
    5048
  • code/branches/core7/src/libraries/core/module/StaticInitializationManager.h

    r10535 r10542  
    3434#include <list>
    3535
     36#include "util/Singleton.h"
     37
    3638namespace orxonox
    3739{
    38     class _CoreExport StaticInitializationManager
     40    class _CoreExport StaticInitializationManager : public Singleton<StaticInitializationManager>
    3941    {
     42        friend class Singleton<StaticInitializationManager>;
     43
    4044        public:
    41             static StaticInitializationManager& getInstance();
    42 
    4345            StaticInitializationManager() {}
    4446            virtual ~StaticInitializationManager() {}
     
    5254        private:
    5355            std::list<StaticInitializationHandler*> handlers_;
     56
     57            static StaticInitializationManager* singletonPtr_s;
    5458    };
    5559}
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.cc

    r10538 r10542  
    3838namespace orxonox
    3939{
    40     /* static */ ScopeManager& ScopeManager::getInstance()
    41     {
    42         static ScopeManager instance;
    43         return instance;
    44     }
     40    ScopeManager* ScopeManager::singletonPtr_s = 0;
    4541
    4642    void ScopeManager::addScope(ScopeID::Value scope)
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.h

    r10538 r10542  
    4141#include <set>
    4242
     43#include "util/Singleton.h"
     44
    4345namespace orxonox
    4446{
     
    5254        @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager.
    5355    */
    54     class _CoreExport ScopeManager
     56    class _CoreExport ScopeManager : public Singleton<ScopeManager>
    5557    {
     58        friend class Singleton<ScopeManager>;
     59
    5660        public:
    57             static ScopeManager& getInstance();
    58 
    5961            /** Adds a scope and activates all listeners which are registered for this scope */
    6062            void addScope(ScopeID::Value scope);
     
    7880            std::set<ScopeID::Value> activeScopes_;
    7981            std::map<ScopeID::Value, std::set<ScopeListener*> > listeners_; //!< Stores all listeners for a scope
     82
     83            static ScopeManager* singletonPtr_s;
    8084    };
    8185}
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.cc

    r10520 r10542  
    3232namespace orxonox
    3333{
    34     /* static */NetworkFunctionManager& NetworkFunctionManager::getInstance()
    35     {
    36         static NetworkFunctionManager instance;
    37         return instance;
    38     }
     34    NetworkFunctionManager* NetworkFunctionManager::singletonPtr_s = 0;
    3935
    4036    void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function)
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.h

    r10520 r10542  
    3636#include <set>
    3737
     38#include "util/Singleton.h"
     39#include "NetworkFunction.h"
     40
    3841namespace orxonox
    3942{
    40     class _NetworkExport NetworkFunctionManager
     43    class _NetworkExport NetworkFunctionManager : public Singleton<NetworkFunctionManager>
    4144    {
     45        friend class Singleton<NetworkFunctionManager>;
     46
    4247        public:
    43             static NetworkFunctionManager& getInstance();
    44 
    4548            void registerFunction(NetworkFunctionBase* function);
    4649            void unregisterFunction(NetworkFunctionBase* function);
     
    5861            std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
    5962            std::map<uint32_t, NetworkFunctionBase*> idMap_;
     63
     64            static NetworkFunctionManager* singletonPtr_s;
    6065    };
    6166}
  • code/branches/core7/src/libraries/network/NetworkStaticInitializationHandler.cc

    r10535 r10542  
    3030
    3131#include "core/module/ModuleInstance.h"
     32#include "NetworkFunctionManager.h"
    3233
    3334namespace orxonox
     
    3536    void NetworkStaticInitializationHandler::setupHandler()
    3637    {
    37         // TODO
     38        // initialize singleton
     39        new NetworkFunctionManager();
    3840    }
    3941
    4042    void NetworkStaticInitializationHandler::shutdownHandler()
    4143    {
    42         // TODO
     44        delete &NetworkFunctionManager::getInstance();
    4345    }
    4446
Note: See TracChangeset for help on using the changeset viewer.