]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/detail/nasal_traits.hxx
Fix headless build and reduce include dependencies.
[simgear.git] / simgear / nasal / cppbind / detail / nasal_traits.hxx
1 ///@file
2 /// Type traits used for converting from and to Nasal types
3 ///
4 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
19
20 #ifndef SG_NASAL_TRAITS_HXX_
21 #define SG_NASAL_TRAITS_HXX_
22
23 #include <boost/type_traits/integral_constant.hpp>
24 #include <boost/type_traits/is_base_of.hpp>
25
26 // Forward declarations
27 class SGWeakReferenced;
28 template<class T> class SGSharedPtr;
29 template<class T> class SGWeakPtr;
30 template<class T> class SGVec2;
31
32 namespace boost
33 {
34   template<class T> class shared_ptr;
35   template<class T> class weak_ptr;
36 }
37 namespace osg
38 {
39   template<class T> class ref_ptr;
40   template<class T> class observer_ptr;
41
42   class Vec2b;
43   class Vec2d;
44   class Vec2f;
45   class Vec2s;
46 }
47
48 // The actual traits...
49 namespace nasal
50 {
51   template<class T>
52   struct is_vec2: public boost::integral_constant<bool, false> {};
53
54 #define SG_MAKE_TRAIT(templ,type,attr)\
55   template templ\
56   struct attr< type >:\
57     public boost::integral_constant<bool, true> {};
58
59 SG_MAKE_TRAIT(<class T>, SGVec2<T>, is_vec2)
60 SG_MAKE_TRAIT(<>, osg::Vec2b, is_vec2)
61 SG_MAKE_TRAIT(<>, osg::Vec2d, is_vec2)
62 SG_MAKE_TRAIT(<>, osg::Vec2f, is_vec2)
63 SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2)
64
65 #undef SG_MAKE_TRAIT
66
67   template<class T>
68   struct shared_ptr_traits;
69
70   template<class T>
71   struct is_strong_ref:
72     public boost::integral_constant<bool, false>
73   {};
74
75   template<class T>
76   struct is_weak_ref:
77     public boost::integral_constant<bool, false>
78   {};
79
80 #define SG_MAKE_SHARED_PTR_TRAIT(ref, weak)\
81   template<class T>\
82   struct shared_ptr_traits<ref<T> >\
83   {\
84     typedef ref<T>  strong_ref;\
85     typedef weak<T> weak_ref;\
86     typedef T       element_type;\
87     typedef boost::integral_constant<bool, true> is_strong;\
88   };\
89   template<class T>\
90   struct shared_ptr_traits<weak<T> >\
91   {\
92     typedef ref<T>  strong_ref;\
93     typedef weak<T> weak_ref;\
94     typedef T       element_type;\
95     typedef boost::integral_constant<bool, false> is_strong;\
96   };\
97   template<class T>\
98   struct is_strong_ref<ref<T> >:\
99     public boost::integral_constant<bool, true>\
100   {};\
101   template<class T>\
102   struct is_weak_ref<weak<T> >:\
103     public boost::integral_constant<bool, true>\
104   {};
105
106   SG_MAKE_SHARED_PTR_TRAIT(SGSharedPtr, SGWeakPtr)
107   SG_MAKE_SHARED_PTR_TRAIT(osg::ref_ptr, osg::observer_ptr)
108   SG_MAKE_SHARED_PTR_TRAIT(boost::shared_ptr, boost::weak_ptr)
109
110 #undef SG_MAKE_SHARED_PTR_TRAIT
111
112   template<class T>
113   struct supports_weak_ref:
114     public boost::integral_constant<bool, true>
115   {};
116
117   template<class T>
118   struct supports_weak_ref<SGSharedPtr<T> >:
119     public boost::integral_constant<
120       bool,
121       boost::is_base_of<SGWeakReferenced, T>::value
122     >
123   {};
124
125 } // namespace nasal
126 #endif /* SG_NASAL_TRAITS_HXX_ */