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// Types
64//----------------------------------------------------------------------------//
65
66#if !defined(_MSC_VER)
67using ::uint8_t;
68using ::int8_t;
69using ::uint16_t;
70using ::int16_t;
71using ::uint32_t;
72using ::int32_t;
73using ::uint64_t;
74using ::int64_t;
75#else
76typedef unsigned char uint8_t;
77typedef signed char int8_t;
78typedef unsigned short uint16_t;
79typedef signed short int16_t;
80typedef unsigned int uint32_t;
81typedef int int32_t;
82typedef unsigned long long uint64_t;
83typedef long long int64_t;
84#endif
85
87typedef float float32_t;
88typedef double float64_t;
89
90#ifdef FIELD3D_VERSION_NS
91typedef Field3D::V3h vec16_t;
92typedef Field3D::V3f vec32_t;
93typedef Field3D::V3d vec64_t;
94typedef Field3D::V3i veci32_t;
95typedef Field3D::M44d mtx64_t;
96#else
97typedef Imath::Vec3<float16_t> vec16_t;
98typedef Imath::Vec3<float32_t> vec32_t;
99typedef Imath::Vec3<float64_t> vec64_t;
100typedef Imath::Vec3<int32_t> veci32_t;
101typedef Imath::M44d mtx64_t;
102#endif
103
104//----------------------------------------------------------------------------//
105// Enums
106//----------------------------------------------------------------------------//
107
119
120//----------------------------------------------------------------------------//
121
126
127 // Signed and unsigned integers from char to long
130
133
136
139
140 // Floats
144
145 // Vec3
150
151 // Matrix
153
154 // String
156
158
159 // Invalid type enum
162
163//----------------------------------------------------------------------------//
164// FieldTraits
165//----------------------------------------------------------------------------//
166
172template <class Data_T>
174{
175public:
177 static const int k_dataDims = 3;
178 static int dataDims() { return k_dataDims; }
179};
180
181template <>
183{
184public:
185 static const int k_dataDims = 1;
186 static int dataDims() { return k_dataDims; }
187};
188
189template <>
191{
192public:
193 static const int k_dataDims = 1;
194 static int dataDims() { return k_dataDims; }
195};
196
197template <>
199{
200public:
201 static const int k_dataDims = 1;
202 static int dataDims() { return k_dataDims; }
203};
204
205template <>
207{
208public:
209 static const int k_dataDims = 1;
210 static int dataDims() { return k_dataDims; }
211};
212
213template <>
215{
216public:
217 static const int k_dataDims = 1;
218 static int dataDims() { return k_dataDims; }
219};
220
221template <>
223{
224public:
225 static const int k_dataDims = 1;
226 static int dataDims() { return k_dataDims; }
227};
228
229template <>
231{
232public:
233 static const int k_dataDims = 3;
234 static int dataDims() { return k_dataDims; }
235};
236
237template <>
239{
240public:
241 static const int k_dataDims = 3;
242 static int dataDims() { return k_dataDims; }
243};
244
245template <>
247{
248public:
249 static const int k_dataDims = 3;
250 static int dataDims() { return k_dataDims; }
251};
252
253template <>
255{
256public:
257 static const int k_dataDims = 3;
258 static int dataDims() { return k_dataDims; }
259};
260
261//----------------------------------------------------------------------------//
262// DataTypeTraits
263//----------------------------------------------------------------------------//
264
265template <typename T>
267 static std::string name()
268 {
269 return typeid(T).name();
270 }
272 static hid_t h5type();
273 static int h5bits();
274};
275
276//----------------------------------------------------------------------------//
277// TemplatedFieldType
278//----------------------------------------------------------------------------//
279
281template <class Field_T>
283{
284 const char *name()
285 {
286 return m_name.c_str();
287 }
289 {
290 m_name = Field_T::staticClassName();
291 m_name +=
292 "<" +
294 ">";
295 }
296private:
297 std::string m_name;
298};
299
300//----------------------------------------------------------------------------//
301// NestedFieldType
302//----------------------------------------------------------------------------//
303
305template <typename Field_T>
307{
308 const char *name()
309 {
310 return m_name.c_str();
311 }
313 {
314 typedef typename Field_T::NestedType NestedType;
315 typedef typename NestedType::value_type value_type;
316
317 m_name = Field_T::staticClassName();
318 m_name +=
319 std::string("<") + NestedType::staticClassName() + "<" +
321 }
322private:
323 std::string m_name;
324};
325
326//----------------------------------------------------------------------------//
327// Template specializations
328//----------------------------------------------------------------------------//
329
330#define FIELD3D_DECL_DATATYPENAME(typeName) \
331 template<> \
332 inline std::string DataTypeTraits<typeName>::name() \
333 { \
334 return std::string(#typeName); \
335 } \
336
337//----------------------------------------------------------------------------//
338
339FIELD3D_DECL_DATATYPENAME(unsigned char)
347
348//----------------------------------------------------------------------------//
349
350template<>
355
356//----------------------------------------------------------------------------//
357
358template<>
363
364//----------------------------------------------------------------------------//
365
366template<>
371
372//----------------------------------------------------------------------------//
373
374template<>
379
380//----------------------------------------------------------------------------//
381
382template<>
387
388//----------------------------------------------------------------------------//
389
390template<>
395
396//----------------------------------------------------------------------------//
397
398template<>
403
404//----------------------------------------------------------------------------//
405
406template<>
411
412template <>
417
418//----------------------------------------------------------------------------//
419
420template <>
425
426//----------------------------------------------------------------------------//
427
428template <>
433
434//----------------------------------------------------------------------------//
435
436template <>
441
442//----------------------------------------------------------------------------//
443
444template <>
449
450//----------------------------------------------------------------------------//
451
452template <>
454{
455 return H5T_NATIVE_INT;
456}
457
458//----------------------------------------------------------------------------//
459
460template <>
465
466//----------------------------------------------------------------------------//
467
468template <>
473
474//----------------------------------------------------------------------------//
475
476template <>
481
482//----------------------------------------------------------------------------//
483
484template <>
486{
487 return 16;
488}
489
490//----------------------------------------------------------------------------//
491
492template <>
494{
495 return 32;
496}
497
498//----------------------------------------------------------------------------//
499
500template <>
502{
503 return 64;
504}
505
506//----------------------------------------------------------------------------//
507
508template <>
510{
511 return 16;
512}
513
514//----------------------------------------------------------------------------//
515
516template <>
518{
519 return 32;
520}
521
522//----------------------------------------------------------------------------//
523
524template <>
526{
527 return 64;
528}
529
530//----------------------------------------------------------------------------//
531
533
534//----------------------------------------------------------------------------//
535
536#endif // Include guard
Contains the Log class which can be used to redirect output to an arbitrary destination.
Imath::V3d V3d
Definition SpiMathLib.h:74
FIELD3D_NAMESPACE_OPENtypedef ::half half
Definition SpiMathLib.h:64
Imath::Vec3< half > V3h
Definition SpiMathLib.h:72
Imath::V3f V3f
Definition SpiMathLib.h:73
Imath::C3f C3f
Definition SpiMathLib.h:68
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
Field3D::V3f vec32_t
Definition Traits.h:92
Field3D::M44d mtx64_t
Definition Traits.h:95
Field3D::V3i veci32_t
Definition Traits.h:94
float float32_t
Definition Traits.h:87
Field3D::V3h vec16_t
Definition Traits.h:91
Field3D::V3d vec64_t
Definition Traits.h:93
OgDataType
Enumerates the various uses for Ogawa-level groups.
Definition Traits.h:125
@ F3DInt64
Definition Traits.h:137
@ F3DUint64
Definition Traits.h:138
@ F3DFloat32
Definition Traits.h:142
@ F3DFloat64
Definition Traits.h:143
@ F3DVec64
Definition Traits.h:148
@ F3DUint32
Definition Traits.h:135
@ F3DInt16
Definition Traits.h:131
@ F3DString
Definition Traits.h:155
@ F3DVec32
Definition Traits.h:147
@ F3DInt32
Definition Traits.h:134
@ F3DUint16
Definition Traits.h:132
@ F3DVecI32
Definition Traits.h:149
@ F3DFloat16
Definition Traits.h:141
@ F3DMtx64
Definition Traits.h:152
@ F3DNumDataTypes
Definition Traits.h:157
@ F3DInt8
Definition Traits.h:128
@ F3DInvalidDataType
Definition Traits.h:160
@ F3DUint8
Definition Traits.h:129
@ F3DVec16
Definition Traits.h:146
DataTypeEnum
Definition Traits.h:108
@ DataTypeFloat
Definition Traits.h:112
@ DataTypeHalf
Definition Traits.h:109
@ DataTypeVecHalf
Definition Traits.h:114
@ DataTypeUnsignedChar
Definition Traits.h:110
@ DataTypeVecDouble
Definition Traits.h:116
@ DataTypeUnknown
Definition Traits.h:117
@ DataTypeVecFloat
Definition Traits.h:115
@ DataTypeInt
Definition Traits.h:111
@ DataTypeDouble
Definition Traits.h:113
#define FIELD3D_DECL_DATATYPENAME(typeName)
Definition Traits.h:330
double float64_t
Definition Traits.h:88
half float16_t
Definition Traits.h:86
Contains typedefs for the commonly used types in Field3D.
static const int k_dataDims
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Definition Traits.h:177
static int dataDims()
Definition Traits.h:178
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
static std::string name()
Definition Traits.h:267
static hid_t h5type()
static DataTypeEnum typeEnum()
static int h5bits()
static int dataDims()
Definition Traits.h:258
static int dataDims()
Definition Traits.h:250
static int dataDims()
Definition Traits.h:242
static int dataDims()
Definition Traits.h:234
static int dataDims()
Definition Traits.h:218
static int dataDims()
Definition Traits.h:202
static int dataDims()
Definition Traits.h:194
static int dataDims()
Definition Traits.h:186
static int dataDims()
Definition Traits.h:210
Used to return a string for the name of a nested templated field.
Definition Traits.h:307
const char * name()
Definition Traits.h:308
std::string m_name
Definition Traits.h:323
Used to return a string for the name of a templated field.
Definition Traits.h:283
std::string m_name
Definition Traits.h:297
const char * name()
Definition Traits.h:284