Field3D
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
60
FIELD3D_NAMESPACE_OPEN
61
62
//----------------------------------------------------------------------------//
63
// Enums
64
//----------------------------------------------------------------------------//
65
66
enum
DataTypeEnum
{
67
DataTypeHalf
=0,
68
DataTypeUnsignedChar
,
69
DataTypeInt
,
70
DataTypeFloat
,
71
DataTypeDouble
,
72
DataTypeVecHalf
,
73
DataTypeVecFloat
,
74
DataTypeVecDouble
,
75
DataTypeUnknown
76
};
77
78
//----------------------------------------------------------------------------//
79
// FieldTraits
80
//----------------------------------------------------------------------------//
81
87
template
<
class
Data_T>
88
class
FieldTraits
89
{
90
public
:
92
static
int
dataDims
();
93
};
94
95
//----------------------------------------------------------------------------//
96
// DataTypeTraits
97
//----------------------------------------------------------------------------//
98
99
template
<
typename
T>
100
struct
DataTypeTraits
{
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>
116
struct
TemplatedFieldType
117
{
118
const
char
*
name
()
119
{
120
return
m_name
.c_str();
121
}
122
TemplatedFieldType
()
123
{
124
m_name
= Field_T::staticClassName();
125
m_name
+=
126
"<"
+
127
DataTypeTraits<typename Field_T::value_type>::name
() +
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
)
148
FIELD3D_DECL_DATATYPENAME
(
int
)
149
FIELD3D_DECL_DATATYPENAME
(
float
)
150
FIELD3D_DECL_DATATYPENAME
(
half
)
151
FIELD3D_DECL_DATATYPENAME
(
double
)
152
FIELD3D_DECL_DATATYPENAME
(
V3h
)
153
FIELD3D_DECL_DATATYPENAME
(
V3f
)
154
FIELD3D_DECL_DATATYPENAME
(
V3d
)
155
156
//----------------------------------------------------------------------------//
157
158
template<>
159
inline
DataTypeEnum
DataTypeTraits
<
half
>::typeEnum()
160
{
161
return
DataTypeHalf
;
162
}
163
164
//----------------------------------------------------------------------------//
165
166
template
<>
167
inline
DataTypeEnum
DataTypeTraits<unsigned char>::typeEnum
()
168
{
169
return
DataTypeUnsignedChar
;
170
}
171
172
//----------------------------------------------------------------------------//
173
174
template
<>
175
inline
DataTypeEnum
DataTypeTraits<int>::typeEnum
()
176
{
177
return
DataTypeInt
;
178
}
179
180
//----------------------------------------------------------------------------//
181
182
template
<>
183
inline
DataTypeEnum
DataTypeTraits<float>::typeEnum
()
184
{
185
return
DataTypeFloat
;
186
}
187
188
//----------------------------------------------------------------------------//
189
190
template
<>
191
inline
DataTypeEnum
DataTypeTraits<double>::typeEnum
()
192
{
193
return
DataTypeDouble
;
194
}
195
196
//----------------------------------------------------------------------------//
197
198
template
<>
199
inline
DataTypeEnum
DataTypeTraits<V3h>::typeEnum
()
200
{
201
return
DataTypeVecHalf
;
202
}
203
204
//----------------------------------------------------------------------------//
205
206
template
<>
207
inline
DataTypeEnum
DataTypeTraits<V3f>::typeEnum
()
208
{
209
return
DataTypeVecFloat
;
210
}
211
212
//----------------------------------------------------------------------------//
213
214
template
<>
215
inline
DataTypeEnum
DataTypeTraits<V3d>::typeEnum
()
216
{
217
return
DataTypeVecDouble
;
218
}
219
220
template
<>
221
inline
hid_t
DataTypeTraits<half>::h5type
()
222
{
223
return
H5T_NATIVE_SHORT;
224
}
225
226
//----------------------------------------------------------------------------//
227
228
template
<>
229
inline
hid_t
DataTypeTraits<float>::h5type
()
230
{
231
return
H5T_NATIVE_FLOAT;
232
}
233
234
//----------------------------------------------------------------------------//
235
236
template
<>
237
inline
hid_t
DataTypeTraits<double>::h5type
()
238
{
239
return
H5T_NATIVE_DOUBLE;
240
}
241
242
//----------------------------------------------------------------------------//
243
244
template
<>
245
inline
hid_t
DataTypeTraits<char>::h5type
()
246
{
247
return
H5T_NATIVE_CHAR;
248
}
249
250
//----------------------------------------------------------------------------//
251
252
template
<>
253
inline
hid_t
DataTypeTraits<unsigned char>::h5type
()
254
{
255
return
H5T_NATIVE_UCHAR;
256
}
257
258
//----------------------------------------------------------------------------//
259
260
template
<>
261
inline
hid_t
DataTypeTraits<int>::h5type
()
262
{
263
return
H5T_NATIVE_INT;
264
}
265
266
//----------------------------------------------------------------------------//
267
268
template
<>
269
inline
hid_t
DataTypeTraits<V3h>::h5type
()
270
{
271
return
H5T_NATIVE_SHORT;
272
}
273
274
//----------------------------------------------------------------------------//
275
276
template
<>
277
inline
hid_t
DataTypeTraits<V3f>::h5type
()
278
{
279
return
H5T_NATIVE_FLOAT;
280
}
281
282
//----------------------------------------------------------------------------//
283
284
template
<>
285
inline
hid_t
DataTypeTraits<V3d>::h5type
()
286
{
287
return
H5T_NATIVE_DOUBLE;
288
}
289
290
//----------------------------------------------------------------------------//
291
292
template
<>
293
inline
int
DataTypeTraits<half>::h5bits
()
294
{
295
return
16;
296
}
297
298
//----------------------------------------------------------------------------//
299
300
template
<>
301
inline
int
DataTypeTraits<float>::h5bits
()
302
{
303
return
32;
304
}
305
306
//----------------------------------------------------------------------------//
307
308
template
<>
309
inline
int
DataTypeTraits<double>::h5bits
()
310
{
311
return
64;
312
}
313
314
//----------------------------------------------------------------------------//
315
316
template
<>
317
inline
int
DataTypeTraits<V3h>::h5bits
()
318
{
319
return
16;
320
}
321
322
//----------------------------------------------------------------------------//
323
324
template
<>
325
inline
int
DataTypeTraits<V3f>::h5bits
()
326
{
327
return
32;
328
}
329
330
//----------------------------------------------------------------------------//
331
332
template
<>
333
inline
int
DataTypeTraits<V3d>::h5bits
()
334
{
335
return
64;
336
}
337
338
//----------------------------------------------------------------------------//
339
340
FIELD3D_NAMESPACE_HEADER_CLOSE
341
342
//----------------------------------------------------------------------------//
343
344
#endif // Include guard
export
Traits.h
Generated on Mon Jul 8 2013 15:25:48 for Field3D by
1.8.4