- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/include/frost_utils_manager.h

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*             Manager header             */
    00005 /*                                        */
    00006 /*                                        */
    00007
    00008 /* Warning : This is a precompiled header.
    00009 *            Modifying it will trigger a
    00010 *            full rebuild !
    00011 */
    00012
    00013 #ifndef FROST_MANAGER_H
    00014 #define FROST_MANAGER_H
    00015
    00016 #include "frost_utils_types.h"
    00017
    00018 namespace Frost
    00019 {
    00020     /// Abstract singleton pattern
    00021     template<class T>
    00022     class Manager
    00023     {
    00024     friend class s_ptr< Manager<T> >;
    00025     public :
    00026
    00027         /// Returns a pointer to the singleton
    00028         /** \note The singleton will be created on the very first call.
    00029         */
    00030         static s_ptr<T> GetSingleton()
    00031         {
    00032             if (!pMgr_)
    00033                 pMgr_ = new T();
    00034
    00035             return pMgr_;
    00036         }
    00037
    00038         /// Deletes the singleton
    00039         /** \note You should call that method when you're not using the
    00040         *         singleton anymore, or if you want to reset it.<br>
    00041         *         Use only if you've called GetSingleton at least once.
    00042         */
    00043         static void Delete()
    00044         {
    00045             delete pMgr_.Get(); pMgr_.SetNull();
    00046         }
    00047
    00048     protected :
    00049
    00050         /// Default constructor
    00051         /** \note This is a singleton class. That means that there can
    00052         *         only be a single instance at the same time. That's why
    00053         *         the constructor is not in public scope.<br>
    00054         *         If you need to get a pointer to that unique instance,
    00055         *         call Manager::GetSingleton().<br>
    00056         *         Note that, if GetSingleton() has been called at least once,
    00057         *         you'll have to delete the returned pointer when you close
    00058         *         your program by calling Manager::Delete().
    00059         */
    00060         Manager() {}
    00061
    00062         /// Destructor
    00063         /** \note If GetSingleton() has been called at least once,
    00064         *         you'll have to delete the returned pointer when you close your
    00065         *         program by calling Manager::Delete() (this is automatically done
    00066         *         by Engine).
    00067         */
    00068         ~Manager() {}
    00069
    00070         /// Copy constructor
    00071         Manager(const Manager& mMgr);
    00072
    00073         /// Assignment operator
    00074         Manager& operator = (const Manager& mMgr);
    00075
    00076     private :
    00077
    00078         static s_ptr<T> pMgr_;
    00079
    00080     };
    00081
    00082     template<class T>
    00083     s_ptr<T> Manager<T>::pMgr_ = nullptr;
    00084 }
    00085
    00086 #endif