Field3D
Traits.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
43 //----------------------------------------------------------------------------//
44 
45 #ifndef _INCLUDED_Field3D_Traits_H_
46 #define _INCLUDED_Field3D_Traits_H_
47 
48 #include <assert.h>
49 #include <string>
50 
51 #include <hdf5.h>
52 
53 #include "Log.h"
54 #include "Types.h"
55 
56 //----------------------------------------------------------------------------//
57 
58 #include "ns.h"
59 
61 
62 //----------------------------------------------------------------------------//
63 // Enums
64 //----------------------------------------------------------------------------//
65 
76 };
77 
78 //----------------------------------------------------------------------------//
79 // FieldTraits
80 //----------------------------------------------------------------------------//
81 
87 template <class Data_T>
89 {
90 public:
92  static int dataDims();
93 };
94 
95 //----------------------------------------------------------------------------//
96 // DataTypeTraits
97 //----------------------------------------------------------------------------//
98 
99 template <typename T>
101  static std::string name()
102  {
103  return typeid(T).name();
104  }
105  static DataTypeEnum typeEnum();
106  static hid_t h5type();
107  static int h5bits();
108 };
109 
110 //----------------------------------------------------------------------------//
111 // TemplatedFieldType
112 //----------------------------------------------------------------------------//
113 
115 template <class Field_T>
117 {
118  const char *name()
119  {
120  return m_name.c_str();
121  }
123  {
124  m_name = Field_T::staticClassName();
125  m_name +=
126  "<" +
128  ">";
129  }
130 private:
131  std::string m_name;
132 };
133 
134 //----------------------------------------------------------------------------//
135 // NestedFieldType
136 //----------------------------------------------------------------------------//
137 
139 template <typename Field_T>
141 {
142  const char *name()
143  {
144  return m_name.c_str();
145  }
147  {
148  typedef typename Field_T::NestedType NestedType;
149  typedef typename NestedType::value_type value_type;
150 
151  m_name = Field_T::staticClassName();
152  m_name +=
153  std::string("<") + NestedType::staticClassName() + "<" +
155  }
156 private:
157  std::string m_name;
158 };
159 
160 //----------------------------------------------------------------------------//
161 // Template specializations
162 //----------------------------------------------------------------------------//
163 
164 #define FIELD3D_DECL_DATATYPENAME(typeName) \
165  template<> \
166  inline std::string DataTypeTraits<typeName>::name() \
167  { \
168  return std::string(#typeName); \
169  } \
170 
171 //----------------------------------------------------------------------------//
172 
173 FIELD3D_DECL_DATATYPENAME(unsigned char)
181 
182 //----------------------------------------------------------------------------//
183 
184 template<>
185 inline DataTypeEnum DataTypeTraits<half>::typeEnum()
186 {
187  return DataTypeHalf;
188 }
189 
190 //----------------------------------------------------------------------------//
191 
192 template<>
194 {
195  return DataTypeUnsignedChar;
196 }
197 
198 //----------------------------------------------------------------------------//
199 
200 template<>
202 {
203  return DataTypeInt;
204 }
205 
206 //----------------------------------------------------------------------------//
207 
208 template<>
210 {
211  return DataTypeFloat;
212 }
213 
214 //----------------------------------------------------------------------------//
215 
216 template<>
218 {
219  return DataTypeDouble;
220 }
221 
222 //----------------------------------------------------------------------------//
223 
224 template<>
226 {
227  return DataTypeVecHalf;
228 }
229 
230 //----------------------------------------------------------------------------//
231 
232 template<>
234 {
235  return DataTypeVecFloat;
236 }
237 
238 //----------------------------------------------------------------------------//
239 
240 template<>
242 {
243  return DataTypeVecDouble;
244 }
245 
246 template <>
248 {
249  return H5T_NATIVE_SHORT;
250 }
251 
252 //----------------------------------------------------------------------------//
253 
254 template <>
256 {
257  return H5T_NATIVE_FLOAT;
258 }
259 
260 //----------------------------------------------------------------------------//
261 
262 template <>
264 {
265  return H5T_NATIVE_DOUBLE;
266 }
267 
268 //----------------------------------------------------------------------------//
269 
270 template <>
272 {
273  return H5T_NATIVE_CHAR;
274 }
275 
276 //----------------------------------------------------------------------------//
277 
278 template <>
280 {
281  return H5T_NATIVE_UCHAR;
282 }
283 
284 //----------------------------------------------------------------------------//
285 
286 template <>
288 {
289  return H5T_NATIVE_INT;
290 }
291 
292 //----------------------------------------------------------------------------//
293 
294 template <>
296 {
297  return H5T_NATIVE_SHORT;
298 }
299 
300 //----------------------------------------------------------------------------//
301 
302 template <>
304 {
305  return H5T_NATIVE_FLOAT;
306 }
307 
308 //----------------------------------------------------------------------------//
309 
310 template <>
312 {
313  return H5T_NATIVE_DOUBLE;
314 }
315 
316 //----------------------------------------------------------------------------//
317 
318 template <>
320 {
321  return 16;
322 }
323 
324 //----------------------------------------------------------------------------//
325 
326 template <>
328 {
329  return 32;
330 }
331 
332 //----------------------------------------------------------------------------//
333 
334 template <>
336 {
337  return 64;
338 }
339 
340 //----------------------------------------------------------------------------//
341 
342 template <>
344 {
345  return 16;
346 }
347 
348 //----------------------------------------------------------------------------//
349 
350 template <>
352 {
353  return 32;
354 }
355 
356 //----------------------------------------------------------------------------//
357 
358 template <>
360 {
361  return 64;
362 }
363 
364 //----------------------------------------------------------------------------//
365 
367 
368 //----------------------------------------------------------------------------//
369 
370 #endif // Include guard
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
Contains typedefs for the commonly used types in Field3D.
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
std::string m_name
Definition: Traits.h:157
static std::string name()
Definition: Traits.h:101
static DataTypeEnum typeEnum()
std::string m_name
Definition: Traits.h:131
Contains the Log class which can be used to redirect output to an arbitrary destination.
Imath::Vec3< half > V3h
Definition: SpiMathLib.h:72
const char * name()
Definition: Traits.h:142
FIELD3D_NAMESPACE_OPEN typedef::half half
Definition: SpiMathLib.h:64
static hid_t h5type()
Imath::V3d V3d
Definition: SpiMathLib.h:74
#define FIELD3D_DECL_DATATYPENAME(typeName)
Definition: Traits.h:164
Imath::V3f V3f
Definition: SpiMathLib.h:73
static int h5bits()
Used to return a string for the name of a templated field.
Definition: Traits.h:116
const char * name()
Definition: Traits.h:118
DataTypeEnum
Definition: Traits.h:66
Used to return a string for the name of a nested templated field.
Definition: Traits.h:140