Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 2, 2010, 3:16:08 AM (14 years ago)
Author:
landauf
Message:

added documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/doc/src/libraries/util/ScopedSingletonManager.h

    r7284 r7323  
    2626 *
    2727 */
     28
     29/**
     30    @file
     31    @ingroup Util 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
     35    a given Scope. For each one of these singletons, the macro ManageScopedSingleton()
     36    has to be called to register the singleton with orxonox::ScopedSingletonManager.
     37
     38    See @ref SingletonExample "this code" for an example.
     39
     40    @see orxonox::Singleton
     41    @see orxonox::Scope
     42*/
    2843
    2944#ifndef __ScopedSingletonManager_H__
     
    3853#include "util/Singleton.h"
    3954
     55/**
     56    @brief Registers an orxonox::Singleton with orxonox::ScopedSingletonManager.
     57    @param className The name of the singleton class
     58    @param scope The scope in which the singleton should exist
     59    @param allowedToFail If true, the singleton is allowed to fail and thus a try-catch block is used when creating the singleton.
     60
     61    If this macro is called for a singleton, it is registered with ScopedSingletonManager
     62    and will thus be created if its scope becomes active and destroyed if is deactivated.
     63*/
    4064#define ManageScopedSingleton(className, scope, allowedToFail) \
    4165    className* className::singletonPtr_s = NULL; \
     
    4670    class OrxonoxClass;
    4771
     72    /**
     73        @brief Base class of ClassScopedSingletonManager, implements some static functions
     74        used to dispatch calls to preUpdate and postUpdate to all instances of this class.
     75        It also keeps track of all existing ScopedSingletonManagers and stores them in a
     76        map, sorted by the scope they belong to.
     77    */
    4878    class _UtilExport ScopedSingletonManager
    4979    {
    5080        public:
     81            /// Constructor: Initializes all the values
    5182            ScopedSingletonManager(const std::string& className, ScopeID::Value scope)
    5283                : className_(className)
     
    5485            { }
    5586            virtual ~ScopedSingletonManager() { }
     87
     88            /// Adds a new instance of ScopedSingletonManager to the map.
    5689            static void addManager(ScopedSingletonManager* manager);
    5790
     91            /// Calls preUpdate in all instances of ScopedSingletonManager that are registered in the map.
    5892            template<ScopeID::Value scope>
    5993            static void preUpdate(const Clock& time)
     
    6498            }
    6599            virtual void preUpdate(const Clock& time) = 0;
     100
     101            /// Calls postUpdate in all instances of ScopedSingletonManager that are registered in the map.
    66102            template<ScopeID::Value scope>
    67103            static void postUpdate(const Clock& time)
     
    78114
    79115        protected:
    80             const std::string className_;
    81             const ScopeID::Value scope_;
     116            const std::string className_;   ///< The name of the scoped singleton class that is managed by this object
     117            const ScopeID::Value scope_;    ///< The scope of the singleton that is managed by this object
    82118    };
    83119
     120    /**
     121        @anchor ClassScopedSingletonManager
     122
     123        @brief Manages a scoped singleton for a given scope.
     124        @param T The managed singleton class
     125        @param scope The scope in which the singleton @a T should be active
     126        @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures.
     127
     128        This class inherits from ScopeListener for the given scope and thus its functions
     129        activated() and deactivated() are called whenever the Scope changes its state.
     130
     131        If the Scope is activated, a new instance of @a T (which must be a singleton) is created.
     132        If the Scope is deactivated, the singleton is destroyed.
     133
     134        @see Singleton
     135    */
    84136    template <class T, ScopeID::Value scope, bool allowedToFail>
    85137    class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener
    86138    {
    87139    public:
     140        //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener
    88141        ClassScopedSingletonManager(const std::string& className)
    89142            : ScopedSingletonManager(className, scope)
     
    113166        }
    114167
     168        //! Destroys the singleton instance - overloaded for OrxonoxClass, calls OrxonoxClass::destroy()
    115169        void destroy(OrxonoxClass*)
    116170        {
    117171            singletonPtr_->destroy();
    118172        }
     173        //! Destroys the singleton instance - overloaded for all other pointers, calls delete
    119174        void destroy(void*)
    120175        {
     
    139194
    140195    private:
    141         T* singletonPtr_;
     196        T* singletonPtr_;   ///< Unique instance of the singleton class @a T
    142197    };
    143198
     199    /**
     200        @brief This class partially spezializes ClassScopedSingletonManager for classes @a T that are allowed to fail.
     201        @param T The managed singleton class
     202        @param scope The scope in which the singleton @a T should be active
     203
     204        Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonManager
     205        uses a try-catch block to handle exceptions.
     206
     207        See @ref ClassScopedSingletonManager for a full documentation of the basis template.
     208    */
    144209    template <class T, ScopeID::Value scope>
    145210    class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener
    146211    {
    147212    public:
     213        //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener
    148214        ClassScopedSingletonManager(const std::string& className)
    149215            : ScopedSingletonManager(className, scope)
     
    180246        }
    181247
     248        //! Destroys the singleton instance - overloaded for OrxonoxClass, calls OrxonoxClass::destroy()
    182249        void destroy(OrxonoxClass* ptr)
    183250        {
    184251            singletonPtr_->destroy();
    185252        }
     253        //! Destroys the singleton instance - overloaded for void*, calls delete
    186254        void destroy(void* ptr)
    187255        {
     
    208276
    209277    private:
    210         T* singletonPtr_;
     278        T* singletonPtr_;   ///< Unique instance of the singleton class @a T
    211279    };
    212280}
Note: See TracChangeset for help on using the changeset viewer.