Cortex  10.0.0-a4
TypeTraits.h
1 //
3 // Copyright (c) 2008-2013, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IE_CORE_TYPETRAITS_H
36 #define IE_CORE_TYPETRAITS_H
37 
38 #include "boost/static_assert.hpp"
39 
40 #include "boost/mpl/or.hpp"
41 #include "boost/mpl/and.hpp"
42 #include "boost/mpl/if.hpp"
43 #include "boost/mpl/not.hpp"
44 #include "boost/mpl/eval_if.hpp"
45 #include "boost/mpl/identity.hpp"
46 
47 #include "boost/type_traits.hpp"
48 
49 #include "IECore/HalfTypeTraits.h"
50 #include "IECore/SimpleTypedData.h"
51 #include "IECore/VectorTypedData.h"
52 #include "IECore/Spline.h"
53 #include "IECore/SplineData.h"
54 #include "IECore/DateTimeData.h"
55 #include "IECore/TransformationMatrixData.h"
56 
57 #include "OpenEXR/ImathVec.h"
58 #include "OpenEXR/ImathMatrix.h"
59 #include "OpenEXR/ImathQuat.h"
60 #include "OpenEXR/ImathBox.h"
61 
62 namespace IECore
63 {
64 
65 namespace TypeTraits
66 {
67 
69 template<typename T> struct HasValueType : public boost::false_type {};
70 template<typename T> struct HasValueType< TypedData<T> > : public boost::true_type {};
71 template<typename T> struct HasValueType< GeometricTypedData<T> > : public boost::true_type {};
72 template<typename T> struct HasValueType< const T > : public HasValueType< T > {};
73 
75 template<typename T> struct HasVectorValueType : public boost::false_type {};
76 template<typename T> struct HasVectorValueType< TypedData< std::vector< T > > > : public boost::true_type {};
77 template<typename T> struct HasVectorValueType< GeometricTypedData<std::vector<T> > > : public boost::true_type {};
78 template<typename T> struct HasVectorValueType< const T > : public HasVectorValueType<T> {};
79 
81 template<typename T> struct HasBaseType : public boost::mpl::not_< boost::is_void<typename T::BaseType> > {};
82 
83 namespace Detail
84 {
85 
86 template <class T>
87 struct GetValueType
88 {
89  typedef typename T::ValueType type;
90 };
91 
92 template <class T>
93 struct GetVectorValueType
94 {
95  typedef typename T::ValueType::value_type type;
96 };
97 
98 } // namespace Detail
99 
100 template <class T>
101 struct ValueType
102 {
103  typedef typename boost::mpl::eval_if< HasValueType<T>, Detail::GetValueType<T>, boost::mpl::identity<T> >::type type;
104 };
105 
106 template <class T>
107 struct VectorValueType
108 {
109  typedef typename boost::mpl::eval_if< HasVectorValueType<T>, Detail::GetVectorValueType<T>, boost::mpl::identity<T> >::type type;
110 };
111 
113 template<typename T> struct IsTypedData : public boost::false_type {};
114 template<typename T> struct IsTypedData< TypedData<T> > : public boost::true_type {};
115 template<typename T> struct IsTypedData< GeometricTypedData<T> > : public boost::true_type {};
116 template<typename T> struct IsTypedData< const T > : public IsTypedData<T> {};
117 
119 template<typename T> struct IsGeometricTypedData : public boost::false_type {};
120 template<typename T> struct IsGeometricTypedData< GeometricTypedData<T> > : public boost::true_type {};
121 template<typename T> struct IsGeometricTypedData< const T > : public IsGeometricTypedData<T> {};
122 
124 template<typename T> struct IsVectorTypedData : public boost::false_type {};
125 template<typename T> struct IsVectorTypedData< TypedData<std::vector<T> > > : public boost::true_type {};
126 template<typename T> struct IsVectorTypedData< GeometricTypedData<std::vector<T> > > : public boost::true_type {};
127 template<typename T> struct IsVectorTypedData< const T > : public IsVectorTypedData<T> {};
128 
130 template<typename T> struct IsSimpleTypedData : public boost::false_type {};
131 template<typename T> struct IsSimpleTypedData< TypedData<T > > : public boost::true_type {};
132 template<typename T> struct IsSimpleTypedData< GeometricTypedData<T > > : public boost::true_type {};
133 template<typename T> struct IsSimpleTypedData< TypedData<std::vector<T> > > : public boost::false_type {};
134 template<typename T> struct IsSimpleTypedData< GeometricTypedData<std::vector<T> > > : public boost::false_type {};
135 template<typename T> struct IsSimpleTypedData< const T > : public IsSimpleTypedData<T> {};
136 
138 template<typename T> struct IsMatrix33 : public boost::false_type {};
139 template<typename T> struct IsMatrix33< Imath::Matrix33<T> > : public boost::true_type {};
140 template<typename T> struct IsMatrix33< const T > : public IsMatrix33< T > {};
141 
143 template<typename T> struct IsMatrix44 : public boost::false_type {};
144 template<typename T> struct IsMatrix44< Imath::Matrix44<T> > : public boost::true_type {};
145 template<typename T> struct IsMatrix44< const T > : public IsMatrix44< T > {};
146 
148 template<typename T> struct IsMatrix : boost::mpl::or_< IsMatrix33<T>, IsMatrix44<T> > {};
149 
151 template<typename T> struct IsVec3 : public boost::false_type {};
152 template<typename T> struct IsVec3< Imath::Vec3<T> > : public boost::true_type {};
153 template<typename T> struct IsVec3< const T > : public IsVec3< T > {};
154 
156 template<typename T> struct IsFloatVec3 : public boost::false_type {};
157 template<> struct IsFloatVec3< Imath::Vec3<float> > : public boost::true_type {};
158 template<> struct IsFloatVec3< Imath::Vec3<double> > : public boost::true_type {};
159 template<typename T> struct IsFloatVec3< const T > : public IsFloatVec3< T > {};
160 
162 template<typename T> struct IsVec2 : public boost::false_type {};
163 template<typename T> struct IsVec2< Imath::Vec2<T> > : public boost::true_type {};
164 template<typename T> struct IsVec2< const T > : public IsVec2< T > {};
165 
167 template<typename T> struct IsFloatVec2 : public boost::false_type {};
168 template<> struct IsFloatVec2< Imath::Vec2<float> > : public boost::true_type {};
169 template<> struct IsFloatVec2< Imath::Vec2<double> > : public boost::true_type {};
170 template<typename T> struct IsFloatVec2< const T > : public IsFloatVec2< T > {};
171 
173 template<typename T> struct IsVec : boost::mpl::or_< IsVec3<T>, IsVec2<T> > {};
174 
176 template<typename T> struct IsColor3 : public boost::false_type {};
177 template<typename T> struct IsColor3< Imath::Color3<T> > : public boost::true_type {};
178 template<typename T> struct IsColor3< const T > : public IsColor3< T > {};
179 
181 template<typename T> struct IsColor4 : public boost::false_type {};
182 template<typename T> struct IsColor4< Imath::Color4<T> > : public boost::true_type {};
183 template<typename T> struct IsColor4< const T > : public IsColor4< T > {};
184 
186 template<typename T> struct IsColor : boost::mpl::or_< IsColor3<T>, IsColor4<T> > {};
187 
189 template<typename T> struct IsQuat : public boost::false_type {};
190 template<typename T> struct IsQuat< Imath::Quat<T> > : public boost::true_type {};
191 template<typename T> struct IsQuat< const T > : public IsQuat< T > {};
192 
194 template<typename T> struct IsBox : public boost::false_type {};
195 template<typename T> struct IsBox< Imath::Box<T> > : public boost::true_type {};
196 template<typename T> struct IsBox< const T> : public IsBox< T > {};
197 
199 template<typename T> struct IsTransformationMatrix : public boost::false_type {};
200 template<typename T> struct IsTransformationMatrix< TransformationMatrix<T> > : public boost::true_type {};
201 template<typename T> struct IsTransformationMatrix< const T > : public IsTransformationMatrix< T > {};
202 
204 template< typename T > struct IsMatrixTypedData : boost::mpl::and_< IsTypedData<T>, IsMatrix< typename ValueType<T>::type > > {};
205 
207 template< typename T > struct IsVec2TypedData : boost::mpl::and_< IsTypedData<T>, IsVec2< typename ValueType<T>::type > > {};
208 
210 template< typename T > struct IsVec2VectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, IsVec2< typename VectorValueType<T>::type > > {};
211 
213 template< typename T > struct IsFloatVec2VectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, IsFloatVec2< typename VectorValueType<T>::type > > {};
214 
216 template< typename T > struct IsVec3TypedData : boost::mpl::and_< IsTypedData<T>, IsVec3< typename ValueType<T>::type > > {};
217 
219 template< typename T > struct IsVec3VectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, IsVec3< typename VectorValueType<T>::type > > {};
220 
222 template< typename T > struct IsFloatVec3VectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, IsFloatVec3< typename VectorValueType<T>::type > > {};
223 
225 template< typename T > struct IsVecTypedData : boost::mpl::or_< IsVec2TypedData<T>, IsVec3TypedData<T> > {};
226 
228 template< typename T > struct IsVecVectorTypedData : boost::mpl::or_< IsVec2VectorTypedData<T>, IsVec3VectorTypedData<T> > {};
229 
231 template< typename T > struct IsNumericVectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, boost::is_arithmetic< typename VectorValueType<T>::type >, boost::mpl::not_< boost::is_same< typename VectorValueType<T>::type, bool > > > {};
232 
234 template< typename T > struct IsNumericBasedVectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, boost::is_arithmetic< typename T::BaseType >, boost::mpl::not_< boost::is_same< typename T::BaseType, bool > > > {};
235 
237 template< typename T > struct IsFloatVectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, boost::is_floating_point< typename VectorValueType<T>::type > > {};
238 
240 template< typename T > struct IsNumericSimpleTypedData : boost::mpl::and_< IsSimpleTypedData<T>, boost::is_arithmetic< typename ValueType<T>::type >, boost::mpl::not_< boost::is_same< typename ValueType<T>::type, bool > > > {};
241 
243 template< typename T > struct IsNumericBasedSimpleTypedData : boost::mpl::and_< IsSimpleTypedData<T>, boost::is_arithmetic< typename T::BaseType >, boost::mpl::not_< boost::is_same< typename T::BaseType, bool > > > {};
244 
246 template< typename T > struct IsNumericTypedData : boost::mpl::or_< IsNumericSimpleTypedData<T>, IsNumericVectorTypedData<T> > {};
247 
249 template< typename T > struct IsNumericBasedTypedData : boost::mpl::or_< IsNumericBasedSimpleTypedData<T>, IsNumericBasedVectorTypedData<T> > {};
250 
251 namespace Detail
252 {
253 template< typename T, template<typename> class Pred > struct IsInterpolableHelper : Pred<T> {};
254 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< TransformationMatrix< T >, Pred > : IsInterpolableHelper<T, Pred> {};
255 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Quat< T >, Pred > : IsInterpolableHelper<T, Pred> {};
256 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Vec2< T >, Pred > : IsInterpolableHelper<T, Pred> {};
257 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Vec3< T >, Pred > : IsInterpolableHelper<T, Pred> {};
258 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Color3< T >, Pred > : IsInterpolableHelper<T, Pred> {};
259 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Color4< T >, Pred > : IsInterpolableHelper<T, Pred> {};
260 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Box< T >, Pred > : IsInterpolableHelper<T, Pred> {};
261 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< Imath::Matrix44< T >, Pred > : IsInterpolableHelper<T, Pred> {};
262 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< std::vector< T >, Pred > : IsInterpolableHelper<T, Pred> {};
263 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< TypedData< T >, Pred > : IsInterpolableHelper<T, Pred> {};
264 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< GeometricTypedData< T >, Pred > : IsInterpolableHelper<T, Pred> {};
265 template< typename T, template<typename> class Pred > struct IsInterpolableHelper< const T, Pred > : IsInterpolableHelper<T, Pred> {};
266 }
267 
271 template< typename T > struct IsInterpolable : Detail::IsInterpolableHelper<T, boost::is_arithmetic > {};
272 
275 template< typename T > struct IsStrictlyInterpolable : Detail::IsInterpolableHelper<T, boost::is_floating_point > {};
276 
278 template< typename T > struct IsInterpolableTypedData : boost::mpl::and_< IsTypedData<T>, IsInterpolable< typename ValueType<T>::type > > {};
279 
281 template< typename T > struct IsStrictlyInterpolableTypedData : boost::mpl::and_< IsTypedData<T>, IsStrictlyInterpolable< typename ValueType<T>::type > > {};
282 
284 template< typename T > struct IsInterpolableVectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, IsInterpolable< typename VectorValueType<T>::type > > {};
285 
287 template< typename T > struct IsStrictlyInterpolableVectorTypedData : boost::mpl::and_< IsVectorTypedData<T>, IsStrictlyInterpolable< typename VectorValueType<T>::type > > {};
288 
290 template< typename T > struct IsInterpolableSimpleTypedData : boost::mpl::and_< IsSimpleTypedData<T>, IsInterpolable< typename ValueType<T>::type > > {};
291 
293 template< typename T > struct IsStrictlyInterpolableSimpleTypedData : boost::mpl::and_< IsSimpleTypedData<T>, IsStrictlyInterpolable< typename ValueType<T>::type > > {};
294 
296 template<typename T, typename U = void > struct IsSpline : public boost::false_type {};
297 template<typename T, typename U> struct IsSpline< Spline<T, U> > : public boost::true_type {};
298 template<typename T, typename U> struct IsSpline< const Spline<T, U> > : public boost::true_type {};
299 
301 template< typename T > struct IsSplineTypedData : boost::mpl::and_< IsTypedData<T>, IsSpline< typename ValueType<T>::type > > {};
302 
303 
304 } // namespace TypeTraits
305 
306 } // namespace IECore
307 
308 #endif // IE_CORE_TYPETRAITS_H
Definition: GeometricTypedData.h:76
Definition: TypeTraits.h:271
IsTransformationMatrix.
Definition: TypeTraits.h:199
IsColor.
Definition: TypeTraits.h:186
IsVec2TypedData.
Definition: TypeTraits.h:207
IsBox.
Definition: TypeTraits.h:194
IsFloatVec3.
Definition: TypeTraits.h:156
IsMatrixTypedData.
Definition: TypeTraits.h:204
IsVecVectorTypedData.
Definition: TypeTraits.h:228
Definition: MStringLess.h:40
IsVec2.
Definition: TypeTraits.h:162
IsMatrix.
Definition: TypeTraits.h:148
IsVec3TypedData.
Definition: TypeTraits.h:216
IsVec3.
Definition: TypeTraits.h:151
IsStrictlyInterpolableSimpleTypedData.
Definition: TypeTraits.h:293
Definition: TypedData.h:64
IsFloatVec2.
Definition: TypeTraits.h:167
IsTypedData.
Definition: TypeTraits.h:113
Definition: Spline.h:53
IsInterpolableSimpleTypedData.
Definition: TypeTraits.h:290
IsNumericBasedVectorTypedData - true if the data holds a vector of types where BaseType is numeric...
Definition: TypeTraits.h:234
IsNumericTypedData.
Definition: TypeTraits.h:246
IsVecTypedData.
Definition: TypeTraits.h:225
IsInterpolableTypedData.
Definition: TypeTraits.h:278
IsInterpolableVectorTypedData.
Definition: TypeTraits.h:284
HasValueType.
Definition: TypeTraits.h:69
IsColor3.
Definition: TypeTraits.h:176
IsNumericBasedTypedData.
Definition: TypeTraits.h:249
HasVectorValueType.
Definition: TypeTraits.h:75
IsGeometricTypedData.
Definition: TypeTraits.h:119
IsSplineTypedData.
Definition: TypeTraits.h:301
IsQuat.
Definition: TypeTraits.h:189
Definition: TypeTraits.h:275
IsVec2VectorTypedData.
Definition: TypeTraits.h:210
IsMatrix33.
Definition: TypeTraits.h:138
IsVec.
Definition: TypeTraits.h:173
IsVectorTypedData.
Definition: TypeTraits.h:124
IsFloatVec3VectorTypedData.
Definition: TypeTraits.h:222
IsSimpleTypedData.
Definition: TypeTraits.h:130
HasBaseType.
Definition: TypeTraits.h:81
IsStrictlyInterpolableTypedData.
Definition: TypeTraits.h:281
IsColor4.
Definition: TypeTraits.h:181
IsFloatVectorTypedData.
Definition: TypeTraits.h:237
IsSpline.
Definition: TypeTraits.h:296
IsFloatVec2VectorTypedData.
Definition: TypeTraits.h:213
IsNumericVectorTypedData.
Definition: TypeTraits.h:231
IsVec3VectorTypedData.
Definition: TypeTraits.h:219
IsNumericBasedSimpleTypedData - true if the data is simple and BaseType is numeric.
Definition: TypeTraits.h:243
Definition: TransformationMatrix.h:53
IsStrictlyInterpolableVectorTypedData.
Definition: TypeTraits.h:287
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43
IsMatrix44.
Definition: TypeTraits.h:143
IsNumericSimpleTypedData.
Definition: TypeTraits.h:240
Definition: VecAlgo.h:49