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 // Template specializations
136 //----------------------------------------------------------------------------//
137 
138 #define FIELD3D_DECL_DATATYPENAME(typeName) \
139  template<> \
140  inline std::string DataTypeTraits<typeName>::name() \
141  { \
142  return std::string(#typeName); \
143  } \
144 
145 //----------------------------------------------------------------------------//
146 
147 FIELD3D_DECL_DATATYPENAME(unsigned char)
155 
156 //----------------------------------------------------------------------------//
157 
158 template<>
159 inline DataTypeEnum DataTypeTraits<half>::typeEnum()
160 {
161  return DataTypeHalf;
162 }
163 
164 //----------------------------------------------------------------------------//
165 
166 template<>
168 {
169  return DataTypeUnsignedChar;
170 }
171 
172 //----------------------------------------------------------------------------//
173 
174 template<>
176 {
177  return DataTypeInt;
178 }
179 
180 //----------------------------------------------------------------------------//
181 
182 template<>
184 {
185  return DataTypeFloat;
186 }
187 
188 //----------------------------------------------------------------------------//
189 
190 template<>
192 {
193  return DataTypeDouble;
194 }
195 
196 //----------------------------------------------------------------------------//
197 
198 template<>
200 {
201  return DataTypeVecHalf;
202 }
203 
204 //----------------------------------------------------------------------------//
205 
206 template<>
208 {
209  return DataTypeVecFloat;
210 }
211 
212 //----------------------------------------------------------------------------//
213 
214 template<>
216 {
217  return DataTypeVecDouble;
218 }
219 
220 template <>
222 {
223  return H5T_NATIVE_SHORT;
224 }
225 
226 //----------------------------------------------------------------------------//
227 
228 template <>
230 {
231  return H5T_NATIVE_FLOAT;
232 }
233 
234 //----------------------------------------------------------------------------//
235 
236 template <>
238 {
239  return H5T_NATIVE_DOUBLE;
240 }
241 
242 //----------------------------------------------------------------------------//
243 
244 template <>
246 {
247  return H5T_NATIVE_CHAR;
248 }
249 
250 //----------------------------------------------------------------------------//
251 
252 template <>
254 {
255  return H5T_NATIVE_UCHAR;
256 }
257 
258 //----------------------------------------------------------------------------//
259 
260 template <>
262 {
263  return H5T_NATIVE_INT;
264 }
265 
266 //----------------------------------------------------------------------------//
267 
268 template <>
270 {
271  return H5T_NATIVE_SHORT;
272 }
273 
274 //----------------------------------------------------------------------------//
275 
276 template <>
278 {
279  return H5T_NATIVE_FLOAT;
280 }
281 
282 //----------------------------------------------------------------------------//
283 
284 template <>
286 {
287  return H5T_NATIVE_DOUBLE;
288 }
289 
290 //----------------------------------------------------------------------------//
291 
292 template <>
294 {
295  return 16;
296 }
297 
298 //----------------------------------------------------------------------------//
299 
300 template <>
302 {
303  return 32;
304 }
305 
306 //----------------------------------------------------------------------------//
307 
308 template <>
310 {
311  return 64;
312 }
313 
314 //----------------------------------------------------------------------------//
315 
316 template <>
318 {
319  return 16;
320 }
321 
322 //----------------------------------------------------------------------------//
323 
324 template <>
326 {
327  return 32;
328 }
329 
330 //----------------------------------------------------------------------------//
331 
332 template <>
334 {
335  return 64;
336 }
337 
338 //----------------------------------------------------------------------------//
339 
341 
342 //----------------------------------------------------------------------------//
343 
344 #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.
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
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:138
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