Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 29, 2009, 10:27:10 PM (15 years ago)
Author:
rgrieder
Message:

Derived all singletons implemented in a usual manner from orxonox::Singleton<T>.
This resolves inconsistencies with the singletonPtr_s variable in case of exceptions (asserts were being triggered then).
And while at it replaced singletonRef_s with singletonPtr_s for it to be less misleading (as fabian has already pointed out).

Location:
code/branches/resource/src/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource/src/util/SignalHandler.cc

    r3301 r3366  
    4141namespace orxonox
    4242{
    43     SignalHandler* SignalHandler::singletonRef_s = NULL;
     43    SignalHandler* SignalHandler::singletonPtr_s = NULL;
    4444}
    4545
     
    122122      }
    123123      // if the signalhandler has already been destroyed then don't do anything
    124       if( SignalHandler::singletonRef_s == 0 )
     124      if( SignalHandler::singletonPtr_s == 0 )
    125125      {
    126126        COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl;
  • code/branches/resource/src/util/SignalHandler.h

    r3068 r3366  
    4040#include <list>
    4141#include <string>
     42#include "Singleton.h"
    4243
    4344namespace orxonox
     
    6768    typedef std::list<SignalCallbackRec> SignalCallbackList;
    6869
    69     class SignalHandler
     70    class SignalHandler : public Singleton<SignalHandler>
    7071    {
     72        friend class Singleton<SignalHandler>;
    7173    public:
    72         SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
    73         ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; }
    74         inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
     74        SignalHandler()  { }
     75        ~SignalHandler() { }
    7576
    7677        void registerCallback( SignalCallback cb, void * someData );
     
    8788        SignalCallbackList callbackList;
    8889
    89         static SignalHandler* singletonRef_s;
     90        static SignalHandler* singletonPtr_s;
    9091
    9192        std::string appName;
     
    9899namespace orxonox
    99100{
    100     class _UtilExport SignalHandler
     101    class _UtilExport SignalHandler : public Singleton<SignalHandler>
    101102    {
     103        friend class Singleton<SignalHandler>;
    102104    public:
    103         SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
    104         ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; }
    105         inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
     105        SignalHandler()  { }
     106        ~SignalHandler() { }
    106107        void doCatch( const std::string & appName, const std::string & filename ) {}
    107108        void dontCatch() {}
     
    109110
    110111    private:
    111         static SignalHandler* singletonRef_s;
     112        static SignalHandler* singletonPtr_s;
    112113    };
    113114}
  • code/branches/resource/src/util/Singleton.h

    r3364 r3366  
    4040        Usage:
    4141        Inherit publicly from Singleton<MyClass> and provide access to
    42         MyClass::singletonRef_s.
    43         This can be done with a friend declaration.
     42        MyClass::singletonPtr_s.
     43        This can easily be done with a friend declaration.
    4444    */
    4545    template <class T>
     
    5050        static T& getInstance()
    5151        {
    52             assert(T::singletonRef_s != NULL);
    53             return *T::singletonRef_s;
     52            assert(T::singletonPtr_s != NULL);
     53            return *T::singletonPtr_s;
    5454        }
    5555
    5656    protected:
    57         // Constructor sets the singleton instance pointer
     57        //! Constructor sets the singleton instance pointer
    5858        Singleton()
    5959        {
    60             assert(T::singletonRef_s == NULL);
    61             T::singletonRef_s = static_cast<T*>(this);
     60            assert(T::singletonPtr_s == NULL);
     61            T::singletonPtr_s = static_cast<T*>(this);
    6262        }
    63         // Constructor resets the singleton instance pointer
     63
     64        //! Constructor resets the singleton instance pointer
    6465        ~Singleton()
    6566        {
    66             assert(T::singletonRef_s != NULL);
    67             T::singletonRef_s = NULL;
     67            assert(T::singletonPtr_s != NULL);
     68            T::singletonPtr_s = NULL;
    6869        }
    6970
Note: See TracChangeset for help on using the changeset viewer.