#include <senf/Utils/singleton.hh>
This mixin class will mark a class as singleton and provide an accessor function to access this singleton instance. The following preconditions must be met for this class to work as advertised:
Usage example:
class SomeClass : public senf::singleton<SomeClass> { // Must have default constructor SomeClass(); // Give singleton access to the constructor friend class senf::singleton<SomeClass>; public: // By default 'instance()' is protected. If you want, you may make it public: using senf::singleton<SomeClass>::instance; // ... }; int main(int argc, char ** argv) { // At this point, the instance has already been constructed SomeClass::instance().doSomething(); }
boost/pool/detail/singleton.hpp
. See that file for a description of the technique. The only difference is, that I prefer to advertise this class as a mixin (though it may be used the same way as the original too).Definition at line 87 of file singleton.hh.
Classes |
|
struct | force_creation |
Internal. |
|
Protected Member Functions |
|
singleton () | |
~singleton () | |
Static Protected Member Functions |
|
static Self & | instance () |
Return singleton instance. |
|
static bool | alive () |
Return true , if instance ok, false otherwise. |
senf::singleton< Self >:: | ||||
singleton | () | |||
Definition at line 34 of file singleton.cti.
senf::singleton< Self >::~ | ||||
~singleton | () | |||
Definition at line 40 of file singleton.cti.
bool senf::singleton< Self >:: | ||||
alive | () | |||
Return true
, if instance ok, false
otherwise.
Definition at line 58 of file singleton.cti.
Self & senf::singleton< Self >:: | ||||
instance | () | |||
Return singleton instance.
Definition at line 49 of file singleton.cti.