]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/OsgSingleton.hxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / util / OsgSingleton.hxx
1 #ifndef SIMGEAR_OSGSINGLETON_HXX
2 #define SIMGEAR_OSGSINGLETON_HXX 1
3
4 #include <simgear/structure/Singleton.hxx>
5
6 #include <osg/Referenced>
7 #include <osg/ref_ptr>
8
9 namespace simgear {
10
11 template <typename RefClass>
12 class SingletonRefPtr
13 {
14 public:
15     SingletonRefPtr()
16     {
17         ptr = new RefClass;
18     }
19     static RefClass* instance()
20     {
21         SingletonRefPtr& singleton
22             = boost::details::pool::singleton_default<SingletonRefPtr>::instance();
23         return singleton.ptr.get();
24     }
25 private:
26     osg::ref_ptr<RefClass> ptr;
27 };
28
29 template <typename RefClass>
30 class ReferencedSingleton : public virtual osg::Referenced
31 {
32 public:
33     static RefClass* instance()
34     {
35         return SingletonRefPtr<RefClass>::instance();
36     }
37 };
38
39 }
40
41 #endif