All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TypeTraits.h
1 //
2 // Copyright 2017 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 _GUSD_UT_TYPETRAITS_H_
25 #define _GUSD_UT_TYPETRAITS_H_
26 
27 #include "pxr/pxr.h"
28 
29 #include <SYS/SYS_TypeTraits.h>
30 #include <SYS/SYS_Types.h>
31 #include <SYS/SYS_Version.h>
32 #include <UT/UT_VectorTypes.h>
33 
34 #include "pxr/base/gf/half.h"
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
42 template <class T>
44 {
45  using ValueType = void;
46  static const int tupleSize = 1;
47 };
48 
49 
51 #define GUSDUT_DECLARE_POD_TUPLE(TYPE, VALUETYPE, TUPLESIZE) \
52  template <> \
53  struct GusdPodTupleTraits<TYPE> { \
54  static const int tupleSize = TUPLESIZE; \
55  using ValueType = VALUETYPE; \
56  };
57 
58 
60 template <typename T>
61 constexpr bool GusdIsPodTuple()
62 {
63  return !SYSisSame<typename GusdPodTupleTraits<T>::ValueType, void>();
64 }
65 
66 
68 template <typename T>
69 constexpr int GusdGetTupleSize()
70 {
72 }
73 
74 
77 template <typename A, typename B>
78 constexpr bool GusdPodTuplesAreCompatible()
79 {
80  return GusdGetTupleSize<A>() == GusdGetTupleSize<B>();
81 }
82 
83 
85 template <typename A, typename B>
86 constexpr bool GusdPodTuplesAreBitwiseCompatible()
87 {
88  return GusdPodTuplesAreCompatible<A,B>() &&
89  SYSisSame<typename GusdPodTupleTraits<A>::ValueType,
90  typename GusdPodTupleTraits<B>::ValueType>();
91 }
92 
93 
95 GUSDUT_DECLARE_POD_TUPLE(UT_Vector2H, fpreal16, 2);
96 GUSDUT_DECLARE_POD_TUPLE(UT_Vector3H, fpreal16, 3);
97 GUSDUT_DECLARE_POD_TUPLE(UT_Vector4H, fpreal16, 4);
98 
99 GUSDUT_DECLARE_POD_TUPLE(UT_Vector2F, fpreal32, 2);
100 GUSDUT_DECLARE_POD_TUPLE(UT_Vector3F, fpreal32, 3);
101 GUSDUT_DECLARE_POD_TUPLE(UT_Vector4F, fpreal32, 4);
102 
103 GUSDUT_DECLARE_POD_TUPLE(UT_Vector2D, fpreal64, 2);
104 GUSDUT_DECLARE_POD_TUPLE(UT_Vector3D, fpreal64, 3);
105 GUSDUT_DECLARE_POD_TUPLE(UT_Vector4D, fpreal64, 4);
106 
107 GUSDUT_DECLARE_POD_TUPLE(UT_Vector2I, int64, 2);
108 GUSDUT_DECLARE_POD_TUPLE(UT_Vector3I, int64, 3);
109 GUSDUT_DECLARE_POD_TUPLE(UT_Vector4I, int64, 4);
110 
111 GUSDUT_DECLARE_POD_TUPLE(UT_Vector2i, int32, 2);
112 GUSDUT_DECLARE_POD_TUPLE(UT_Vector3i, int32, 3);
113 GUSDUT_DECLARE_POD_TUPLE(UT_Vector4i, int32, 4);
114 
115 #if SYS_VERSION_FULL_INT >= 0x11000000
116 GUSDUT_DECLARE_POD_TUPLE(UT_QuaternionH, fpreal16, 4);
117 #endif
118 GUSDUT_DECLARE_POD_TUPLE(UT_QuaternionF, fpreal32, 4);
119 GUSDUT_DECLARE_POD_TUPLE(UT_QuaternionD, fpreal64, 4);
120 
121 GUSDUT_DECLARE_POD_TUPLE(UT_Matrix2F, fpreal32, 4);
122 GUSDUT_DECLARE_POD_TUPLE(UT_Matrix3F, fpreal32, 9);
123 GUSDUT_DECLARE_POD_TUPLE(UT_Matrix4F, fpreal32, 16);
124 
125 GUSDUT_DECLARE_POD_TUPLE(UT_Matrix2D, fpreal64, 4);
126 GUSDUT_DECLARE_POD_TUPLE(UT_Matrix3D, fpreal64, 9);
127 GUSDUT_DECLARE_POD_TUPLE(UT_Matrix4D, fpreal64, 16);
128 
130 GUSDUT_DECLARE_POD_TUPLE(bool, bool, 1);
131 GUSDUT_DECLARE_POD_TUPLE(uint8, uint8, 1);
132 GUSDUT_DECLARE_POD_TUPLE(uint16, uint16, 1);
133 GUSDUT_DECLARE_POD_TUPLE(uint32, uint32, 1);
134 GUSDUT_DECLARE_POD_TUPLE(uint64, uint64, 1);
135 GUSDUT_DECLARE_POD_TUPLE(int8, int8, 1);
136 GUSDUT_DECLARE_POD_TUPLE(int16, int16, 1);
137 GUSDUT_DECLARE_POD_TUPLE(int32, int32, 1);
138 GUSDUT_DECLARE_POD_TUPLE(int64, int64, 1);
139 GUSDUT_DECLARE_POD_TUPLE(fpreal16, fpreal16, 1);
140 GUSDUT_DECLARE_POD_TUPLE(fpreal32, fpreal32, 1);
141 GUSDUT_DECLARE_POD_TUPLE(fpreal64, fpreal64, 1);
142 GUSDUT_DECLARE_POD_TUPLE(GfHalf, GfHalf, 1);
143 
144 PXR_NAMESPACE_CLOSE_SCOPE
145 
146 #endif // _GUSD_UT_TYPETRAITS_H_
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:42
Traits for a POD tuple; fixed-size tuples of a single POD type.
Definition: UT_TypeTraits.h:43