]> git.mxchange.org Git - simgear.git/blob - simgear/structure/Singleton.hxx
Remove stray ';'
[simgear.git] / simgear / structure / Singleton.hxx
1 #ifndef SIMGEAR_SINGLETON_HXX
2 #define SIMGEAR_SINGLETON_HXX 1
3
4 #include "singleton.hpp"
5
6 #ifndef NO_OPENSCENEGRAPH_INTERFACE
7 #include <osg/Referenced>
8 #include <osg/ref_ptr>
9 #endif
10
11 namespace simgear
12 {
13 /**
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.
17  */
18 template <typename Class>
19 class Singleton
20 {
21 protected:
22     Singleton() {}
23 public:
24     static Class* instance()
25     {
26         Class& singleton
27             = boost::details::pool::singleton_default<Class>::instance();
28         return &singleton;
29     }
30 };
31
32 #ifndef NO_OPENSCENEGRAPH_INTERFACE
33 template <typename RefClass>
34 class SingletonRefPtr
35 {
36 public:
37     SingletonRefPtr()
38     {
39         ptr = new RefClass;
40     }
41     static RefClass* instance()
42     {
43         SingletonRefPtr& singleton
44             = boost::details::pool::singleton_default<SingletonRefPtr>::instance();
45         return singleton.ptr.get();
46     }
47 private:
48     osg::ref_ptr<RefClass> ptr;
49 };
50
51 template <typename RefClass>
52 class ReferencedSingleton : public virtual osg::Referenced
53 {
54 public:
55     static RefClass* instance()
56     {
57         return SingletonRefPtr<RefClass>::instance();
58     }
59 };
60 #endif // of NO_OPENSCENEGRAPH_INTERFACE
61
62 }
63 #endif