HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_Types.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VEX_Types.h ( VEX Library, C++)
7  *
8  * COMMENTS: Data types for VEX variables
9  */
10 
11 #ifndef __VEX_Types__
12 #define __VEX_Types__
13 
14 #include "VEX_API.h"
15 #include <SYS/SYS_StaticAssert.h>
16 #include <UT/UT_Vector3.h>
17 #include <UT/UT_Vector4.h>
18 #include <UT/UT_Matrix3.h>
19 #include <UT/UT_Matrix4.h>
20 #include <UT/UT_Options.h>
21 #include "VEX_PodTypes.h"
22 #include "VEX_VexTypes.h"
23 #include "VEX_RefObject.h"
24 
25 template <VEX_Precision PREC> class VEX_Value;
26 template <VEX_Precision PREC> class VEX_Instance;
27 class VEX_ProcArray;
28 class VEX_OpCode;
29 class FS_DiskCache;
30 
31 // Two way type resolver
32 //
33 // VEX_VexTypeResolver: C++ Type -> Vex Type
34 // VEX_TypeResolver: Vex Type + PREC -> C++ Type
35 //
36 
37 template <typename T>
39 template <VEX_Type VTYPE, VEX_Precision PREC>
41 
42 
43 #define VEX_TYPERESOLVE_CASE(VexType, CPPType) \
44  template <> \
45  struct VEX_VexTypeResolver<VEX##CPPType<VEX_32> > \
46  { \
47  static constexpr VEX_Type type = VEX_TYPE_##VexType; \
48  }; \
49  template <> \
50  struct VEX_VexTypeResolver<VEX##CPPType<VEX_64> > \
51  { \
52  static constexpr VEX_Type type = VEX_TYPE_##VexType; \
53  }; \
54  template <VEX_Precision PREC> \
55  struct VEX_TypeResolver<VEX_TYPE_##VexType, PREC> \
56  { \
57  typedef VEX##CPPType<PREC> T; \
58  };
59  /* end of macro */
60 
62 VEX_TYPERESOLVE_CASE(INTEGER, int);
63 VEX_TYPERESOLVE_CASE(VECTOR2, vec2);
65 VEX_TYPERESOLVE_CASE(VECTOR4, vec4);
66 VEX_TYPERESOLVE_CASE(MATRIX2, mat2);
67 VEX_TYPERESOLVE_CASE(MATRIX3, mat3);
68 VEX_TYPERESOLVE_CASE(MATRIX4, mat4);
69 
70 template <>
72 {
73  static constexpr VEX_Type type = VEX_TYPE_STRING;
74 };
75 template <VEX_Precision PREC>
77 {
78  typedef UT_StringHolder T;
79 };
80 template <>
82 {
83  static constexpr VEX_Type type = VEX_TYPE_DICT;
84 };
85 template <VEX_Precision PREC>
87 {
89 };
90 template <>
92 {
93  static constexpr VEX_Type type = VEX_TYPE_BSDF;
94 };
95 template <VEX_Precision PREC>
97 {
98  typedef VEX_RefObject* T;
99 };
100 
101 #undef VEX_TYPERESOLVE_CASE
102 
103 
105 {
106  VEX_STORE_UNDEF, // Undefined until a later date
107 
108  VEX_STORE_PARAMETER, // Possibly bound to some other source
109  VEX_STORE_LOCAL, // Local variable - storage deferred until bind
110  VEX_STORE_CONST, // Constant
111  VEX_STORE_GLOBAL, // Global variable
112 
113  VEX_MAX_STORAGE // Last entry is a counter only
114 };
115 
117 {
119  VEX_BASETYPE_INT, // Integer
122  VEX_BASETYPE_DICT, // Untyped dictionary
123 };
124 
126 {
127  VEX_UI_NONE, // No ui hint
128  VEX_UI_COLOR, // Parameter represents a color
129  VEX_UI_DIRECTION, // a direction vector
130  VEX_UI_VECTOR, // a position vector
131  VEX_UI_VECTOR4, // a position vector 4
132  VEX_UI_UV, // a uv position
133  VEX_UI_UVW, // a uvw position
134  VEX_UI_ANGLE, // an angle
135  VEX_UI_TOGGLE, // a boolean toggle
136  VEX_UI_BUTTON, // a button for executing a callback
137  VEX_UI_FILE, // a filename
138  VEX_UI_IMGFILE, // an image file/ramp
139  VEX_UI_GEOFILE, // a geometry file
140  VEX_UI_OPPATH, // an operator path
141  VEX_UI_OPLIST, // a list of operator paths
142  VEX_UI_EMBED, // an embedded set of parameters
144 };
145 
146 class VEX_RWType {
147 public:
149  : myRead(false)
150  , myWrite(false) {}
151  VEX_RWType(bool read, bool write)
152  : myRead(read)
153  , myWrite(write) {}
154 
155  void setRead(bool r = true) { myRead = r; }
156  void setWrite(bool w = true) { myWrite = w; }
157  bool isRead() const { return myRead; }
158  bool isWrite() const { return myWrite; }
159 
160  bool operator==(const VEX_RWType &rhs) const
161  { return myRead == rhs.myRead &&
162  myWrite == rhs.myWrite; }
163  bool operator!=(const VEX_RWType &rhs) const
164  { return !(*this == rhs); }
165 
166  const char *asString() const
167  {
168  if (myRead && myWrite) return "modify";
169  if (myRead) return "read";
170  if (myWrite) return "write";
171  return "unused";
172  }
173 
174 private:
175  bool myRead;
176  bool myWrite;
177 };
178 
179 static const VEX_RWType VEX_RW_NONE(false, false);
180 static const VEX_RWType VEX_RW_READ(true, false);
181 static const VEX_RWType VEX_RW_WRITE(false, true);
182 static const VEX_RWType VEX_RW_MODIFY(true, true);
183 
184 VEX_API const char *VEXgetType(VEX_Type type);
188 VEX_API VEX_Type VEXgetType(const char *label);
189 VEX_API VEX_Type VEXgetType(const char *label, bool &isarray);
190 // Dangerous as there is no unique mapping.
191 // VEX_API VEX_Type VEXgetType(int size);
192 VEX_API VEX_Type VEXgetMangleType(char mangle);
196 VEX_API const char *VEXgetUIHint(VEX_UIHint type);
197 VEX_API VEX_UIHint VEXgetUIHint(const char *label);
198 
199 SYS_FORCE_INLINE constexpr bool
201 {
202  switch (type)
203  {
204  case VEX_TYPE_FLOAT: return true;
205  case VEX_TYPE_INTEGER: return true;
206  case VEX_TYPE_VECTOR2: return true;
207  case VEX_TYPE_VECTOR: return true;
208  case VEX_TYPE_VECTOR4: return true;
209  case VEX_TYPE_MATRIX2: return true;
210  case VEX_TYPE_MATRIX3: return true;
211  case VEX_TYPE_MATRIX4: return true;
212  default: return false;
213  }
214  return false;
215 }
216 
217 
219 
220 template <VEX_Precision PREC> static inline constexpr size_t
221 VEXsizeof(VEX_Type type)
222 {
223  switch (type)
224  {
225  case VEX_TYPE_VECTOR4: return sizeof(VEXvec4<PREC>);
226  case VEX_TYPE_VECTOR: return sizeof(VEXvec3<PREC>);
227  case VEX_TYPE_VECTOR2: return sizeof(VEXvec2<PREC>);
228  case VEX_TYPE_FLOAT: return sizeof(VEXfloat<PREC>);
229  case VEX_TYPE_INTEGER: return sizeof(VEXint<PREC>);
230  case VEX_TYPE_STRING: return sizeof(UT_StringHolder);
231  case VEX_TYPE_MATRIX2: return sizeof(VEXmat2<PREC>);
232  case VEX_TYPE_MATRIX3: return sizeof(VEXmat3<PREC>);
233  case VEX_TYPE_MATRIX4: return sizeof(VEXmat4<PREC>);
234  case VEX_TYPE_BSDF: return sizeof(VEX_RefObject *);
235  case VEX_TYPE_DICT: return sizeof(UT_OptionsHolder);
236  default: break;
237  }
238  return 0;
239 }
240 
241 VEX_API int VEXtupleSize(VEX_Type type); // Tuple size
242 VEX_API bool VEXisFloat(VEX_Type type);
243 VEX_API bool VEXisInt(VEX_Type type);
244 VEX_API bool VEXisString(VEX_Type type);
245 
246 static inline bool
247 VEXisNumeric(VEX_Type type)
248 {
249  return VEXisInt(type) || VEXisFloat(type);
250 }
251 
252 template <typename T> static inline constexpr int VEXtupleSize()
253  { SYS_UNIMPLEMENTED_TEMPLATE(T); return 0; }
254 template <> inline constexpr int VEXtupleSize<VEXint<VEX_32>>() { return 1; }
255 template <> inline constexpr int VEXtupleSize<VEXint<VEX_64>>() { return 1; }
256 template <> inline constexpr int VEXtupleSize<VEXfloat<VEX_32>>() { return 1; }
257 template <> inline constexpr int VEXtupleSize<VEXfloat<VEX_64>>() { return 1; }
258 template <> inline constexpr int VEXtupleSize<VEXvec2<VEX_32>>() { return 2; }
259 template <> inline constexpr int VEXtupleSize<VEXvec2<VEX_64>>() { return 2; }
260 template <> inline constexpr int VEXtupleSize<VEXvec3<VEX_32>>() { return 3; }
261 template <> inline constexpr int VEXtupleSize<VEXvec3<VEX_64>>() { return 3; }
262 template <> inline constexpr int VEXtupleSize<VEXvec4<VEX_32>>() { return 4; }
263 template <> inline constexpr int VEXtupleSize<VEXvec4<VEX_64>>() { return 4; }
264 template <> inline constexpr int VEXtupleSize<VEXmat2<VEX_32>>() { return 4; }
265 template <> inline constexpr int VEXtupleSize<VEXmat2<VEX_64>>() { return 4; }
266 template <> inline constexpr int VEXtupleSize<VEXmat3<VEX_32>>() { return 9; }
267 template <> inline constexpr int VEXtupleSize<VEXmat3<VEX_64>>() { return 9; }
268 template <> inline constexpr int VEXtupleSize<VEXmat4<VEX_32>>() { return 16; }
269 template <> inline constexpr int VEXtupleSize<VEXmat4<VEX_64>>() { return 16; }
270 
271 #endif
272 
VEX_Storage
Definition: VEX_Types.h:104
VEX_Type
VEX variable types.
Definition: VEX_VexTypes.h:18
VEX_API const char * VEXgetBaseType(VEX_BaseType type)
VEX_API const char * VEXgetUIHint(VEX_UIHint type)
VEX_API FS_DiskCache & VEXcompileCache()
#define VEX_TYPERESOLVE_CASE(VexType, CPPType)
Definition: VEX_Types.h:43
VEX_API bool VEXisString(VEX_Type type)
#define VEX_API
Definition: VEX_API.h:13
VEX_API const char * VEXgetStorage(VEX_Storage type)
void read(T &in, bool &v)
Definition: ImfXdr.h:611
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
bool isWrite() const
Definition: VEX_Types.h:158
SYS_FORCE_INLINE constexpr bool VEXisPrecisioned(VEX_Type type)
Definition: VEX_Types.h:200
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
VEX_API const char * VEXgetShortStorage(VEX_Storage type)
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
VEX_API bool VEXisFloat(VEX_Type type)
typename VEX_PrecisionResolver< P >::mat4_type VEXmat4
Definition: VEX_PodTypes.h:74
VEX_BaseType
Definition: VEX_Types.h:116
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GLuint GLsizei GLsizei GLchar * label
Definition: glew.h:8986
typename VEX_PrecisionResolver< P >::mat2_type VEXmat2
Definition: VEX_PodTypes.h:72
VEX_API const char * VEXgetType(VEX_Type type)
bool isRead() const
Definition: VEX_Types.h:157
typename VEX_PrecisionResolver< P >::vec2_type VEXvec2
Definition: VEX_PodTypes.h:69
VEX_API int VEXtupleSize(VEX_Type type)
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
typename VEX_PrecisionResolver< P >::vec4_type VEXvec4
Definition: VEX_PodTypes.h:71
#define SYS_UNIMPLEMENTED_TEMPLATE(T)
bool operator!=(const VEX_RWType &rhs) const
Definition: VEX_Types.h:163
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
VEX_API bool VEXisInt(VEX_Type type)
VEX_UIHint
Definition: VEX_Types.h:125
VEX_RWType(bool read, bool write)
Definition: VEX_Types.h:151
void write(T &out, bool v)
Definition: ImfXdr.h:332
void setRead(bool r=true)
Definition: VEX_Types.h:155
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73
bool operator==(const VEX_RWType &rhs) const
Definition: VEX_Types.h:160
void setWrite(bool w=true)
Definition: VEX_Types.h:156
VEX_API char VEXgetMangleType(VEX_Type type)
const char * asString() const
Definition: VEX_Types.h:166