2 /// Type traits used for converting from and to Nasal types
4 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
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.
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.
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
20 #ifndef SG_NASAL_TRAITS_HXX_
21 #define SG_NASAL_TRAITS_HXX_
23 #include <boost/type_traits/integral_constant.hpp>
24 #include <boost/type_traits/is_base_of.hpp>
26 // Forward declarations
27 class SGWeakReferenced;
28 template<class T> class SGSharedPtr;
29 template<class T> class SGWeakPtr;
30 template<class T> class SGVec2;
34 template<class T> class shared_ptr;
35 template<class T> class weak_ptr;
39 template<class T> class ref_ptr;
40 template<class T> class observer_ptr;
48 // The actual traits...
52 struct is_vec2: public boost::integral_constant<bool, false> {};
54 #define SG_MAKE_TRAIT(templ,type,attr)\
57 public boost::integral_constant<bool, true> {};
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)
68 struct shared_ptr_traits;
72 public boost::integral_constant<bool, false>
77 public boost::integral_constant<bool, false>
80 #define SG_MAKE_SHARED_PTR_TRAIT(ref, weak)\
82 struct shared_ptr_traits<ref<T> >\
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;\
90 struct shared_ptr_traits<weak<T> >\
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;\
98 struct is_strong_ref<ref<T> >:\
99 public boost::integral_constant<bool, true>\
102 struct is_weak_ref<weak<T> >:\
103 public boost::integral_constant<bool, true>\
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)
110 #undef SG_MAKE_SHARED_PTR_TRAIT
113 struct supports_weak_ref:
114 public boost::integral_constant<bool, true>
118 struct supports_weak_ref<SGSharedPtr<T> >:
119 public boost::integral_constant<
121 boost::is_base_of<SGWeakReferenced, T>::value
126 #endif /* SG_NASAL_TRAITS_HXX_ */