1 #ifndef SIMGEAR_SINGLETON_HXX
2 #define SIMGEAR_SINGLETON_HXX 1
4 #include <boost/pool/detail/singleton.hpp>
6 #ifndef NO_OPENSCENEGRAPH_INTERFACE
7 #include <osg/Referenced>
14 * Class that supplies the address of a singleton instance. This class
15 * can be inherited by its Class argument in order to support the
16 * instance() method in that class.
18 template <typename Class>
24 static Class* instance()
27 = boost::details::pool::singleton_default<Class>::instance();
32 #ifndef NO_OPENSCENEGRAPH_INTERFACE
33 template <typename RefClass>
41 static RefClass* instance()
43 SingletonRefPtr& singleton
44 = boost::details::pool::singleton_default<SingletonRefPtr>::instance();
45 return singleton.ptr.get();
48 osg::ref_ptr<RefClass> ptr;
51 template <typename RefClass>
52 class ReferencedSingleton : public virtual osg::Referenced
55 static RefClass* instance()
57 return SingletonRefPtr<RefClass>::instance();
60 #endif // of NO_OPENSCENEGRAPH_INTERFACE