Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/util/Singleton.h

    r8858 r10624  
    5252        public:
    5353            TestSingleton();                                // public constructor because we may want to manage this singleton
    54                                                             //     with an orxonox::ScopedSingletonManager (see below)
     54                                                            //     with an orxonox::ScopedSingletonWrapper
    5555            virtual ~TestSingleton();                       // public destructor
    5656
     
    6868    TestSingleton* TestSingleton::singletonPtr_s = NULL;
    6969    @endcode
    70 
    71     Usually a singleton gets created automatically when it is first used, but it will never
    72     be destroyed (unless the singleton explicitly deletes itself). To allow controlled
    73     construction and destruction, the singleton can be put within a virtual scope. This is
    74     done by registering the singleton class with orxonox::ScopedSingletonManager. To
    75     do so, the ManageScopedSingleton() macro has to be called:
    76 
    77     @code
    78     ManageScopedSingleton(TestSingleton, ScopeID::Graphics, false); // muste be called in a source (*.cc) file
    79     @endcode
    80 
    81     @b Important: If you call ManageScopedSingleton(), you don't have to initialize singletonPtr_s anymore,
    82     because that's already done by the macro.
    83 
    84     Now the singleton TestSingleton gets automatically created if the scope Graphics becomes
    85     active and also gets destroyed if the scope is deactivated.
    86 
    87     Note that not all singletons must register with a scope, but it's recommended.
    8870
    8971    If a class inherits from orxonox::Singleton, it also inherits its functions. The most important
     
    11294#include "UtilPrereqs.h"
    11395
    114 #include <cassert>
    11596#include <cstring>
     97#include <typeinfo>
     98
     99#include "OrxAssert.h"
    116100
    117101namespace orxonox
     
    134118        static T& getInstance()
    135119        {
    136             assert(T::singletonPtr_s != NULL);
     120            OrxVerify(T::singletonPtr_s != NULL, "T=" << typeid(T).name());
    137121            return *T::singletonPtr_s;
    138122        }
     
    144128        }
    145129
    146         //! Update method called by ClassSingletonManager (if used)
    147         void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }
    148         //! Empty update method for the static polymorphism
    149         void preUpdate(const Clock& time) { }
    150         //! Update method called by ClassSingletonManager (if used)
    151         void postUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->postUpdate(time); }
    152         //! Empty update method for the static polymorphism
    153         void postUpdate(const Clock& time) { }
    154 
    155130    protected:
    156131        //! Constructor sets the singleton instance pointer
    157132        Singleton()
    158133        {
    159             assert(T::singletonPtr_s == NULL);
     134            OrxVerify(T::singletonPtr_s == NULL, "T=" << typeid(T).name());
    160135            T::singletonPtr_s = static_cast<T*>(this);
    161136        }
     
    164139        virtual ~Singleton()
    165140        {
    166             assert(T::singletonPtr_s != NULL);
     141            OrxVerify(T::singletonPtr_s != NULL, "T=" << typeid(T).name());
    167142            T::singletonPtr_s = NULL;
    168143        }
Note: See TracChangeset for help on using the changeset viewer.