HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TypeTraits.h
Go to the documentation of this file.
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 <UT/UT_VectorTypes.h>
32 
33 #include "pxr/base/gf/half.h"
34 
36 
37 /// Traits for a POD tuple; fixed-size tuples of a single POD type.
38 /// These are defined in order to have an API for type traits shared between
39 /// both the Houdini's UT types and Gf types.
40 /// Use GUSDUT_DECLARE_POD_TUPLE() to declare the type info for a new type.
41 template <class T>
43 {
44  using ValueType = void;
45  static const int tupleSize = 1;
46 };
47 
48 
49 /// Helper for declaring a POD tuple.
50 #define GUSDUT_DECLARE_POD_TUPLE(TYPE, VALUETYPE, TUPLESIZE) \
51  template <> \
52  struct GusdPodTupleTraits<TYPE> { \
53  static const int tupleSize = TUPLESIZE; \
54  using ValueType = VALUETYPE; \
55  };
56 
57 
58 /// Returns true if a type is a POD tuple.
59 template <typename T>
60 constexpr bool GusdIsPodTuple()
61 {
62  return !SYSisSame<typename GusdPodTupleTraits<T>::ValueType, void>();
63 }
64 
65 
66 /// Returns the tuples ize of a POD tuple.
67 template <typename T>
68 constexpr int GusdGetTupleSize()
69 {
71 }
72 
73 
74 /// Returns true if two POD tuples are compatible
75 /// (I.e., same tuple size, not necessarily same types).
76 template <typename A, typename B>
78 {
79  return GusdGetTupleSize<A>() == GusdGetTupleSize<B>();
80 }
81 
82 
83 /// Returns true if two POD tuples have identical memory layouts.
84 template <typename A, typename B>
86 {
87  return GusdPodTuplesAreCompatible<A,B>() &&
88  SYSisSame<typename GusdPodTupleTraits<A>::ValueType,
90 }
91 
92 
93 /// Declare traits on core types.
97 
101 
105 
109 
113 
117 
121 
125 
126 /// Declare PODs as POD tuples of tupleSize=1.
127 GUSDUT_DECLARE_POD_TUPLE(bool, bool, 1);
140 
142 
143 #endif // _GUSD_UT_TYPETRAITS_H_
constexpr int GusdGetTupleSize()
Returns the tuples ize of a POD tuple.
Definition: UT_TypeTraits.h:68
unsigned short uint16
Definition: SYS_Types.h:38
constexpr bool GusdIsPodTuple()
Returns true if a type is a POD tuple.
Definition: UT_TypeTraits.h:60
int int32
Definition: SYS_Types.h:39
unsigned long long uint64
Definition: SYS_Types.h:117
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:166
2D Vector class.
Definition: UT_Vector2.h:149
float fpreal32
Definition: SYS_Types.h:200
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
void
Definition: png.h:1083
long long int64
Definition: SYS_Types.h:116
signed char int8
Definition: SYS_Types.h:35
static const int tupleSize
Definition: UT_TypeTraits.h:45
Quaternion class.
Definition: UT_Quaternion.h:51
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
short int16
Definition: SYS_Types.h:37
constexpr bool GusdPodTuplesAreBitwiseCompatible()
Returns true if two POD tuples have identical memory layouts.
Definition: UT_TypeTraits.h:85
#define GUSDUT_DECLARE_POD_TUPLE(TYPE, VALUETYPE, TUPLESIZE)
Helper for declaring a POD tuple.
Definition: UT_TypeTraits.h:50
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
unsigned int uint32
Definition: SYS_Types.h:40
constexpr bool GusdPodTuplesAreCompatible()
Definition: UT_TypeTraits.h:77