PixelLightAPI  .
Functions
Singleton.h File Reference
#include "PLCore/PLCore.h"
#include "PLCore/Core/Singleton.inl"

Go to the source code of this file.

Functions

PL_WARNING_PUSH PL_WARNING_DISABLE (4251) namespace PLCore

Function Documentation

PL_WARNING_PUSH PL_WARNING_DISABLE ( 4251  )

Singleton template

Remarks:
If you want to export a class based on this template by creating e.g. a dynamic library, you have to explicitly instantiate that template class, so that the compiler can import it instead of creating an own class base on the class template. If you don't do this, a call to ::GetInstance() will result in different objects being created for each module, e.g. the library will then get another Singleton-instance than an application using that library. This is of course not desired. To instantiate and export a class, use the export-macros which are defined in each PL-library. Because it seems that according to the ISO/IEC standard 14882 par. 17.4.3 (http://www.kuzbass.ru:8086/docs/isocpp/template.html) instantiation of a template (which is defined in an namespace) inside another namespace is forbidden, use the export macros like this: namespace PLCore { class System; } extern template class Singleton<System>;

Please note that the example above may not be compatible with each legacy compiler like GCC 4.2.1 used on Mac OS X 10.6. -> The C++11 feature "extern template" (C++11, see e.g. http://www2.research.att.com/~bs/C++0xFAQ.html#extern-templates) can only be used on modern compilers like GCC 4.6 -> In PixelLight itself, we can't break legacy compiler support, especially when only the singletons are responsible for the break -> As workaround, singleton implementations adding "GetInstance()" and "HasInstance()" within their interface

Note:
  • As the class same indicates, this is an implementation of the singleton design pattern
  • Do only use singletons, if they *really* make sense - not just because it's comfortable to have a global instance, this may lead to a shaky design...

Returns the class instance

Returns:
Pointer to the instance, assumed to be never a null pointer
Note:
  • Returns a pointer to the singleton instance. The instance will be created if it has not been created before.
  • The returned pointer can be a null pointer if the instance has already been destroyed, that is on deinitialization of the program. So be careful when using a singleton during deinitialization of the program, or better - don't do it :-)

Returns whether or not there's an instance

Returns:
'true' if there's an instance, else 'false'

Constructor

Destructor

Destruction guard, deletes a singleton on deinitialization

< Destroys the object on shutdown

< Pointer to the singleton instance, can be a null pointer

< Destruction flag - set only on shutdown



PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:03
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported