Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3366 for code


Ignore:
Timestamp:
Jul 29, 2009, 10:27:10 PM (15 years ago)
Author:
rgrieder
Message:

Derived all singletons implemented in a usual manner from orxonox::Singleton<T>.
This resolves inconsistencies with the singletonPtr_s variable in case of exceptions (asserts were being triggered then).
And while at it replaced singletonRef_s with singletonPtr_s for it to be less misleading (as fabian has already pointed out).

Location:
code/branches/resource/src
Files:
45 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource/src/core/Clock.h

    r3196 r3366  
    2626 *
    2727 */
    28 
    29 /**
    30     @file
    31     @brief Declaration of the Core class.
    32 
    33     The Core class is a singleton, only used to configure some variables
    34     in the core through the config-file.
    35 */
    3628
    3729#ifndef _Clock_H__
  • code/branches/resource/src/core/ConfigFileManager.cc

    r3301 r3366  
    4242    const char* const DEFAULT_CONFIG_FILE = "default.ini";
    4343
    44     ConfigFileManager* ConfigFileManager::singletonRef_s = 0;
     44    ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
    4545
    4646    SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
     
    482482         : mininmalFreeType_(ConfigFileType::numberOfReservedTypes)
    483483    {
    484         assert(singletonRef_s == 0);
    485         singletonRef_s = this;
    486484    }
    487485
     
    490488        for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); )
    491489            delete (it++)->second;
    492 
    493         assert(singletonRef_s != 0);
    494         singletonRef_s = 0;
    495490    }
    496491
  • code/branches/resource/src/core/ConfigFileManager.h

    r3196 r3366  
    3838
    3939#include "util/OrxEnum.h"
     40#include "util/Singleton.h"
    4041
    4142namespace orxonox
     
    267268    // ConfigFileManager //
    268269    ///////////////////////
    269     class _CoreExport ConfigFileManager
    270     {
     270    class _CoreExport ConfigFileManager : public Singleton<ConfigFileManager>
     271    {
     272        friend class Singleton<ConfigFileManager>;
    271273        public:
    272274            ConfigFileManager();
     
    305307            void updateConfigValues(ConfigFileType type);
    306308
    307             static ConfigFileManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    308 
    309309        private:
    310310            ConfigFileManager(const ConfigFileManager&);
     
    315315            unsigned int mininmalFreeType_;
    316316
    317             static ConfigFileManager* singletonRef_s;
     317            static ConfigFileManager* singletonPtr_s;
    318318    };
    319319}
  • code/branches/resource/src/core/Core.cc

    r3363 r3366  
    8383{
    8484    //! Static pointer to the singleton
    85     Core* Core::singletonRef_s  = 0;
     85    Core* Core::singletonPtr_s  = 0;
    8686
    8787    SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
     
    139139                .callback(this, &CoreConfiguration::debugLevelChanged);
    140140
    141             SetConfigValue(language_, Language::getLanguage().defaultLanguage_)
     141            SetConfigValue(language_, Language::getInstance().defaultLanguage_)
    142142                .description("The language of the ingame text")
    143143                .callback(this, &CoreConfiguration::languageChanged);
     
    179179        {
    180180            // Read the translation file after the language was configured
    181             Language::getLanguage().readTranslatedLanguageFile();
     181            Language::getInstance().readTranslatedLanguageFile();
    182182        }
    183183
     
    252252        // Cleanup guard for external console commands that don't belong to an Identifier
    253253        , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)
     254        , configuration_(new CoreConfiguration()) // Don't yet create config values!
    254255        , bDevRun_(false)
    255256        , bGraphicsLoaded_(false)
    256         , configuration_(new CoreConfiguration()) // Don't yet create config values!
    257     {
    258         if (singletonRef_s != 0)
    259         {
    260             COUT(0) << "Error: The Core singleton cannot be recreated! Shutting down." << std::endl;
    261             abort();
    262         }
    263         Core::singletonRef_s = this;
    264 
     257    {
    265258        // Parse command line arguments first
    266259        CommandLine::parseCommandLine(cmdLine);
     
    328321    Core::~Core()
    329322    {
    330         // Don't assign singletonRef_s with NULL! Recreation is not supported
    331         // The is quite simply because of the pre-main code that uses heap allocation
    332         // And we correctly deallocate these resources in this destructor.
    333323    }
    334324
  • code/branches/resource/src/core/Core.h

    r3363 r3366  
    4646#include "util/OutputHandler.h"
    4747#include "util/ScopeGuard.h"
     48#include "util/Singleton.h"
    4849
    4950namespace orxonox
     
    5859        The class provides information about the media, config and log path.
    5960        It determines those by the use of platform specific functions.
     61    @remark
     62        You should only create this singleton once because it destroys the identifiers!
    6063    */
    61     class _CoreExport Core
     64    class _CoreExport Core : public Singleton<Core>
    6265    {
    6366        typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
     67        friend class Singleton<Core>;
    6468
    6569        public:
     
    8185            void loadGraphics();
    8286            void unloadGraphics();
    83 
    84             static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
    8587
    8688            static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
     
    136138            bool                          bGraphicsLoaded_;
    137139
    138             static Core* singletonRef_s;
     140            static Core* singletonPtr_s;
    139141    };
    140142}
  • code/branches/resource/src/core/GUIManager.cc

    r3346 r3366  
    8787    static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
    8888
    89     GUIManager* GUIManager::singletonRef_s = 0;
     89    GUIManager* GUIManager::singletonPtr_s = 0;
    9090
    9191    /**
     
    105105        , resourceProvider_(0)
    106106    {
    107         assert(singletonRef_s == 0);
    108         singletonRef_s = this;
    109 
    110107        using namespace CEGUI;
    111108
     
    161158        // destroy our own tolua interfaces
    162159        LuaBind::getInstance().closeToluaInterfaces(this->luaState_);
    163 
    164         singletonRef_s = 0;
    165160    }
    166161
  • code/branches/resource/src/core/GUIManager.h

    r3346 r3366  
    4545
    4646#include "util/OgreForwardRefs.h"
     47#include "util/Singleton.h"
    4748#include "input/InputHandler.h"
    4849
     
    6061        Those input events are then injected into CEGUI in Lua.
    6162    */
    62     class _CoreExport GUIManager : public InputHandler
     63    class _CoreExport GUIManager : public Singleton<GUIManager>, public InputHandler
    6364    {
     65        friend class Singleton<GUIManager>;
    6466    public:
    6567        GUIManager(Ogre::RenderWindow* renderWindow);
     
    7375        void setCamera(Ogre::Camera* camera);
    7476
    75         static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
    76         static GUIManager* getInstancePtr() { return singletonRef_s; }
     77        static GUIManager* getInstancePtr() { return singletonPtr_s; }
    7778
    7879    private:
     
    99100        lua_State*               luaState_;         //!< Lua state, access point to the Lua engine
    100101
    101         static GUIManager*       singletonRef_s;    //!< Singleton reference to GUIManager
     102        static GUIManager*       singletonPtr_s;    //!< Singleton reference to GUIManager
    102103
    103104    };
  • code/branches/resource/src/core/Game.cc

    r3363 r3366  
    6262
    6363    std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s;
    64     Game* Game::singletonRef_s = 0;
     64    Game* Game::singletonPtr_s = 0;
    6565
    6666
     
    114114    Game::Game(const std::string& cmdLine)
    115115    {
    116         if (singletonRef_s != 0)
    117         {
    118             COUT(0) << "Error: The Game singleton cannot be recreated! Shutting down." << std::endl;
    119             abort();
    120         }
    121         singletonRef_s = this;
    122 
    123116        this->bAbort_ = false;
    124117        bChangingState_ = false;
     
    163156    Game::~Game()
    164157    {
    165         // Don't assign singletonRef_s with NULL! Recreation is not supported
    166158    }
    167159
  • code/branches/resource/src/core/Game.h

    r3363 r3366  
    4848
    4949#include "util/Debug.h"
     50#include "util/Singleton.h"
    5051
    5152/**
     
    7576    @brief
    7677        Main class responsible for running the game.
     78    @remark
     79        You should only create this singleton once because it owns the Core class! (see remark there)
    7780    */
    78     class _CoreExport Game
     81    class _CoreExport Game : public Singleton<Game>
    7982    {
     83        friend class Singleton<Game>;
    8084        typedef std::vector<shared_ptr<GameState> > GameStateVector;
    8185        typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
     
    104108        template <class T>
    105109        static bool declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bConsoleMode);
    106         static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    107110
    108111    private:
     
    175178
    176179        static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
    177         static Game* singletonRef_s;        //!< Pointer to the Singleton
     180        static Game* singletonPtr_s;        //!< Pointer to the Singleton
    178181    };
    179182
  • code/branches/resource/src/core/GraphicsManager.cc

    r3349 r3366  
    8383    };
    8484
    85     GraphicsManager* GraphicsManager::singletonRef_s = 0;
     85    GraphicsManager* GraphicsManager::singletonPtr_s = 0;
    8686
    8787    /**
     
    9898        RegisterObject(GraphicsManager);
    9999
    100         assert(singletonRef_s == 0);
    101         singletonRef_s = this;
    102 
    103100        this->setConfigValues();
    104101
     
    154151
    155152        delete this->ogreWindowEventListener_;
    156 
    157         assert(singletonRef_s);
    158         singletonRef_s = 0;
    159153    }
    160154
  • code/branches/resource/src/core/GraphicsManager.h

    r3346 r3366  
    4242#include <string>
    4343#include <OgreLog.h>
     44#include "util/Singleton.h"
    4445#include "OrxonoxClass.h"
    4546
     
    5051        Graphics engine manager class
    5152    */
    52     class _CoreExport GraphicsManager : public OrxonoxClass, public Ogre::LogListener
     53    class _CoreExport GraphicsManager : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener
    5354    {
     55        friend class Singleton<GraphicsManager>;
    5456    public:
    5557        GraphicsManager();
     
    6668
    6769        void setCamera(Ogre::Camera* camera);
    68 
    69         inline static GraphicsManager& getInstance()
    70             { assert(singletonRef_s); return *singletonRef_s; }
    7170
    7271    private:
     
    107106        ConsoleCommand*     ccPrintScreen_;
    108107
    109         static GraphicsManager* singletonRef_s;        //!< Pointer to the Singleton
     108        static GraphicsManager* singletonPtr_s;        //!< Pointer to the Singleton
    110109    };
    111110}
  • code/branches/resource/src/core/Language.cc

    r3280 r3366  
    8989    // ###############################
    9090
    91     Language* Language::singletonRef_s = 0;
     91    Language* Language::singletonPtr_s = 0;
    9292
    9393    /**
     
    9696    Language::Language()
    9797    {
    98         assert(singletonRef_s == 0);
    99         singletonRef_s = this;
    100 
    10198        this->defaultLanguage_ = "default";
    10299        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    113110        for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
    114111            delete (it->second);
    115 
    116         assert(singletonRef_s);
    117         singletonRef_s = 0;
    118112    }
    119113
  • code/branches/resource/src/core/Language.h

    r3280 r3366  
    3737    Usage:
    3838     - Set the entry with the default string:
    39        Language::getLanguage()->addEntry("label of the entry", "the string to translate");
     39       Language::getInstance()->addEntry("label of the entry", "the string to translate");
    4040
    4141     - Get the localisation of the entry in the configured language:
    42        std::cout << Language::getLanguage()->getLocalisation("name of the entry") << std::endl;
     42       std::cout << Language::getInstance()->getLocalisation("name of the entry") << std::endl;
    4343*/
    4444
     
    5151#include <string>
    5252#include <cassert>
     53#include "util/Singleton.h"
    5354
    5455#define AddLanguageEntry(label, fallbackstring) \
    55     orxonox::Language::getLanguage().addEntry(label, fallbackstring)
     56    orxonox::Language::getInstance().addEntry(label, fallbackstring)
    5657
    5758#define GetLocalisation(label) \
    58     orxonox::Language::getLanguage().getLocalisation(label)
     59    orxonox::Language::getInstance().getLocalisation(label)
    5960
    6061
     
    112113    // ###############################
    113114    //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map.
    114     class _CoreExport Language
     115    class _CoreExport Language : public Singleton<Language>
    115116    {
     117        friend class Singleton<Language>;
    116118        friend class CoreConfiguration;
    117119
     
    120122            ~Language();
    121123
    122             static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }
    123124            void addEntry(const LanguageEntryLabel& label, const std::string& entry);
    124125            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
     
    137138            std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
    138139
    139             static Language* singletonRef_s;
     140            static Language* singletonPtr_s;
    140141    };
    141142}
  • code/branches/resource/src/core/LuaBind.cc

    r3340 r3366  
    4343namespace orxonox
    4444{
    45   LuaBind* LuaBind::singletonRef_s = NULL;
     45  LuaBind* LuaBind::singletonPtr_s = NULL;
    4646
    4747  LuaBind::LuaBind()
    4848  {
    49     assert(LuaBind::singletonRef_s == 0);
    50     LuaBind::singletonRef_s = this;
    51 
    5249    this->includePath_ = Core::getMediaPathString();
    5350
     
    7572  {
    7673    this->closeToluaInterfaces(luaState_);
    77 
    78     assert(singletonRef_s);
    79     LuaBind::singletonRef_s = NULL;
    8074  };
    8175
  • code/branches/resource/src/core/LuaBind.h

    r3359 r3366  
    4545}
    4646
     47#include "util/Singleton.h"
     48
    4749// tolua_begin
    4850namespace orxonox
    4951{
    50   class _CoreExport LuaBind
     52  class _CoreExport LuaBind : public Singleton<LuaBind>
    5153  {
     54// tolua_end
     55    friend class Singleton<LuaBind>;
    5256
    53 // tolua_end
    5457    struct LoadS {
    5558      const char *s;
     
    6164      ~LuaBind();
    6265
    63       inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
     66      static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export
    6467
    6568    void loadFile(const std::string& filename, bool luaTags);
     
    8992
    9093    private:
    91       static LuaBind* singletonRef_s;
     94      static LuaBind* singletonPtr_s;
    9295
    9396      std::string luaSource_;
  • code/branches/resource/src/core/Shell.cc

    r3301 r3366  
    5151    SetConsoleCommandShortcut(OutputHandler, debug);
    5252
    53     Shell* Shell::singletonRef_s = 0;
     53    Shell* Shell::singletonPtr_s = 0;
    5454
    5555    Shell::Shell()
    5656    {
    57         assert(singletonRef_s == 0);
    58         singletonRef_s = this;
    59 
    6057        int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell);
    6158        Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1);
     
    9289        if (this->inputBuffer_)
    9390            delete this->inputBuffer_;
    94         singletonRef_s = 0;
    9591    }
    9692
  • code/branches/resource/src/core/Shell.h

    r3280 r3366  
    6060    };
    6161
    62     class _CoreExport Shell : virtual public OrxonoxClass, public OutputBufferListener
     62    class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener
    6363    {
     64        friend class Singleton<Shell>;
    6465        public:
    6566            Shell();
    6667            virtual ~Shell();
    67 
    68             static Shell& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    6968
    7069            static void clearShell();
     
    148147            ConfigFileType commandHistoryConfigFileType_;
    149148
    150             static Shell* singletonRef_s;
     149            static Shell* singletonPtr_s;
    151150    };
    152151}
  • code/branches/resource/src/core/TclBind.cc

    r3360 r3366  
    4646    SetConsoleCommandShortcut(TclBind, bgerror);
    4747
    48     TclBind* TclBind::singletonRef_s = 0;
     48    TclBind* TclBind::singletonPtr_s = 0;
    4949
    5050    TclBind::TclBind(const std::string& datapath)
    5151    {
    52         assert(singletonRef_s == 0);
    53         singletonRef_s = this;
    5452        this->interpreter_ = 0;
    5553        this->bSetTclDataPath_ = false;
     
    6159        if (this->interpreter_)
    6260            delete this->interpreter_;
    63         singletonRef_s = 0;
    6461    }
    6562
  • code/branches/resource/src/core/TclBind.h

    r3360 r3366  
    3434#include <cassert>
    3535#include <string>
     36#include "util/Singleton.h"
    3637
    3738namespace orxonox
    3839{
    39     class _CoreExport TclBind
     40    class _CoreExport TclBind : public Singleton<TclBind>
    4041    {
     42        friend class Singleton<TclBind>;
    4143        public:
    4244            TclBind(const std::string& datapath);
    4345            ~TclBind();
    44 
    45             static TclBind& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    4646
    4747            static std::string tcl(const std::string& tclcode);
     
    6868            bool bSetTclDataPath_;
    6969
    70             static TclBind* singletonRef_s;
     70            static TclBind* singletonPtr_s;
    7171    };
    7272}
  • code/branches/resource/src/core/TclThreadManager.cc

    r3361 r3366  
    9191        RegisterRootObject(TclThreadManager);
    9292
    93         assert(TclThreadManager::singletonPtr_s == 0);
    94         TclThreadManager::singletonPtr_s = this;
    95 
    9693        this->numInterpreterBundles_ = 0;
    9794
     
    116113    TclThreadManager::~TclThreadManager()
    117114    {
    118         TclThreadManager::singletonPtr_s = 0;
    119 
    120115        delete this->interpreterBundlesMutex_;
    121116//        delete this->mainInterpreterMutex_; // <-- temporary disabled to avoid crash if a thread is still actively queriyng
  • code/branches/resource/src/core/TclThreadManager.h

    r3361 r3366  
    3737#include <string>
    3838
     39#include "util/Singleton.h"
    3940#include "OrxonoxClass.h"
    4041
     
    4344namespace orxonox
    4445{
    45     class _CoreExport TclThreadManager : public OrxonoxClass
     46    class _CoreExport TclThreadManager : public Singleton<TclThreadManager>, public OrxonoxClass
    4647    {
     48        friend class Singleton<TclThreadManager>;
    4749        friend class TclBind;
    4850        friend _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);
     
    5355            TclThreadManager(Tcl::interpreter* interpreter);
    5456            virtual ~TclThreadManager();
    55 
    56             static TclThreadManager& getInstance() { assert(TclThreadManager::singletonPtr_s); return *TclThreadManager::singletonPtr_s; }
    5757
    5858            static unsigned int      create();
  • code/branches/resource/src/core/input/InputManager.cc

    r3327 r3366  
    6464    InputHandler InputHandler::EMPTY;
    6565
    66     InputManager* InputManager::singletonRef_s = 0;
     66    InputManager* InputManager::singletonPtr_s = 0;
    6767
    6868    //! Defines the |= operator for easier use.
     
    9393        RegisterRootObject(InputManager);
    9494
    95         assert(singletonRef_s == 0);
    96         singletonRef_s = this;
    97 
    9895        CCOUT(4) << "Constructing..." << std::endl;
    9996
     
    138135        }
    139136
     137        CCOUT(4) << "Construction complete." << std::endl;
    140138        internalState_ = Nothing;
    141         CCOUT(4) << "Construction complete." << std::endl;
    142139    }
    143140
     
    297294
    298295        CCOUT(4) << "Destruction complete." << std::endl;
    299         singletonRef_s = 0;
    300296    }
    301297
  • code/branches/resource/src/core/input/InputManager.h

    r3327 r3366  
    3737#include <vector>
    3838
     39#include "util/Singleton.h"
    3940#include "core/WindowEventListener.h"
    4041#include "InputState.h"
     
    6263          If the OIS::InputManager or the Keyboard fail, an exception is thrown.
    6364    */
    64     class _CoreExport InputManager : public WindowEventListener
     65    class _CoreExport InputManager : public Singleton<InputManager>, public WindowEventListener
    6566    {
     67        friend class Singleton<InputManager>;
    6668    public:
    6769        //! Represents internal states of the InputManager.
     
    168170            { return this->oisInputManager_; }
    169171
    170         //! Returns a reference to the singleton instance
    171         static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    172 
    173172    private: // functions
    174173        // don't mess with a Singleton
     
    211210        std::set<InputState*>               stateDestroyRequests_; //!< Requests to destroy a state
    212211
    213         static InputManager*                singletonRef_s;        //!< Pointer reference to the singleton
     212        static InputManager*                singletonPtr_s;        //!< Pointer reference to the singleton
    214213    };
    215214}
  • code/branches/resource/src/orxonox/CameraManager.cc

    r3346 r3366  
    4242namespace orxonox
    4343{
    44     CameraManager* CameraManager::singletonRef_s = 0;
     44    CameraManager* CameraManager::singletonPtr_s = 0;
    4545
    4646    CameraManager::CameraManager(Ogre::Viewport* viewport)
    4747        : viewport_(viewport)
    4848    {
    49         assert(singletonRef_s == 0);
    50         singletonRef_s = this;
    51 
    5249        this->fallbackCamera_ = 0;
    5350    }
     
    5552    CameraManager::~CameraManager()
    5653    {
    57         assert(singletonRef_s != 0);
    58         singletonRef_s = 0;
    59 
    6054        if (this->fallbackCamera_)
    6155            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
  • code/branches/resource/src/orxonox/CameraManager.h

    r3196 r3366  
    4141#include <list>
    4242#include "util/OgreForwardRefs.h"
     43#include "util/Singleton.h"
    4344
    4445namespace orxonox
    4546{
    46     class _OrxonoxExport CameraManager
     47    class _OrxonoxExport CameraManager : public Singleton<CameraManager>
    4748    {
     49            friend class Singleton<CameraManager>;
    4850        public:
    4951            CameraManager(Ogre::Viewport* viewport);
     
    5759            void useCamera(Ogre::Camera* camera);
    5860
    59             static CameraManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    60             static CameraManager* getInstancePtr() { return singletonRef_s; }
     61            static CameraManager* getInstancePtr() { return singletonPtr_s; }
    6162
    6263        private:
     
    6768            Ogre::Camera*         fallbackCamera_;
    6869
    69             static CameraManager* singletonRef_s;
     70            static CameraManager* singletonPtr_s;
    7071    };
    7172}
  • code/branches/resource/src/orxonox/LevelManager.cc

    r3343 r3366  
    4545    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
    4646
    47     LevelManager* LevelManager::singletonRef_s = 0;
     47    LevelManager* LevelManager::singletonPtr_s = 0;
    4848
    4949    LevelManager::LevelManager()
    5050    {
    51         assert(singletonRef_s == 0);
    52         singletonRef_s = this;
    53 
    5451        RegisterRootObject(LevelManager);
    5552        this->setConfigValues();
     
    6461    LevelManager::~LevelManager()
    6562    {
    66         assert(singletonRef_s != 0);
    67         singletonRef_s = 0;
    6863    }
    6964
  • code/branches/resource/src/orxonox/LevelManager.h

    r3339 r3366  
    3535#include <list>
    3636#include <string>
     37
     38#include "util/Singleton.h"
    3739#include "core/OrxonoxClass.h"
    3840
     
    4244    class _OrxonoxExport LevelManager
    4345    // tolua_end
    44         : public OrxonoxClass
     46        : public Singleton<LevelManager>, public OrxonoxClass
    4547    { // tolua_export
     48            friend class Singleton<LevelManager>;
    4649        public:
    4750            LevelManager();
     
    5962            std::string getAvailableLevelListItem(unsigned int index) const; //tolua_export
    6063
    61             static LevelManager* getInstancePtr() { return singletonRef_s; }
    62             static LevelManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
     64            static LevelManager* getInstancePtr() { return singletonPtr_s; }
     65            static LevelManager& getInstance()    { return Singleton<LevelManager>::getInstance(); } // tolua_export
    6366
    6467        private:
     
    7376            std::string defaultLevelName_;
    7477
    75             static LevelManager* singletonRef_s;
     78            static LevelManager* singletonPtr_s;
    7679    }; // tolua_export
    7780} // tolua_export
  • code/branches/resource/src/orxonox/PawnManager.cc

    r3196 r3366  
    3434namespace orxonox
    3535{
    36     PawnManager* PawnManager::singletonRef_s = 0;
     36    PawnManager* PawnManager::singletonPtr_s = 0;
    3737
    3838    PawnManager::PawnManager()
    3939    {
    4040        RegisterRootObject(PawnManager);
    41 
    42         assert(PawnManager::singletonRef_s == 0);
    43         PawnManager::singletonRef_s = this;
    4441    }
    4542
    4643    PawnManager::~PawnManager()
    4744    {
    48         assert(PawnManager::singletonRef_s != 0);
    49         PawnManager::singletonRef_s = 0;
    5045    }
    5146
    5247    void PawnManager::touch()
    5348    {
    54         if (!PawnManager::singletonRef_s)
     49        if (!PawnManager::singletonPtr_s)
    5550            new PawnManager();
    5651    }
  • code/branches/resource/src/orxonox/PawnManager.h

    r3196 r3366  
    3131
    3232#include "OrxonoxPrereqs.h"
     33
     34#include "util/Singleton.h"
    3335#include "interfaces/Tickable.h"
    3436
    3537namespace orxonox
    3638{
    37     class _OrxonoxExport PawnManager : public Tickable
     39    class _OrxonoxExport PawnManager : protected Singleton<PawnManager>, public Tickable
    3840    {
     41            friend class Singleton<PawnManager>;
    3942        public:
    4043            static void touch();
     
    4649            virtual ~PawnManager();
    4750
    48             static PawnManager* singletonRef_s;
     51            static PawnManager* singletonPtr_s;
    4952    };
    5053}
  • code/branches/resource/src/orxonox/PlayerManager.cc

    r3297 r3366  
    3737namespace orxonox
    3838{
    39     PlayerManager* PlayerManager::singletonRef_s = 0;
     39    PlayerManager* PlayerManager::singletonPtr_s = 0;
    4040
    4141    PlayerManager::PlayerManager()
    4242    {
    4343        RegisterRootObject(PlayerManager);
    44 
    45         assert(singletonRef_s == 0);
    46         singletonRef_s = this;
    4744
    4845        this->getConnectedClients();
     
    5148    PlayerManager::~PlayerManager()
    5249    {
    53         assert(singletonRef_s);
    54         singletonRef_s = 0;
    5550    }
    5651
  • code/branches/resource/src/orxonox/PlayerManager.h

    r3196 r3366  
    3434#include <cassert>
    3535#include <map>
     36#include "util/Singleton.h"
    3637#include "network/ClientConnectionListener.h"
    3738
    3839namespace orxonox
    3940{
    40     class _OrxonoxExport PlayerManager : public ClientConnectionListener
     41    class _OrxonoxExport PlayerManager : public Singleton<PlayerManager>, public ClientConnectionListener
    4142    {
     43            friend class Singleton<PlayerManager>;
    4244        public:
    4345            PlayerManager();
    4446            virtual ~PlayerManager();
    45 
    46             inline static PlayerManager& getInstance()
    47                 { assert(singletonRef_s); return *singletonRef_s; }
    4847
    4948            PlayerInfo* getClient(unsigned int clientID) const;
     
    5756            std::map<unsigned int, PlayerInfo*> clients_;
    5857
    59             static PlayerManager* singletonRef_s;
     58            static PlayerManager* singletonPtr_s;
    6059    };
    6160}
  • code/branches/resource/src/orxonox/objects/pickup/BaseItem.h

    r3196 r3366  
    5151            Daniel 'Huty' Haggenmueller
    5252    */
    53     class _OrxonoxExport BaseItem
    54 // tolua_end
    55         : public BaseObject
    56 // tolua_begin
     53    class _OrxonoxExport BaseItem : public BaseObject
    5754    {
    5855// tolua_end
  • code/branches/resource/src/orxonox/objects/pickup/PickupInventory.h

    r3196 r3366  
    4343namespace orxonox
    4444{
    45 // tolua_end
    4645    /**
    4746        @brief Static class for the inventory GUI window.
    4847        @author Daniel 'Huty' Haggenmueller
    4948    */
    50 // tolua_begin
    5149    class _OrxonoxExport PickupInventory
    5250    {
  • code/branches/resource/src/orxonox/objects/quest/QuestDescription.h

    r3196 r3366  
    5454        Damian 'Mozork' Frick
    5555    */
    56     class _OrxonoxExport QuestDescription
     56    class _OrxonoxExport QuestDescription : public BaseObject
     57    {
    5758// tolua_end
    58         : public BaseObject
    59     { // tolua_export
    6059        public:
    6160            QuestDescription(BaseObject* creator);
  • code/branches/resource/src/orxonox/objects/quest/QuestManager.cc

    r3349 r3366  
    4747{
    4848    //! Pointer to the current (and single) instance of this class.
    49     /*static*/ QuestManager* QuestManager::singletonRef_s = NULL;
     49    /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL;
    5050
    5151    /**
     
    5858    {
    5959        RegisterRootObject(QuestManager);
    60 
    61         assert(singletonRef_s == 0);
    62         singletonRef_s = this;
    6360    }
    6461
     
    7067    {
    7168
    72     }
    73 
    74     /**
    75     @brief
    76         Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.
    77     @return
    78         Returns a reference to the single instance of the Quest Manager.
    79     */
    80     /*static*/ QuestManager & QuestManager::getInstance()
    81     {
    82         assert(singletonRef_s);
    83         return *singletonRef_s;
    8469    }
    8570
  • code/branches/resource/src/orxonox/objects/quest/QuestManager.h

    r3196 r3366  
    4040#include <map>
    4141#include <string>
     42
     43#include "util/Singleton.h"
    4244#include "core/OrxonoxClass.h"
    4345
     
    7173        Damian 'Mozork' Frick
    7274    */
    73     class _OrxonoxExport QuestManager
    74 // tolua_end
    75         : public OrxonoxClass
    76 // tolua_begin
     75    class _OrxonoxExport QuestManager : public Singleton<QuestManager>, public orxonox::OrxonoxClass
    7776    {
    7877// tolua_end
     78            friend class Singleton<QuestManager>;
    7979        public:
    8080            QuestManager();
    8181            virtual ~QuestManager();
    8282
    83             static QuestManager& getInstance(); // tolua_export //!< Returns a reference to the single instance of the Quest Manager.
     83            //! Returns a reference to the single instance of the Quest Manager.
     84            static QuestManager& getInstance() { return Singleton<QuestManager>::getInstance(); } // tolua_export
    8485
    8586            bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
     
    9293
    9394        private:
    94             static QuestManager* singletonRef_s;
     95            static QuestManager* singletonPtr_s;
    9596
    9697            std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
  • code/branches/resource/src/orxonox/overlays/console/InGameConsole.cc

    r3327 r3366  
    6060    SetConsoleCommand(InGameConsole, closeConsole, true);
    6161
    62     InGameConsole* InGameConsole::singletonRef_s = 0;
     62    InGameConsole* InGameConsole::singletonPtr_s = 0;
    6363
    6464    /**
     
    7676        RegisterObject(InGameConsole);
    7777
    78         assert(singletonRef_s == 0);
    79         singletonRef_s = this;
    80 
    8178        this->bActive_ = false;
    8279        this->cursor_ = 0.0f;
     
    131128        if (this->consoleOverlay_)
    132129            Ogre::OverlayManager::getSingleton().destroy(consoleOverlay_);
    133 
    134         singletonRef_s = 0;
    135130    }
    136131
  • code/branches/resource/src/orxonox/overlays/console/InGameConsole.h

    r3327 r3366  
    3434
    3535#include <string>
     36
    3637#include "util/OgreForwardRefs.h"
     38#include "util/Singleton.h"
    3739#include "core/Shell.h"
    3840#include "core/WindowEventListener.h"
     
    4042namespace orxonox
    4143{
    42     class _OrxonoxExport InGameConsole : public ShellListener, public WindowEventListener
     44    class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener
    4345    {
     46        friend class Singleton<InGameConsole>;
    4447    public: // functions
    4548        InGameConsole();
     
    5154
    5255        void update(const Clock& time);
    53 
    54         static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    55         static InGameConsole* getInstancePtr() { return singletonRef_s; }
    5656
    5757        static void openConsole();
     
    112112        bool bHidesAllInput_;
    113113
    114         static InGameConsole* singletonRef_s;
     114        static InGameConsole* singletonPtr_s;
    115115    };
    116116}
  • code/branches/resource/src/orxonox/overlays/notifications/NotificationManager.cc

    r3196 r3366  
    4646    const std::string NotificationManager::NONE = "none";
    4747
    48     NotificationManager* NotificationManager::singletonRef_s = NULL;
     48    NotificationManager* NotificationManager::singletonPtr_s = NULL;
    4949
    5050    /**
     
    5555    {
    5656        RegisterRootObject(NotificationManager);
    57 
    58         assert(singletonRef_s == 0);
    59         singletonRef_s = this;
    6057
    6158        this->highestIndex_ = 0;
     
    7067    }
    7168
    72     /**
    73     @brief
    74         Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with.
    75     @return
    76         Returns a reference to the single instance of the NotificationManager.
    77     */
    78     /*static*/ NotificationManager & NotificationManager::getInstance()
    79     {
    80         assert(singletonRef_s);
    81         return *singletonRef_s;
    82     }
    83    
    8469    /**
    8570    @brief
  • code/branches/resource/src/orxonox/overlays/notifications/NotificationManager.h

    r3196 r3366  
    4040#include <map>
    4141#include <string>
     42
     43#include "util/Singleton.h"
    4244#include "core/OrxonoxClass.h"
    4345
     
    5254        Damian 'Mozork' Frick
    5355    */
    54     class _OrxonoxExport NotificationManager : public OrxonoxClass
     56    class _OrxonoxExport NotificationManager : public Singleton<NotificationManager>, public OrxonoxClass
    5557    {
     58            friend class Singleton<NotificationManager>;
    5659        public:
    5760            NotificationManager();
     
    6063            static const std::string ALL;
    6164            static const std::string NONE;
    62 
    63             static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
    6465
    6566            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
     
    8889
    8990        private:
    90             static NotificationManager* singletonRef_s;
     91            static NotificationManager* singletonPtr_s;
    9192
    9293            int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
  • code/branches/resource/src/orxonox/sound/SoundManager.cc

    r3342 r3366  
    3838namespace orxonox
    3939{
    40     SoundManager* SoundManager::singletonRef_s = NULL;
     40    SoundManager* SoundManager::singletonPtr_s = NULL;
    4141
    4242    /**
     
    4545    SoundManager::SoundManager()
    4646    {
    47         assert(singletonRef_s == NULL);
    48         singletonRef_s = this;
    49 
    5047        this->device_ = NULL;
    5148        this->soundavailable_ = true;
     
    9390    SoundManager::~SoundManager()
    9491    {
    95         assert(singletonRef_s != NULL);
    96         singletonRef_s = NULL;
    97 
    9892        alcDestroyContext(this->context_);
    9993        alcCloseDevice(this->device_);
  • code/branches/resource/src/orxonox/sound/SoundManager.h

    r3280 r3366  
    3232#include <cassert>
    3333#include <list>
     34#include "util/Singleton.h"
    3435#include "interfaces/Tickable.h"
    3536
     
    4243     *
    4344     */
    44     class _OrxonoxExport SoundManager : public Tickable
     45    class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public Tickable
    4546    {
     47        friend class Singleton<SoundManager>;
    4648    public:
    4749        SoundManager();
     
    5254        bool isSoundAvailable();
    5355
    54         static SoundManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    55 
    5656    private:
    5757        ALCdevice* device_;
     
    6060        bool soundavailable_;
    6161
    62         static SoundManager* singletonRef_s;
     62        static SoundManager* singletonPtr_s;
    6363    }; // class SoundManager
    6464} // namespace orxonox
  • code/branches/resource/src/util/SignalHandler.cc

    r3301 r3366  
    4141namespace orxonox
    4242{
    43     SignalHandler* SignalHandler::singletonRef_s = NULL;
     43    SignalHandler* SignalHandler::singletonPtr_s = NULL;
    4444}
    4545
     
    122122      }
    123123      // if the signalhandler has already been destroyed then don't do anything
    124       if( SignalHandler::singletonRef_s == 0 )
     124      if( SignalHandler::singletonPtr_s == 0 )
    125125      {
    126126        COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl;
  • code/branches/resource/src/util/SignalHandler.h

    r3068 r3366  
    4040#include <list>
    4141#include <string>
     42#include "Singleton.h"
    4243
    4344namespace orxonox
     
    6768    typedef std::list<SignalCallbackRec> SignalCallbackList;
    6869
    69     class SignalHandler
     70    class SignalHandler : public Singleton<SignalHandler>
    7071    {
     72        friend class Singleton<SignalHandler>;
    7173    public:
    72         SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
    73         ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; }
    74         inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
     74        SignalHandler()  { }
     75        ~SignalHandler() { }
    7576
    7677        void registerCallback( SignalCallback cb, void * someData );
     
    8788        SignalCallbackList callbackList;
    8889
    89         static SignalHandler* singletonRef_s;
     90        static SignalHandler* singletonPtr_s;
    9091
    9192        std::string appName;
     
    9899namespace orxonox
    99100{
    100     class _UtilExport SignalHandler
     101    class _UtilExport SignalHandler : public Singleton<SignalHandler>
    101102    {
     103        friend class Singleton<SignalHandler>;
    102104    public:
    103         SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
    104         ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; }
    105         inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
     105        SignalHandler()  { }
     106        ~SignalHandler() { }
    106107        void doCatch( const std::string & appName, const std::string & filename ) {}
    107108        void dontCatch() {}
     
    109110
    110111    private:
    111         static SignalHandler* singletonRef_s;
     112        static SignalHandler* singletonPtr_s;
    112113    };
    113114}
  • code/branches/resource/src/util/Singleton.h

    r3364 r3366  
    4040        Usage:
    4141        Inherit publicly from Singleton<MyClass> and provide access to
    42         MyClass::singletonRef_s.
    43         This can be done with a friend declaration.
     42        MyClass::singletonPtr_s.
     43        This can easily be done with a friend declaration.
    4444    */
    4545    template <class T>
     
    5050        static T& getInstance()
    5151        {
    52             assert(T::singletonRef_s != NULL);
    53             return *T::singletonRef_s;
     52            assert(T::singletonPtr_s != NULL);
     53            return *T::singletonPtr_s;
    5454        }
    5555
    5656    protected:
    57         // Constructor sets the singleton instance pointer
     57        //! Constructor sets the singleton instance pointer
    5858        Singleton()
    5959        {
    60             assert(T::singletonRef_s == NULL);
    61             T::singletonRef_s = static_cast<T*>(this);
     60            assert(T::singletonPtr_s == NULL);
     61            T::singletonPtr_s = static_cast<T*>(this);
    6262        }
    63         // Constructor resets the singleton instance pointer
     63
     64        //! Constructor resets the singleton instance pointer
    6465        ~Singleton()
    6566        {
    66             assert(T::singletonRef_s != NULL);
    67             T::singletonRef_s = NULL;
     67            assert(T::singletonPtr_s != NULL);
     68            T::singletonPtr_s = NULL;
    6869        }
    6970
Note: See TracChangeset for help on using the changeset viewer.