Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2015, 11:51:05 AM (10 years ago)
Author:
landauf
Message:

renamed ScopedSingletonManager to ScopedSingletonWrapper. removed static maps.

Location:
code/branches/core7/src/libraries/core/singleton
Files:
1 deleted
2 edited
1 moved

Legend:

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

    r10407 r10458  
    11ADD_SOURCE_FILES(CORE_SRC_FILES
    22  Scope.cc
    3   ScopedSingletonManager.cc
    43)
  • code/branches/core7/src/libraries/core/singleton/Scope.h

    r10412 r10458  
    4646Scopes are usually used to control the creation and destruction of Singletons.
    4747
    48 @see orxonox::ScopedSingletonManager
    4948@see orxonox::Singleton
    5049*/
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h

    r10457 r10458  
    3030    @file
    3131    @ingroup SingletonScope
    32     @brief Definition of orxonox::ScopedSingletonManager, orxonox::ClassScopedSingletonManager, and the ManageScopedSingleton macro.
    33 
    34     ScopedSingletonManager is used to create and destroy Singletons that belong to
     32    @brief Definition of orxonox::ScopedSingletonWrapper, orxonox::ClassScopedSingletonWrapper, and the ManageScopedSingleton macro.
     33
     34    ScopedSingletonWrapper is used to create and destroy Singletons that belong to
    3535    a given Scope. For each one of these singletons, the macro ManageScopedSingleton()
    36     has to be called to register the singleton with orxonox::ScopedSingletonManager.
     36    has to be called to register the wrapper with orxonox::ScopeManager.
    3737
    3838    See @ref SingletonExample "this code" for an example.
     
    4242*/
    4343
    44 #ifndef __ScopedSingletonManager_H__
    45 #define __ScopedSingletonManager_H__
     44#ifndef __ScopedSingletonWrapper_H__
     45#define __ScopedSingletonWrapper_H__
    4646
    4747#include "core/CorePrereqs.h"
    4848
    4949#include <cassert>
    50 #include <map>
    5150#include "util/Exception.h"
    5251#include "util/Singleton.h"
     
    5453
    5554/**
    56     @brief Registers an orxonox::Singleton with orxonox::ScopedSingletonManager.
     55    @brief Creates an orxonox::ScopedSingletonWrapper for an orxonox::Singleton and registers it with orxonox::ScopeManager.
    5756    @param className The name of the singleton class
    5857    @param scope The scope in which the singleton should exist
    5958    @param allowedToFail If true, the singleton is allowed to fail and thus a try-catch block is used when creating the singleton.
    6059
    61     If this macro is called for a singleton, it is registered with ScopedSingletonManager
     60    If this macro is called for a singleton, it is wrapped in a ScopedSingletonWrapper and registered with ScopeManager
    6261    and will thus be created if its scope becomes active and destroyed if is deactivated.
    6362
     
    6665    be destroyed (unless the singleton explicitly deletes itself). To allow controlled
    6766    construction and destruction, the singleton can be put within a virtual scope. This is
    68     done by registering the singleton class with orxonox::ScopedSingletonManager. To
     67    done by registering the singleton class with orxonox::ScopeManager. To
    6968    do so, the ManageScopedSingleton() macro has to be called:
    7069
     
    8483#define ManageScopedSingleton(className, scope, allowedToFail) \
    8584    className* className::singletonPtr_s = NULL; \
    86     static ClassScopedSingletonManager<className, scope, allowedToFail> className##ScopedSingletonManager(#className)
     85    static ClassScopedSingletonWrapper<className, scope, allowedToFail> className##ScopedSingletonWrapper(#className)
    8786
    8887namespace orxonox
    8988{
    9089    /**
    91         @brief Base class of ClassScopedSingletonManager. Keeps track of all existing ScopedSingletonManagers
    92         and stores them in a map, sorted by the scope they belong to.
     90        @brief Base class of ClassScopedSingletonWrapper.
    9391    */
    94     class _CoreExport ScopedSingletonManager
     92    class _CoreExport ScopedSingletonWrapper
    9593    {
    9694        public:
    9795            /// Constructor: Initializes all the values
    98             ScopedSingletonManager(const std::string& className, ScopeID::Value scope)
     96            ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope)
    9997                : className_(className)
    10098                , scope_(scope)
    10199            { }
    102             virtual ~ScopedSingletonManager() { }
    103 
    104             /// Adds a new instance of ScopedSingletonManager to the map.
    105             static void addManager(ScopedSingletonManager* manager);
    106 
    107             static std::map<std::string, ScopedSingletonManager*>& getManagers();
    108             typedef std::multimap<ScopeID::Value, ScopedSingletonManager*> ManagerMultiMap;
     100            virtual ~ScopedSingletonWrapper() { }
    109101
    110102        protected:
     
    114106
    115107    /**
    116         @anchor ClassScopedSingletonManager
     108        @anchor ClassScopedSingletonWrapper
    117109
    118110        @brief Manages a scoped singleton for a given scope.
     
    130122    */
    131123    template <class T, ScopeID::Value scope, bool allowedToFail>
    132     class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener
     124    class ClassScopedSingletonWrapper : public ScopedSingletonWrapper, public ScopeListener
    133125    {
    134126    public:
    135         //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener
    136         ClassScopedSingletonManager(const std::string& className)
    137             : ScopedSingletonManager(className, scope)
     127        //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
     128        ClassScopedSingletonWrapper(const std::string& className)
     129            : ScopedSingletonWrapper(className, scope)
    138130            , ScopeListener(scope)
    139131            , singletonPtr_(NULL)
    140132        {
    141             ScopedSingletonManager::addManager(this);
    142         }
    143 
    144         ~ClassScopedSingletonManager()
     133        }
     134
     135        ~ClassScopedSingletonWrapper()
    145136        {
    146137        }
     
    177168
    178169    /**
    179         @brief This class partially spezializes ClassScopedSingletonManager for classes @a T that are allowed to fail.
     170        @brief This class partially spezializes ClassScopedSingletonWrapper for classes @a T that are allowed to fail.
    180171        @param T The managed singleton class
    181172        @param scope The scope in which the singleton @a T should be active
    182173
    183         Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonManager
     174        Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonWrapper
    184175        uses a try-catch block to handle exceptions.
    185176
    186         See @ref ClassScopedSingletonManager for a full documentation of the basis template.
     177        See @ref ClassScopedSingletonWrapper for a full documentation of the basis template.
    187178    */
    188179    template <class T, ScopeID::Value scope>
    189     class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener
     180    class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper, public ScopeListener
    190181    {
    191182    public:
    192         //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener
    193         ClassScopedSingletonManager(const std::string& className)
    194             : ScopedSingletonManager(className, scope)
     183        //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
     184        ClassScopedSingletonWrapper(const std::string& className)
     185            : ScopedSingletonWrapper(className, scope)
    195186            , ScopeListener(scope)
    196187            , singletonPtr_(NULL)
    197188        {
    198             ScopedSingletonManager::addManager(this);
    199         }
    200 
    201         ~ClassScopedSingletonManager()
     189        }
     190
     191        ~ClassScopedSingletonWrapper()
    202192        {
    203193        }
     
    241231}
    242232
    243 #endif /* __ScopedSingletonManager_H__ */
     233#endif /* __ScopedSingletonWrapper_H__ */
Note: See TracChangeset for help on using the changeset viewer.