Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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/orxonox
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.