HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TypedPropertyTraits.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
4 // Sony Pictures Imageworks, Inc. and
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
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
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // * Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36 
37 #ifndef _Alembic_Abc_TypedPropertyTraits_h_
38 #define _Alembic_Abc_TypedPropertyTraits_h_
39 
40 #include <Alembic/Abc/Foundation.h>
41 
42 //-*****************************************************************************
43 // The property traits class maps ValueTypes with their protocol
44 // strings.
45 
46 namespace Alembic {
47 namespace Abc {
48 namespace ALEMBIC_VERSION_NS {
49 
50 //-*****************************************************************************
51 //-*****************************************************************************
52 // This macro relies on there being a default constructor for the type
53 // VAL
54 #define ALEMBIC_ABC_DECLARE_TYPE_TRAITS( VAL, POD, EXTENT, INTERP, PTDEF ) \
55 struct PTDEF \
56 { \
57  static const PlainOldDataType pod_enum = POD; \
58  static const int extent = EXTENT; \
59  typedef VAL value_type; \
60  static const char * interpretation() { return ( INTERP ) ; } \
61  static const char * name() { return #PTDEF; } \
62  static AbcA::DataType dataType() \
63  { return AbcA::DataType( POD, EXTENT ) ; } \
64  static value_type defaultValue() \
65  { value_type v; return v; } \
66 }
67 
68 //-*****************************************************************************
69 //-*****************************************************************************
70 #define DECLARE_POD_TRAITS( POD_TYPE , PTDEF ) \
71 struct PTDEF \
72 { \
73  static const PlainOldDataType pod_enum = \
74  PODTraitsFromType< POD_TYPE >::pod_enum; \
75  static const int extent = 1; \
76  typedef POD_TYPE value_type; \
77  static const char * interpretation() { return ""; } \
78  static const char * name() { return #PTDEF; } \
79  static AbcA::DataType dataType() \
80  { return AbcA::DataType( PODTraitsFromType< POD_TYPE >::pod_enum, 1 ); } \
81  static value_type defaultValue() \
82  { return PODTraitsFromType< POD_TYPE >::default_value(); } \
83 }
84 
85 //-*****************************************************************************
86 DECLARE_POD_TRAITS( bool_t, BooleanTPTraits );
87 DECLARE_POD_TRAITS( uint8_t, Uint8TPTraits );
88 DECLARE_POD_TRAITS( int8_t, Int8TPTraits );
89 DECLARE_POD_TRAITS( uint16_t, Uint16TPTraits );
90 DECLARE_POD_TRAITS( int16_t, Int16TPTraits );
91 DECLARE_POD_TRAITS( uint32_t, Uint32TPTraits );
92 DECLARE_POD_TRAITS( int32_t, Int32TPTraits );
93 DECLARE_POD_TRAITS( uint64_t, Uint64TPTraits );
94 DECLARE_POD_TRAITS( int64_t, Int64TPTraits );
95 DECLARE_POD_TRAITS( float16_t, Float16TPTraits );
96 DECLARE_POD_TRAITS( float32_t, Float32TPTraits );
97 DECLARE_POD_TRAITS( float64_t, Float64TPTraits );
98 DECLARE_POD_TRAITS( string, StringTPTraits );
99 DECLARE_POD_TRAITS( wstring, WstringTPTraits );
100 
101 #undef DECLARE_POD_TRAITS
102 
103 //-*****************************************************************************
104 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2s, kInt16POD, 2, "vector", V2sTPTraits );
105 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2i, kInt32POD, 2, "vector", V2iTPTraits );
106 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2f, kFloat32POD, 2, "vector", V2fTPTraits );
107 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2d, kFloat64POD, 2, "vector", V2dTPTraits );
108 
109 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3s, kInt16POD, 3, "vector", V3sTPTraits );
110 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3i, kInt32POD, 3, "vector", V3iTPTraits );
111 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3f, kFloat32POD, 3, "vector", V3fTPTraits );
112 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3d, kFloat64POD, 3, "vector", V3dTPTraits );
113 
114 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2s, kInt16POD, 2, "point", P2sTPTraits );
115 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2i, kInt32POD, 2, "point", P2iTPTraits );
116 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2f, kFloat32POD, 2, "point", P2fTPTraits );
117 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2d, kFloat64POD, 2, "point", P2dTPTraits );
118 
119 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3s, kInt16POD, 3, "point", P3sTPTraits );
120 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3i, kInt32POD, 3, "point", P3iTPTraits );
121 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3f, kFloat32POD, 3, "point", P3fTPTraits );
122 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V3d, kFloat64POD, 3, "point", P3dTPTraits );
123 
124 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box2s, kInt16POD, 4, "box", Box2sTPTraits );
125 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box2i, kInt32POD, 4, "box", Box2iTPTraits );
126 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box2f, kFloat32POD, 4, "box", Box2fTPTraits );
127 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box2d, kFloat64POD, 4, "box", Box2dTPTraits );
128 
129 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box3s, kInt16POD, 6, "box", Box3sTPTraits );
130 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box3i, kInt32POD, 6, "box", Box3iTPTraits );
131 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box3f, kFloat32POD, 6, "box", Box3fTPTraits );
132 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Box3d, kFloat64POD, 6, "box", Box3dTPTraits );
133 
134 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( M33f, kFloat32POD, 9, "matrix", M33fTPTraits );
135 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( M33d, kFloat64POD, 9, "matrix", M33dTPTraits );
136 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( M44f, kFloat32POD, 16, "matrix", M44fTPTraits );
137 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( M44d, kFloat64POD, 16, "matrix", M44dTPTraits );
138 
139 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Quatf, kFloat32POD, 4, "quat", QuatfTPTraits );
140 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( Quatd, kFloat64POD, 4, "quat", QuatdTPTraits );
141 
142 //-*****************************************************************************
143 // colors. For now, using "rgb"/"rgba" as the interpretation
144 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( C3h, kFloat16POD, 3, "rgb", C3hTPTraits );
145 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( C3f, kFloat32POD, 3, "rgb", C3fTPTraits );
146 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( C3c, kUint8POD, 3, "rgb", C3cTPTraits );
147 
148 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( C4h, kFloat16POD, 4, "rgba", C4hTPTraits );
149 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( C4f, kFloat32POD, 4, "rgba", C4fTPTraits );
150 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( C4c, kUint8POD, 4, "rgba", C4cTPTraits );
151 
152 //-*****************************************************************************
153 // Normals.
154 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2f, kFloat32POD, 2, "normal", N2fTPTraits );
155 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( V2d, kFloat64POD, 2, "normal", N2dTPTraits );
156 
157 // N3f and N3d is typedefed in Foundation from V3f and V3d
158 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( N3f, kFloat32POD, 3, "normal", N3fTPTraits );
159 ALEMBIC_ABC_DECLARE_TYPE_TRAITS( N3d, kFloat64POD, 3, "normal", N3dTPTraits );
160 
161 } // End namespace ALEMBIC_VERSION_NS
162 
163 using namespace ALEMBIC_VERSION_NS;
164 
165 } // End namespace Abc
166 } // End namespace Alembic
167 
168 #endif
ALEMBIC_ABC_DECLARE_TYPE_TRAITS(V2s, kInt16POD, 2,"vector", V2sTPTraits)
DECLARE_POD_TRAITS(bool_t, BooleanTPTraits)
Definition: ImathBox.h:72
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104