Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5867


Ignore:
Timestamp:
Oct 4, 2009, 12:02:28 AM (15 years ago)
Author:
rgrieder
Message:

Modified Scoped Singleton concept: Derive from Singleton normally, but place an important pre-main() instruction in the source file: ManageScopedSingleton(className, scope) (it's a macro).
This causes the Singleton to be created and destroyed with the Scope. Thus if a Singleton c'tor throws, it is much easier to react accordingly.

Location:
code/branches/core5/src
Files:
2 added
1 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/CMakeLists.txt

    r5855 r5867  
    3737  PathConfig.cc
    3838  Resource.cc
     39  ScopedSingletonManager.cc
    3940  WindowEventListener.cc
    4041
  • code/branches/core5/src/libraries/core/Core.cc

    r5863 r5867  
    6565#include "Language.h"
    6666#include "LuaState.h"
     67#include "ScopedSingletonManager.h"
    6768#include "Shell.h"
    6869#include "TclBind.h"
     
    433434    {
    434435        // singletons from other libraries
    435         Scope<ScopeID::Root>::update(time);
     436        ScopedSingletonManager::update(time, ScopeID::Root);
    436437        if (this->bGraphicsLoaded_)
    437438        {
     
    441442            this->guiManager_->update(time);
    442443            // graphics singletons from other libraries
    443             Scope<ScopeID::Graphics>::update(time);
     444            ScopedSingletonManager::update(time, ScopeID::Graphics);
    444445        }
    445446        // process thread commands
  • code/branches/core5/src/libraries/util/Scope.h

    r5858 r5867  
    7373            //! Gets called if the scope is deactivated
    7474            virtual void deactivated() = 0;
    75             //! Gets called if the scope is updated
    76             virtual void updated(const Clock& time) = 0;
    7775
    7876        private:
     
    124122                return (ScopeManager::instanceCounts_s[scope] > 0);
    125123            }
    126 
    127             //! Update method for the ScopeListeners (to implement singleton updates)
    128             static void update(const Clock& time)
    129             {
    130                 if (isActive())
    131                 {
    132                     for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
    133                         (*(it++))->updated(time);
    134                 }
    135             }
    136124    };
    137125}
  • code/branches/core5/src/libraries/util/Singleton.h

    r5738 r5867  
    5555        }
    5656
     57        //! Update method called by ClassSingletonManager (if used)
     58        void updateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->update(time); }
     59        //! Empty update method for the static polymorphism
     60        void update(const Clock& time) { }
     61
    5762    protected:
    5863        //! Constructor sets the singleton instance pointer
  • code/branches/core5/src/modules/questsystem/QuestManager.cc

    r5800 r5867  
    4141#include "core/ConsoleCommand.h"
    4242#include "core/LuaState.h"
     43#include "core/ScopedSingletonManager.h"
    4344#include "infos/PlayerInfo.h"
    4445#include "overlays/GUIOverlay.h"
     
    5657    //! Pointer to the current (and single) instance of this class.
    5758    /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL;
     59    ManageScopedSingleton(QuestManager, ScopeID::Root);
    5860
    5961    /**
  • code/branches/core5/src/modules/questsystem/QuestManager.h

    r5850 r5867  
    4242#include <string>
    4343
    44 #include "util/ScopedSingleton.h"
     44#include "util/Singleton.h"
    4545#include "core/OrxonoxClass.h"
    4646
     
    5959    class _QuestsystemExport QuestManager
    6060// tolua_end
    61         : public ScopedSingleton<QuestManager, ScopeID::Root>, public orxonox::OrxonoxClass
     61        : public Singleton<QuestManager>, public orxonox::OrxonoxClass
    6262    { // tolua_export
    6363
    64             friend class ScopedSingleton<QuestManager, ScopeID::Root>;
     64            friend class Singleton<QuestManager>;
    6565            friend class QuestGUI;
    6666
     
    7070
    7171            //! Returns a reference to the single instance of the Quest Manager.
    72             static QuestManager& getInstance() { return ScopedSingleton<QuestManager, ScopeID::Root>::getInstance(); } // tolua_export
     72            static QuestManager& getInstance() { return Singleton<QuestManager>::getInstance(); } // tolua_export
    7373
    7474            //! Retreive the main window for the GUI.
  • code/branches/core5/src/modules/questsystem/QuestsystemPrecompiledHeaders.h

    r5749 r5867  
    5151#include <OgreColourValue.h> // 16
    5252
    53 #include <tinyxml/ticpp.h>        // 14
    54 #include "util/ScopedSingleton.h" // 13
     53#include <tinyxml/ticpp.h>   // 14
     54#include "util/Singleton.h" // 13
    5555
    5656///////////////////////////////////////////
  • code/branches/core5/src/modules/questsystem/notifications/NotificationManager.cc

    r5760 r5867  
    3737
    3838#include "core/CoreIncludes.h"
     39#include "core/ScopedSingletonManager.h"
    3940#include "Notification.h"
    4041#include "interfaces/NotificationListener.h"
     
    4748
    4849    NotificationManager* NotificationManager::singletonPtr_s = NULL;
     50    ManageScopedSingleton(NotificationManager, ScopeID::Root);
    4951
    5052    /**
  • code/branches/core5/src/modules/questsystem/notifications/NotificationManager.h

    r5850 r5867  
    4141#include <string>
    4242
    43 #include "util/ScopedSingleton.h"
     43#include "util/Singleton.h"
    4444#include "core/OrxonoxClass.h"
    4545
     
    5353        Damian 'Mozork' Frick
    5454    */
    55     class _QuestsystemExport NotificationManager : public ScopedSingleton<NotificationManager, ScopeID::Root>, public OrxonoxClass
     55    class _QuestsystemExport NotificationManager : public Singleton<NotificationManager>, public OrxonoxClass
    5656    {
    57             friend class ScopedSingleton<NotificationManager, ScopeID::Root>;
     57            friend class Singleton<NotificationManager>;
    5858        public:
    5959            NotificationManager();
  • code/branches/core5/src/orxonox/CameraManager.cc

    r5850 r5867  
    2626 *
    2727 */
     28
    2829#include "CameraManager.h"
    2930
     
    3738#include "core/GUIManager.h"
    3839#include "core/ObjectList.h"
     40#include "core/ScopedSingletonManager.h"
    3941#include "tools/Shader.h"
    4042#include "graphics/Camera.h"
     
    4345namespace orxonox
    4446{
     47    ManageScopedSingleton(CameraManager, ScopeID::Graphics);
    4548    CameraManager* CameraManager::singletonPtr_s = 0;
    4649
  • code/branches/core5/src/orxonox/CameraManager.h

    r5850 r5867  
    4141#include <list>
    4242#include "util/OgreForwardRefs.h"
    43 #include "util/ScopedSingleton.h"
     43#include "util/Singleton.h"
    4444#include "core/OrxonoxClass.h"
    4545#include "core/SmartPtr.h"
     
    4747namespace orxonox
    4848{
    49     class _OrxonoxExport CameraManager : public ScopedSingleton<CameraManager, ScopeID::Graphics>, public OrxonoxClass
     49    class _OrxonoxExport CameraManager : public Singleton<CameraManager>, public OrxonoxClass
    5050    {
    51             friend class ScopedSingleton<CameraManager, ScopeID::Graphics>;
     51            friend class Singleton<CameraManager>;
    5252        public:
    5353            CameraManager();
  • code/branches/core5/src/orxonox/LevelManager.cc

    r5836 r5867  
    3636#include "core/CoreIncludes.h"
    3737#include "core/Loader.h"
     38#include "core/ScopedSingletonManager.h"
    3839#include "PlayerManager.h"
    3940#include "Level.h"
     
    4344    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
    4445
     46    ManageScopedSingleton(LevelManager, ScopeID::Root);
    4547    LevelManager* LevelManager::singletonPtr_s = 0;
    4648
  • code/branches/core5/src/orxonox/LevelManager.h

    r5850 r5867  
    3636#include <string>
    3737
    38 #include "util/ScopedSingleton.h"
     38#include "util/Singleton.h"
    3939#include "core/OrxonoxClass.h"
    4040
     
    4444    class _OrxonoxExport LevelManager
    4545    // tolua_end
    46         : public ScopedSingleton<LevelManager, ScopeID::Root>, public OrxonoxClass
     46        : public Singleton<LevelManager>, public OrxonoxClass
    4747    { // tolua_export
    48             friend class ScopedSingleton<LevelManager, ScopeID::Root>;
     48            friend class Singleton<LevelManager>;
    4949        public:
    5050            LevelManager();
     
    6363
    6464            static LevelManager* getInstancePtr() { return singletonPtr_s; }
    65             static LevelManager& getInstance()    { return ScopedSingleton<LevelManager, ScopeID::Root>::getInstance(); } // tolua_export
     65            static LevelManager& getInstance()    { return Singleton<LevelManager>::getInstance(); } // tolua_export
    6666
    6767        private:
  • code/branches/core5/src/orxonox/PlayerManager.cc

    r5820 r5867  
    3131#include "core/CoreIncludes.h"
    3232#include "core/GameMode.h"
     33#include "core/ScopedSingletonManager.h"
    3334#include "Level.h"
    3435#include "infos/HumanPlayer.h"
     
    3839{
    3940    PlayerManager* PlayerManager::singletonPtr_s = 0;
     41    ManageScopedSingleton(PlayerManager, ScopeID::Root);
    4042
    4143    PlayerManager::PlayerManager()
  • code/branches/core5/src/orxonox/PlayerManager.h

    r5850 r5867  
    3434#include <cassert>
    3535#include <map>
    36 #include "util/ScopedSingleton.h"
     36#include "util/Singleton.h"
    3737#include "network/ClientConnectionListener.h"
    3838
    3939namespace orxonox
    4040{
    41     class _OrxonoxExport PlayerManager : public ScopedSingleton<PlayerManager, ScopeID::Root>, public ClientConnectionListener
     41    class _OrxonoxExport PlayerManager : public Singleton<PlayerManager>, public ClientConnectionListener
    4242    {
    43             friend class ScopedSingleton<PlayerManager, ScopeID::Root>;
     43            friend class Singleton<PlayerManager>;
    4444        public:
    4545            PlayerManager();
  • code/branches/core5/src/orxonox/overlays/InGameConsole.cc

    r5855 r5867  
    4848#include "core/ConfigValueIncludes.h"
    4949#include "core/ConsoleCommand.h"
     50#include "core/ScopedSingletonManager.h"
    5051#include "core/input/InputManager.h"
    5152#include "core/input/InputState.h"
     
    6162
    6263    InGameConsole* InGameConsole::singletonPtr_s = 0;
     64    ManageScopedSingleton(InGameConsole, ScopeID::Graphics);
    6365
    6466    /**
  • code/branches/core5/src/orxonox/overlays/InGameConsole.h

    r5850 r5867  
    3636
    3737#include "util/OgreForwardRefs.h"
    38 #include "util/ScopedSingleton.h"
     38#include "util/Singleton.h"
    3939#include "core/Shell.h"
    4040#include "core/WindowEventListener.h"
     
    4242namespace orxonox
    4343{
    44     class _OrxonoxExport InGameConsole : public ScopedSingleton<InGameConsole, ScopeID::Graphics>, public ShellListener, public WindowEventListener
     44    class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener
    4545    {
    46         friend class ScopedSingleton<InGameConsole, ScopeID::Graphics>;
     46        friend class Singleton<InGameConsole>;
    4747    public: // functions
    4848        InGameConsole();
  • code/branches/core5/src/orxonox/sound/SoundManager.cc

    r5738 r5867  
    3232
    3333#include "util/Math.h"
     34#include "core/ScopedSingletonManager.h"
    3435#include "CameraManager.h"
    3536#include "graphics/Camera.h"
     
    3940{
    4041    SoundManager* SoundManager::singletonPtr_s = NULL;
     42    ManageScopedSingleton(SoundManager, ScopeID::Graphics);
    4143
    4244    /**
  • code/branches/core5/src/orxonox/sound/SoundManager.h

    r5850 r5867  
    3232#include <cassert>
    3333#include <list>
    34 #include "util/ScopedSingleton.h"
     34#include "util/Singleton.h"
    3535#include "tools/interfaces/Tickable.h"
    3636
     
    4343     *
    4444     */
    45     class _OrxonoxExport SoundManager : public ScopedSingleton<SoundManager, ScopeID::Graphics>, public Tickable
     45    class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public Tickable
    4646    {
    47         friend class ScopedSingleton<SoundManager, ScopeID::Graphics>;
     47        friend class Singleton<SoundManager>;
    4848    public:
    4949        SoundManager();
Note: See TracChangeset for help on using the changeset viewer.