All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_VT_TYPES_H
25 #define PXR_BASE_VT_TYPES_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/vt/api.h"
32 #include "pxr/base/vt/traits.h"
33 #include "pxr/base/arch/inttypes.h"
34 #include "pxr/base/gf/declare.h"
35 #include "pxr/base/gf/half.h"
36 #include "pxr/base/tf/token.h"
37 
38 #include <boost/preprocessor/cat.hpp>
39 #include <boost/preprocessor/seq/for_each.hpp>
40 #include <boost/preprocessor/tuple/elem.hpp>
41 
42 #include <cstddef>
43 #include <cstring>
44 #include <string>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 // Help ensure TfToken is stored in local storage in VtValue by indicating it is
49 // cheap to copy (just refcount operations).
50 VT_TYPE_IS_CHEAP_TO_COPY(TfToken);
51 
52 // Value types.
53 
54 #define VT_FLOATING_POINT_BUILTIN_VALUE_TYPES \
55 (( double, Double )) \
56 (( float, Float )) \
57 (( GfHalf, Half ))
58 
59 #define VT_INTEGRAL_BUILTIN_VALUE_TYPES \
60 (( bool, Bool )) \
61 (( char, Char )) \
62 (( unsigned char, UChar )) \
63 (( short, Short )) \
64 (( unsigned short, UShort )) \
65 (( int, Int )) \
66 (( unsigned int, UInt )) \
67 (( int64_t, Int64 )) \
68 (( uint64_t, UInt64 ))
69 
70 #define VT_VEC_INT_VALUE_TYPES \
71 (( GfVec4i, Vec4i )) \
72 (( GfVec3i, Vec3i )) \
73 (( GfVec2i, Vec2i ))
74 
75 #define VT_VEC_HALF_VALUE_TYPES \
76 (( GfVec4h, Vec4h )) \
77 (( GfVec3h, Vec3h )) \
78 (( GfVec2h, Vec2h ))
79 
80 #define VT_VEC_FLOAT_VALUE_TYPES \
81 (( GfVec4f, Vec4f )) \
82 (( GfVec3f, Vec3f )) \
83 (( GfVec2f, Vec2f ))
84 
85 #define VT_VEC_DOUBLE_VALUE_TYPES \
86 (( GfVec4d, Vec4d )) \
87 (( GfVec3d, Vec3d )) \
88 (( GfVec2d, Vec2d ))
89 
90 #define VT_VEC_VALUE_TYPES \
91  VT_VEC_INT_VALUE_TYPES \
92  VT_VEC_HALF_VALUE_TYPES \
93  VT_VEC_FLOAT_VALUE_TYPES \
94  VT_VEC_DOUBLE_VALUE_TYPES
95 
96 #define VT_MATRIX_FLOAT_VALUE_TYPES \
97 (( GfMatrix4f, Matrix4f )) \
98 (( GfMatrix3f, Matrix3f )) \
99 (( GfMatrix2f, Matrix2f )) \
100 
101 #define VT_MATRIX_DOUBLE_VALUE_TYPES \
102 (( GfMatrix4d, Matrix4d )) \
103 (( GfMatrix3d, Matrix3d )) \
104 (( GfMatrix2d, Matrix2d ))
105 
106 #define VT_MATRIX_VALUE_TYPES \
107  VT_MATRIX_FLOAT_VALUE_TYPES \
108  VT_MATRIX_DOUBLE_VALUE_TYPES \
109 
110 #define VT_GFRANGE_VALUE_TYPES \
111 (( GfRange3f, Range3f )) \
112 (( GfRange3d, Range3d )) \
113 (( GfRange2f, Range2f )) \
114 (( GfRange2d, Range2d )) \
115 (( GfRange1f, Range1f )) \
116 (( GfRange1d, Range1d ))
117 
118 #define VT_RANGE_VALUE_TYPES \
119  VT_GFRANGE_VALUE_TYPES \
120 (( GfInterval, Interval )) \
121 (( GfRect2i, Rect2i ))
122 
123 #define VT_STRING_VALUE_TYPES \
124 (( std::string, String )) \
125 (( TfToken, Token ))
126 
127 #define VT_QUATERNION_VALUE_TYPES \
128 (( GfQuath, Quath )) \
129 (( GfQuatf, Quatf )) \
130 (( GfQuatd, Quatd )) \
131 (( GfQuaternion, Quaternion ))
132 
133 #define VT_NONARRAY_VALUE_TYPES \
134 (( GfFrustum, Frustum)) \
135 (( GfMultiInterval, MultiInterval))
136 
137 // Helper macros for extracting bits from a type tuple.
138 #define VT_TYPE(elem) \
139 BOOST_PP_TUPLE_ELEM(2, 0, elem)
140 #define VT_TYPE_NAME(elem) \
141 BOOST_PP_TUPLE_ELEM(2, 1, elem)
142 
143 
144 // Composite groups of types.
145 #define VT_BUILTIN_NUMERIC_VALUE_TYPES \
146 VT_INTEGRAL_BUILTIN_VALUE_TYPES VT_FLOATING_POINT_BUILTIN_VALUE_TYPES
147 
148 #define VT_BUILTIN_VALUE_TYPES \
149 VT_BUILTIN_NUMERIC_VALUE_TYPES VT_STRING_VALUE_TYPES
150 
151 #define VT_SCALAR_CLASS_VALUE_TYPES \
152 VT_VEC_VALUE_TYPES \
153 VT_MATRIX_VALUE_TYPES \
154 VT_RANGE_VALUE_TYPES \
155 VT_QUATERNION_VALUE_TYPES
156 
157 #define VT_SCALAR_VALUE_TYPES \
158 VT_SCALAR_CLASS_VALUE_TYPES VT_BUILTIN_VALUE_TYPES
159 
160 
161 // The following preprocessor code produces typedefs for VtArray holding
162 // various scalar value types. The produced typedefs are of the form:
163 //
164 // typedef VtArray<int> VtIntArray;
165 // typedef VtArray<double> VtDoubleArray;
166 template<typename T> class VtArray;
167 #define VT_ARRAY_TYPEDEF(r, unused, elem) \
168 typedef VtArray< VT_TYPE(elem) > \
169 BOOST_PP_CAT(Vt, BOOST_PP_CAT(VT_TYPE_NAME(elem), Array)) ;
170 BOOST_PP_SEQ_FOR_EACH(VT_ARRAY_TYPEDEF, ~, VT_SCALAR_VALUE_TYPES)
171 
172 // The following preprocessor code generates the boost pp sequence for
173 // all array value types (VT_ARRAY_VALUE_TYPES)
174 #define VT_ARRAY_TYPE_TUPLE(r, unused, elem) \
175 (( BOOST_PP_CAT(Vt, BOOST_PP_CAT(VT_TYPE_NAME(elem), Array)) , \
176  BOOST_PP_CAT(VT_TYPE_NAME(elem), Array) ))
177 #define VT_ARRAY_VALUE_TYPES \
178 BOOST_PP_SEQ_FOR_EACH(VT_ARRAY_TYPE_TUPLE, ~, VT_SCALAR_VALUE_TYPES)
179 
180 #define VT_CLASS_VALUE_TYPES \
181 VT_ARRAY_VALUE_TYPES VT_SCALAR_CLASS_VALUE_TYPES VT_NONARRAY_VALUE_TYPES
182 
183 // Free functions to represent "zero" for various base types. See
184 // specializations in Types.cpp
185 template<typename T>
186 T VtZero();
187 
188 // Shape representation used in VtArray for legacy code. This is not supported
189 // at the pxr level or in usd. Shape is represented by a total size, plus sized
190 // dimensions other than the last. The size of the last dimension is computed
191 // as totalSize / (product-of-other-dimensions).
192 struct Vt_ShapeData {
193  unsigned int GetRank() const {
194  return
195  otherDims[0] == 0 ? 1 :
196  otherDims[1] == 0 ? 2 :
197  otherDims[2] == 0 ? 3 : 4;
198  }
199  bool operator==(Vt_ShapeData const &other) const {
200  if (totalSize != other.totalSize)
201  return false;
202  unsigned int thisRank = GetRank(), otherRank = other.GetRank();
203  if (thisRank != otherRank)
204  return false;
205  return std::equal(otherDims, otherDims + GetRank() - 1,
206  other.otherDims);
207  }
208  bool operator!=(Vt_ShapeData const &other) const {
209  return !(*this == other);
210  }
211  void clear() {
212  memset(this, 0, sizeof(*this));
213  }
214  static const int NumOtherDims = 3;
215  size_t totalSize;
216  unsigned int otherDims[NumOtherDims];
217 };
218 
219 PXR_NAMESPACE_CLOSE_SCOPE
220 
221 #endif // PXR_BASE_VT_TYPES_H
This header serves to simply bring in the half float datatype and provide a hash_value function...
Declares Gf types.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:229
Define integral types.
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...