HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_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: GA_Types.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_Types__
14 #define __GA_Types__
15 
16 #include "GA_API.h"
17 #include <UT/UT_Assert.h>
18 #include <UT/UT_ValArray.h>
19 #include <SYS/SYS_Math.h>
20 #include <SYS/SYS_Types.h>
21 
22 
23 // -------------------------------------------------------------
24 // GA Enums/Defines
25 // -------------------------------------------------------------
26 /// The GA_AttributeOwner enum is used to differentiate between the different
27 /// types of attribute arrays stored in a GA_Detail. The different classes
28 /// represent
29 /// -# unique point attribute data (one per vertex on a primitive)
30 /// -# shared point attribute data (attributes shared multiple vertices)
31 /// -# per-primitive attribute data (one per primitive)
32 /// -# attribute data stored on the detail itself (single value)
34 {
35  GA_ATTRIB_VERTEX, // Unique vertex data
36  GA_ATTRIB_POINT, // Shared vertex data
37  GA_ATTRIB_PRIMITIVE, // Primitive attribute data
38  GA_ATTRIB_GLOBAL, // Global data
39 
40  GA_ATTRIB_OWNER_N, // Number of GA_AttributeOwner enums
41 
42  GA_ATTRIB_DETAIL = GA_ATTRIB_GLOBAL,// Detail data, same as global
43  GA_ATTRIB_INVALID = -1 // Not a valid attribute owner
44 };
45 GA_API size_t format(char *buffer, size_t buffer_size, const GA_AttributeOwner &v);
46 
47 /// Attributes (and other data) may be stored with different precision and
48 /// storage types.
50 {
51  GA_STORE_INVALID=-1, // Invalid storage
52  GA_STORE_BOOL, // Bool storage (bit-array)
53  GA_STORE_UINT8, // 8-bit unsigned integer
54  GA_STORE_INT8, // 8-bit signed integer
55  GA_STORE_INT16, // 16-bit integer
56  GA_STORE_INT32, // 32-bit integer
57  GA_STORE_INT64, // 64-bit integer
58  GA_STORE_REAL16, // 16-bit real
59  GA_STORE_REAL32, // 32-bit real
60  GA_STORE_REAL64, // 64-bit real
61  GA_STORE_STRING, // ASCII string data
62  GA_STORE_DICT, // Option Dictionaries
63  // GA_STORE_UTF8, // Future?
64  // GA_STORE_UTF16, // Future?
65  // GA_STORE_UTF32, // Future?
66 };
67 GA_API size_t format(char *buffer, size_t buffer_size, const GA_Storage &v);
68 
69 /// Often one does not care about the precision. In this case
70 /// the storage class gives a good idea which AIFs will be supported.
72 {
73  GA_STORECLASS_INVALID = -1, // Invalid storage
74  GA_STORECLASS_INT, // Any integer type
75  GA_STORECLASS_REAL, // Any real type
80 };
81 GA_API size_t format(char *buffer, size_t buffer_size, const GA_StorageClass &v);
82 
83 /// If one only cares about precision, this can be used.
84 /// Note that 8-bit reals do not exist so will instead refer
85 /// to 16-bit.
87 {
88  GA_PRECISION_INVALID = -1, // Storage with no precision, String
94 };
95 GA_API size_t format(char *buffer, size_t buffer_size, const GA_Precision &v);
96 
97 /// Type qualifiers on attributes. These qualifiers can help to interpret the
98 /// data associated with an attribute, but are not required.
100 {
101  /// Data has no numeric representation
103  /// Data represents a position in space. Token "point"
105  /// Data represents a position and homogeneous coordinate. The position is
106  /// stored in non-homogeneous space (i.e. the w coordinate is not
107  /// multiplied through). Token "hpoint"
109  /// Data represents a direction vector. Token "vector"
111  /// Data represents a normal vector. Token "normal"
113  /// Data represents a color. Token "color"
115  /// Data represents a transform matrix. Token "matrix"
117  /// Data represents a quaternion. Token "quaternion"
119  /// Data represents an index-pair. Token "indexpair"
121 
122  /// When a numeric attribute is created with integer storage, the attribute
123  /// will be tagged as a non-arithmetic integer. This means that
124  /// mathematical operations will not typically be performed (i.e. integer
125  /// values will not be averaged). This works well for most cases of
126  /// integers under Houdini.
128  /// Arithmetic integers will be modified under arithmetic operations.
129  /// Their values will be averaged etc.
130  /// @note This is not the default behaviour for numeric attributes
132 
133  /// Data represents a coordinate in texture space, a.k.a. uv/uvw,
134  /// but not a primitive uv/uvw.
136 };
137 GA_API size_t format(char *buffer, size_t buffer_size, const GA_TypeInfo &v);
138 
139 /// Scope qualifiers on attributes. Each valid scope has its own namespace,
140 /// along with other consequences.
142 {
143  /// Data has no numeric representation
145  /// Standard user attribute level
146  // GA_OPTION_EXPORT_ON_SAVE/MERGE defaults to true
148  // Internal attribute level
149  // GA_OPTION_EXPORT_ON_SAVE/MERGE defaults to false
151  // Group attribute level
152  // GA_OPTION_EXPORT_ON_SAVE/MERGE defaults to false,
153  // because GA_Group saves/merges it, not GA_Attribute.
155 };
156 GA_API size_t format(char *buffer, size_t buffer_size, const GA_AttributeScope &v);
157 
158 /// An ordinal enum for the different types of groups in GA
160 {
168 };
169 GA_API size_t format(char *buffer, size_t buffer_size, const GA_GroupType &v);
170 
171 /// Currently SOP_Node::parseAllGroups takes a mask of different types of
172 /// groups. This enum allows group types to be packed into a bit field.
174 {
182 };
183 
184 // Maximum order for NURBs/Bezier bases
185 #define GA_MAX_ORDER 11
186 
187 // Types of knot spacing for NURBs operations
189 {
192 };
193 
194 // Basis parametrization types
196 {
201 };
202 
203 /// Strategies that may be used for attribute data IDs, usually when merging
204 /// or copying attributes.
205 ///
206 /// @note Most functions with a parameter of this type typically treat it as
207 /// a hint, and may ignore it when the requested strategy is not appropriate.
209 {
210  /// The default strategy, where the caller does not have to explicitly
211  /// worry about attribute data IDs.
213 
214  /// Attributes should inherit the data IDs from their corresponding source
215  /// attribute. The caller will typically call GA_Attribute::bumpDataId()
216  /// on any attributes that they later modify.
218 };
219 
220 /// Attributes may paritition their data in pages of GA_PAGE_SIZE offsets.
221 #define GA_PAGE_BITS 10
222 #define GA_PAGE_SIZE (1 << GA_PAGE_BITS)
223 #define GA_PAGE_MASK (GA_PAGE_SIZE - 1)
224 #define GA_DEFRAGMENT_OCCUPANCY 1.00
225 
226 // -------------------------------------------------------------
227 // GA Types
228 // When indexing points, vertices or primitives, use
229 // GA_Index (ordered) or GA_Offset (data offset)
230 // -------------------------------------------------------------
231 
232 /// Defines the bit width for index and offset types in GA
233 typedef exint GA_Size;
234 
235 /// Define the strictness of GA_Offset/GA_Index
236 #if !defined(GA_STRICT_TYPES) && UT_ASSERT_LEVEL > 2
237  #define GA_STRICT_TYPES 0
238 #endif
239 
240 #if defined(GA_STRICT_TYPES)
241 
242 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
243 #define GA_MAGIC_BAD_VALUE 0x7BADF00D7F00DBAD
244 #endif
245 
246 #if (UT_ASSERT_LEVEL < UT_ASSERT_LEVEL_NORMAL)
247 #include <SYS/SYS_TypeDecorate.h>
248 #endif
249 
250 #include <SYS/SYS_Compiler.h>
251 #include <SYS/SYS_Hash.h>
252 #include <SYS/SYS_TypeTraits.h>
253 #include <ostream>
254 
255 #if defined(MBSD)
256  #define GA_DEFINE_ORDINAL_METHODS_EXTRA \
257  size_t operator*(size_t v) const { return myVal * v; } \
258  friend size_t operator*(size_t v, const ThisType &a) { return v * a.myVal; }
259 #else
260  #define GA_DEFINE_ORDINAL_METHODS_EXTRA
261 #endif
262 
263 
264 #define GA_DEFINE_ORDINAL_METHODS \
265  GA_DEFINE_ORDINAL_METHODS_EXTRA \
266  bool operator==(const ThisType &that) const { return (myVal == that.myVal); } \
267  bool operator!=(const ThisType &that) const { return (myVal != that.myVal); } \
268  bool operator<(const ThisType &that) const { return (myVal < that.myVal); } \
269  bool operator<=(const ThisType &that) const { return (myVal <= that.myVal); } \
270  bool operator>(const ThisType &that) const { return (myVal > that.myVal); } \
271  bool operator>=(const ThisType &that) const { return (myVal >= that.myVal); } \
272  exint operator&(exint v) const { return myVal & v; } \
273  exint operator&(int v) const { return myVal & v; } \
274  exint operator&(uint v) const { return myVal & v; } \
275  exint operator>>(exint v) const { return myVal >> v; } \
276  exint operator>>(int v) const { return myVal >> v; } \
277  exint operator>>(uint v) const { return myVal >> v; } \
278  exint operator*(exint v) const { return myVal * v; } \
279  exint operator*(int v) const { return myVal * v; } \
280  exint operator*(uint v) const { return myVal * v; } \
281  exint operator*(uint64 v) const { return exint(myVal * v); } \
282  ThisType operator+(const ThisType &that) const { return ThisType(myVal + that.myVal); } \
283  ThisType operator+(exint v) const { return ThisType(myVal + v); } \
284  ThisType operator+(uint64 v) const { return ThisType(myVal + v); } \
285  ThisType operator+(int v) const { return ThisType(myVal + v); } \
286  ThisType operator+(uint v) const { return ThisType(myVal + v); } \
287  friend ThisType operator+(exint v, const ThisType &a) { return ThisType(a.myVal + v); } \
288  friend ThisType operator+(uint64 v, const ThisType &a) { return ThisType(a.myVal + v); } \
289  friend ThisType operator+(int v, const ThisType &a) { return ThisType(a.myVal + v); } \
290  friend ThisType operator+(uint v, const ThisType &a) { return ThisType(a.myVal + v); } \
291  friend exint operator*(exint v, const ThisType &a) { return ThisType(a.myVal * v); } \
292  friend exint operator*(uint64 v, const ThisType &a) { return ThisType(a.myVal * v); } \
293  friend exint operator*(int v, const ThisType &a) { return ThisType(a.myVal * v); } \
294  friend exint operator*(uint v, const ThisType &a) { return ThisType(a.myVal * v); } \
295  /* NOTE: ThisType-ThisType must return something that can be divided \
296  by (unsigned int)2 in order to support TBB blocked ranges.*/ \
297  exint operator/(uint v) const { return myVal/v; } \
298  exint operator/(int v) const { return myVal/v; } \
299  exint operator/(uint64 v) const { return myVal/v; } \
300  exint operator/(int64 v) const { return myVal/v; } \
301  ThisType operator-(const ThisType &that) const { return ThisType(myVal - that.myVal); } \
302  ThisType operator-(exint v) const { return ThisType(myVal - v); } \
303  ThisType operator-(uint64 v) const { return ThisType(myVal - v); } \
304  ThisType operator-(int v) const { return ThisType(myVal - v); } \
305  ThisType operator-(uint v) const { return ThisType(myVal - v); } \
306  ThisType operator+=(const ThisType &that) { myVal += that.myVal; return *this; } \
307  ThisType operator+=(exint v) { myVal += v; return *this; } \
308  ThisType operator+=(uint64 v){ myVal += v; return *this; } \
309  ThisType operator+=(int v) { myVal += v; return *this; } \
310  ThisType operator+=(uint v) { myVal += v; return *this; } \
311  ThisType operator-=(const ThisType &that) { myVal -= that.myVal; return *this; } \
312  ThisType operator-=(exint v) { myVal -= v; return *this; } \
313  ThisType operator-=(uint64 v){ myVal -= v; return *this; } \
314  ThisType operator-=(int v) { myVal -= v; return *this; } \
315  ThisType operator-=(uint v) { myVal -= v; return *this; } \
316  ThisType & operator++() { ++myVal; return *this; } \
317  ThisType operator++(int) { return ThisType(myVal++); } \
318  ThisType & operator--() { --myVal; return *this; } \
319  ThisType operator--(int) { return ThisType(myVal--); } \
320  ThisType operator-() { return ThisType(-myVal); } \
321  friend std::ostream &operator<< (std::ostream &stream, const ThisType &a) { return stream << a.myVal; } \
322  friend ThisType SYSmax(const ThisType &a, const ThisType &b) \
323  { return ThisType(SYSmax(a.myVal, b.myVal)); } \
324  friend ThisType SYSmin(const ThisType &a, const ThisType &b) \
325  { return ThisType(SYSmin(a.myVal, b.myVal)); } \
326  friend ThisType SYSclamp(const ThisType &a, const ThisType &b, const ThisType &c) \
327  { return ThisType(SYSclamp(a.myVal, b.myVal, c.myVal)); } \
328  friend ThisType UTbumpAlloc(const ThisType &a) \
329  { return ThisType(UTbumpAlloc(a.myVal)); } \
330 
331  /**/
332 
333 template <typename TAG, typename BASE_TYPE>
334 class GA_API_TMPL GA_OrdinalType
335 {
336 private:
337  typedef GA_OrdinalType<TAG, BASE_TYPE> ThisType;
338 
339 public:
340  GA_OrdinalType()
341 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
342  : myVal(BASE_TYPE(GA_MAGIC_BAD_VALUE))
343 #endif
344  {}
345  explicit GA_OrdinalType(const BASE_TYPE &val) : myVal(val) { }
346 
347  operator BASE_TYPE() const { return myVal; }
348 
349  GA_DEFINE_ORDINAL_METHODS
350 
351 private:
352  BASE_TYPE myVal;
353 };
354 
355 class GA_Index;
356 
357 /// GA_Offset defines an offset into the attribute table of a GA_IndexMap.
358 /// Properties:
359 /// - Not allowed to be converted from a GA_Index
360 /// - Not implicitly convertible from a GA_Size
362 {
363  typedef GA_Offset ThisType;
364 
365 public:
366  GA_Offset()
367 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
368  : myVal(GA_MAGIC_BAD_VALUE)
369 #endif
370  {}
371  explicit constexpr GA_Offset(GA_Size val) : myVal(val) { }
372 
373  operator int64() const { return myVal; }
374  operator uint64() const { return myVal; }
375 
376  // NOTE: These should generally be avoided, but are mostly here
377  // for templated code that over-instantiates for bogus type
378  // conversions.
379  operator int32() const { return myVal; }
380  operator uint32() const { return myVal; }
381  operator int16() const { return myVal; }
382  operator uint16() const { return myVal; }
383  operator int8() const { return myVal; }
384  operator uint8() const { return myVal; }
385 #if defined(MBSD)
386  // NOTE: These ones are because on Mac GCC, long and size_t are treated as
387  // types different from int64 and uint64 somehow (they are both
388  // 64-bit integers).
389  operator long() const { return myVal; }
390  operator unsigned long() const { return myVal; }
391 #endif
392 
393  GA_DEFINE_ORDINAL_METHODS
394 
395 private:
396  GA_Offset(const GA_Index &v); // DISALLOW
397 
398  /// Disallow boolean operations, because they're almost guaranteed
399  /// to be porting errors checking if a pointer is NULL or non-NULL
400  /// instead of checking whether the offset is zero.
401  SYS_SAFE_BOOL operator bool() const;
402 
403  /// Disallow comparison with integers, for example, the
404  /// "if (ptoff==0)" case, since it's most likely a porting error.
405  bool operator==(exint v) const;
406  bool operator==(uint64 v) const;
407  bool operator==(int v) const;
408  bool operator==(uint v) const;
409  bool operator!=(exint v) const;
410  bool operator!=(uint64 v) const;
411  bool operator!=(int v) const;
412  bool operator!=(uint v) const;
413 
414  GA_Size myVal;
415 };
417 
419 {
420  return SYShash(GA_Size(off));
421 }
422 
423 /// GA_Index defines an ordered index of a GA_IndexMap.
424 /// Properties:
425 /// - Not allowed to be converted from a GA_Offset
426 /// - Implicitly convertible from and to a GA_Size
427 class GA_API_TMPL GA_Index
428 {
429 private:
430  typedef GA_Index ThisType;
431 
432 public:
433  GA_Index()
434 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
435  : myVal(GA_MAGIC_BAD_VALUE)
436 #endif
437  {}
438  GA_Index(const GA_Size &val) : myVal(val) { }
439 
440  operator int64() const { return myVal; }
441  operator uint64() const { return myVal; }
442 
443  // NOTE: These should generally be avoided, but are mostly here
444  // for templated code that over-instantiates for bogus type
445  // conversions.
446  operator int32() const { return myVal; }
447  operator uint32() const { return myVal; }
448  operator int16() const { return myVal; }
449  operator uint16() const { return myVal; }
450  operator int8() const { return myVal; }
451  operator uint8() const { return myVal; }
452 #if defined(MBSD)
453  // NOTE: This one is because on Mac GCC, long is treated as a type
454  // different from int64 somehow (they are both 64-bit integers).
455  operator long() const { return myVal; }
456  operator unsigned long() const { return myVal; }
457 #endif
458 
459  GA_DEFINE_ORDINAL_METHODS
460 
461  // NOTE: These methods are to avoid having to change the ton of code that
462  // uses ints, etc, as interchangeable with GA_Index
463  // Equality comparisons with integers were re-allowed, since most porting
464  // errors would involve GA_Offset, not GA_Index, and not being able to compare
465  // getNumPoints() with 0 is counterintuitive.
466  bool operator< (exint v) const { return (myVal < v); }
467  bool operator<=(exint v) const { return (myVal <= v); }
468  bool operator> (exint v) const { return (myVal > v); }
469  bool operator>=(exint v) const { return (myVal >= v); }
470  bool operator==(exint v) const { return (myVal == v); }
471  bool operator!=(exint v) const { return (myVal != v); }
472  bool operator< (uint64 v) const { return (myVal < v); }
473  bool operator<=(uint64 v) const { return (myVal <= v); }
474  bool operator> (uint64 v) const { return (myVal > v); }
475  bool operator>=(uint64 v) const { return (myVal >= v); }
476  bool operator==(uint64 v) const { return (myVal == v); }
477  bool operator!=(uint64 v) const { return (myVal != v); }
478  bool operator< (int v) const { return (myVal < v); }
479  bool operator<=(int v) const { return (myVal <= v); }
480  bool operator> (int v) const { return (myVal > v); }
481  bool operator>=(int v) const { return (myVal >= v); }
482  bool operator==(int v) const { return (myVal == v); }
483  bool operator!=(int v) const { return (myVal != v); }
484  bool operator< (uint v) const { return (myVal < v); }
485  bool operator<=(uint v) const { return (myVal <= v); }
486  bool operator> (uint v) const { return (myVal > v); }
487  bool operator>=(uint v) const { return (myVal >= v); }
488  bool operator==(uint v) const { return (myVal == v); }
489  bool operator!=(uint v) const { return (myVal != v); }
490 #if defined(MBSD)
491  // NOTE: This one is because on Mac GCC, long is treated as a type
492  // different from int64 somehow (they are both 64-bit integers).
493  bool operator< (unsigned long v) const { return (myVal < v); }
494  bool operator<=(unsigned long v) const { return (myVal <= v); }
495  bool operator> (unsigned long v) const { return (myVal > v); }
496  bool operator>=(unsigned long v) const { return (myVal >= v); }
497  bool operator==(unsigned long v) const { return (myVal == v); }
498  bool operator!=(unsigned long v) const { return (myVal != v); }
499 #endif
500 
501  friend bool operator<( exint v, const GA_Index &a) { return (v < a.myVal); }
502  friend bool operator<=(exint v, const GA_Index &a) { return (v <= a.myVal); }
503  friend bool operator>( exint v, const GA_Index &a) { return (v > a.myVal); }
504  friend bool operator>=(exint v, const GA_Index &a) { return (v >= a.myVal); }
505  friend bool operator==(exint v, const GA_Index &a) { return (v == a.myVal); }
506  friend bool operator!=(exint v, const GA_Index &a) { return (v != a.myVal); }
507  friend bool operator<( uint64 v, const GA_Index &a) { return (v < a.myVal); }
508  friend bool operator<=(uint64 v, const GA_Index &a) { return (v <= a.myVal); }
509  friend bool operator>( uint64 v, const GA_Index &a) { return (v > a.myVal); }
510  friend bool operator>=(uint64 v, const GA_Index &a) { return (v >= a.myVal); }
511  friend bool operator==(uint64 v, const GA_Index &a) { return (v == a.myVal); }
512  friend bool operator!=(uint64 v, const GA_Index &a) { return (v != a.myVal); }
513  friend bool operator<( int v, const GA_Index &a) { return (v < a.myVal); }
514  friend bool operator<=(int v, const GA_Index &a) { return (v <= a.myVal); }
515  friend bool operator>( int v, const GA_Index &a) { return (v > a.myVal); }
516  friend bool operator>=(int v, const GA_Index &a) { return (v >= a.myVal); }
517  friend bool operator==(int v, const GA_Index &a) { return (v == a.myVal); }
518  friend bool operator!=(int v, const GA_Index &a) { return (v != a.myVal); }
519  friend bool operator<( uint v, const GA_Index &a) { return (v < a.myVal); }
520  friend bool operator<=(uint v, const GA_Index &a) { return (v <= a.myVal); }
521  friend bool operator>( uint v, const GA_Index &a) { return (v > a.myVal); }
522  friend bool operator>=(uint v, const GA_Index &a) { return (v >= a.myVal); }
523  friend bool operator==(uint v, const GA_Index &a) { return (v == a.myVal); }
524  friend bool operator!=(uint v, const GA_Index &a) { return (v != a.myVal); }
525 #if defined(MBSD)
526  // NOTE: This one is because on Mac GCC, long is treated as a type
527  // different from int64 somehow (they are both 64-bit integers).
528  friend bool operator<( unsigned long v, const GA_Index &a) { return (v < a.myVal); }
529  friend bool operator<=(unsigned long v, const GA_Index &a) { return (v <= a.myVal); }
530  friend bool operator>( unsigned long v, const GA_Index &a) { return (v > a.myVal); }
531  friend bool operator>=(unsigned long v, const GA_Index &a) { return (v >= a.myVal); }
532  friend bool operator==(unsigned long v, const GA_Index &a) { return (v == a.myVal); }
533  friend bool operator!=(unsigned long v, const GA_Index &a) { return (v != a.myVal); }
534 #endif
535 
536  /// Boolean operations were re-allowed for if (getNumPoints()), because
537  /// most porting errors would involve checking GA_Offset, not GA_Index.
538  SYS_SAFE_BOOL operator bool() const { return myVal != 0; }
539 
540 private:
541  GA_Index(const GA_Offset &v); // DISALLOW
542 
543  GA_Size myVal;
544 };
546 
548 {
549  return SYShash(GA_Size(idx));
550 }
551 
552 #undef GA_DEFINE_ORDINAL_BINARY_OPS
553 #undef GA_DEFINE_ORDINAL_METHODS
554 
555 
556 class GA_PageNumTag {};
557 typedef GA_OrdinalType<GA_PageNumTag, GA_Size> GA_PageNum;
559 
560 
561 class GA_PageOffTag {};
562 typedef GA_OrdinalType<GA_PageOffTag, GA_Size> GA_PageOff;
564 
565 inline bool GAisValid(GA_Offset v)
566 {
567  UT_ASSERT(v != GA_Offset(GA_MAGIC_BAD_VALUE));
568  return v >= GA_Offset(0);
569 }
570 inline bool GAisValid(GA_Index v)
571 {
572  UT_ASSERT(v != GA_Index(GA_MAGIC_BAD_VALUE));
573  return v >= GA_Index(0);
574 }
575 
576 namespace UT {
577 template<typename T>
578 struct DefaultClearer;
579 
580 template<>
581 struct DefaultClearer<GA_Offset>
582 {
583  static void clear(GA_Offset &v)
585  static bool isClear(GA_Offset v)
586  { return v == GA_Offset(std::numeric_limits<exint>::min()); }
587  static void clearConstruct(GA_Offset *p) { clear(*p); }
588 
589  static const bool clearNeedsDestruction = false;
590 };
591 
592 template<>
593 struct DefaultClearer<GA_Index>
594 {
595  static void clear(GA_Index &v)
597  static bool isClear(GA_Index v)
598  { return v == GA_Index(std::numeric_limits<exint>::min()); }
599  static void clearConstruct(GA_Index *p) { clear(*p); }
600 
601  static const bool clearNeedsDestruction = false;
602 };
603 }
604 
605 namespace std {
606 template<>
607 struct hash<GA_Offset>
608 {
609  size_t operator()(GA_Offset v)
610  { return std::hash<exint>()((exint)v); }
611 };
612 template<>
613 struct hash<GA_Index>
614 {
615  size_t operator()(GA_Index v)
616  { return std::hash<exint>()((exint)v); }
617 };
618 }
619 
620 GA_API size_t format(char *buf, size_t bufsize, const GA_Index &v);
621 GA_API size_t format(char *buf, size_t bufsize, const GA_Offset &v);
622 
623 #else
624 
625 /// GA_Index is a contiguous index into an element in a GA_Detail structure.
626 /// Since the list of elements can contain gaps, the index should be translated
627 /// into a GA_Offset prior to lookup. The index remains constant if the element
628 /// list is defragmented, but will be invalid if an element, prior to a given
629 /// index, is inserted or deleted.
630 /// \sa GA_Detail::pointOffset, GA_Detail::pointIndex,
631 /// \sa GA_Detail::primitiveOffset, GA_Detail::primitiveIndex
632 /// \sa GA_Detail::vertexOffset, GA_Detail::vertexIndex
634 
635 /// GA_Offset is a, possibly, non-contiguous offset to an element in a
636 /// GA_Detail structure. GA_Offsets remain constant even if an element prior to
637 /// it is deleted, but will be invalidated if an element is inserted prior to
638 /// it, or if the element list is defragmented.
640 
641 
644 
645 #endif
646 
647 inline bool GAisValid(GA_Size v) {
648 #if defined(GA_STRICT_TYPES)
649  UT_ASSERT(v != GA_Size(GA_MAGIC_BAD_VALUE));
650 #endif
651  return v >= 0;
652 }
653 
654 inline GA_PageNum GAgetPageNum(GA_Offset v)
655 {
656  return GA_PageNum(v >> GA_PAGE_BITS);
657 }
658 inline GA_PageOff GAgetPageOff(GA_Offset v)
659 {
660  return GA_PageOff(v & GA_PAGE_MASK);
661 }
662 inline bool GAisFullPage(GA_Offset start, GA_Offset end)
663 {
664  return (GAgetPageOff(start) == 0 &&
665  GAgetPageOff(end) == 0 &&
666  (GAgetPageNum(start) == GAgetPageNum(end)-1));
667 }
668 
669 inline GA_Offset GAgetPageBoundary(const GA_Offset &start,
670  const GA_Offset &end)
671 {
672  return GA_Offset(SYSmin(GA_Size(end), GA_Size(start) - GA_Size(GAgetPageOff(start)) + GA_PAGE_SIZE));
673 }
674 
675 #define GA_INVALID_INDEX GA_Index(-1)
676 #define GA_INVALID_OFFSET GA_Offset(-1)
677 
678 /// Details are always at index and offset zero in their own detail index map.
679 #define GA_DETAIL_INDEX GA_Index(0)
680 #define GA_DETAIL_OFFSET GA_Offset(0)
681 
684 
685 typedef int64 GA_DataId;
686 #define GA_INVALID_DATAID GA_DataId(-1)
687 
688 
689 /// @{
690 /// At the current time, intrinsic handles are an integer.
691 /// This may change in the future.
692 typedef int GA_LocalIntrinsic;
693 typedef int GA_GlobalIntrinsic;
694 #define GA_INVALID_INTRINSIC_HANDLE -1
695 static inline bool GAisValidGlobalIntrinsic(GA_GlobalIntrinsic h)
696  { return h >= 0; }
697 static inline bool GAisValidLocalIntrinsic(GA_LocalIntrinsic h)
698  { return h >= 0; }
699 /// @}
700 
701 // -------------------------------------------------------------
702 // Functions to map storage enums to tokens.
703 // -------------------------------------------------------------
704 /// Lookup the size in bytes of a storage type (inaccurate for bool)
705 GA_API extern unsigned GAsizeof(GA_Storage store);
706 
707 /// Compare precision of GA_Storage types. The function will return:
708 /// -2 invalid comparison (i.e. comparing a string to a float)
709 /// -1 if a is less precise than b
710 /// 0 if a and be have the same precision
711 /// 1 if a is more precise than b
713 
714 /// Return the precision associated with the storage.
716 /// Lookup the precision name from the precision
717 GA_API extern const char *GAprecision(GA_Precision precision);
718 /// Lookup the precision type from the precision name
719 GA_API extern GA_Precision GAprecision(const char *precision);
720 /// Returns the nominal bits of provided precision, 0 for invalid.
722 
723 /// Lookup the owner name from the owner type
724 GA_API extern const char *GAowner(GA_AttributeOwner owner);
725 /// Lookup the owner type from the owner name
726 GA_API extern GA_AttributeOwner GAowner(const char *owner);
727 
728 /// Lookup the scope name from the scope type
729 GA_API extern const char *GAscope(GA_AttributeScope scope);
730 /// Lookup the scope type from the scope name
731 GA_API extern GA_AttributeScope GAscope(const char *scope);
732 
733 /// Lookup the storage name from the storage type
734 GA_API extern const char *GAstorage(GA_Storage store);
735 /// Lookup the storage type from the storage name
736 GA_API extern GA_Storage GAstorage(const char *store);
737 
738 /// Lookup the storage label (descriptive name) from the storage type
739 GA_API extern const char *GAstorageLabel(GA_Storage store);
740 /// Lookup the storage type from the storage label
741 GA_API extern GA_Storage GAstorageLabel(const char *store);
742 
743 
744 
745 /// Lookup the storage name from the storage type
746 GA_API extern const char *GAstorageClass(GA_StorageClass store);
747 /// Lookup the intrinsic storage type from the storage name
748 GA_API extern GA_StorageClass GAstorageClass(const char *store);
749 
750 /// Lookup the type-info name from the type-info type
751 GA_API extern const char *GAtypeinfo(GA_TypeInfo type);
752 /// Lookup the type-info type from the type-info name
753 GA_API extern GA_TypeInfo GAtypeinfo(const char *type);
754 
755 /// Lookup the type-info label (descriptive name) from the type-info type
756 GA_API extern const char *GAtypeinfoLabel(GA_TypeInfo type);
757 /// Lookup the type-info type from the type-info label (descriptive name)
758 GA_API extern GA_TypeInfo GAtypeinfoLabel(const char *type);
759 
760 /// Lookup the owner name from the owner type
761 GA_API extern const char *GAgroupType(GA_GroupType owner);
762 /// Lookup the owner type from the owner name
763 GA_API extern GA_GroupType GAgroupType(const char *owner);
764 
765 
766 /// Convenience method to determine whether an integer represents a valid
767 /// storage type.
768 static inline bool GAisStorageType(int s)
769  {
770  return s >= GA_STORE_BOOL && s <= GA_STORE_STRING;
771  }
772 
773 /// Convenience method to determine whether storage is real valued
774 static inline bool GAisFloatStorage(GA_Storage s)
775  {
776  return s == GA_STORE_REAL16 ||
777  s == GA_STORE_REAL32 ||
778  s == GA_STORE_REAL64;
779  }
780 
781 /// Convenience method to determine whether storage is integer valued
782 static inline bool GAisIntStorage(GA_Storage s)
783  {
784  return
785  s == GA_STORE_UINT8 ||
786  s == GA_STORE_INT8 ||
787  s == GA_STORE_INT16 ||
788  s == GA_STORE_INT32 ||
789  s == GA_STORE_INT64;
790  }
791 
792 /// Convenience method to determine whether storage is numeric (real/integer)
793 static inline bool GAisNumericStorage(GA_Storage s)
794  {
795  return GAisFloatStorage(s) || GAisIntStorage(s);
796  }
797 
798 /// Convenience method to determine if type info is a transforming type
799 static inline bool GAisTransformingType(GA_TypeInfo t)
800  {
801  return
802  t == GA_TYPE_VECTOR ||
803  t == GA_TYPE_NORMAL ||
804  t == GA_TYPE_POINT ||
805  t == GA_TYPE_HPOINT ||
806  t == GA_TYPE_TRANSFORM ||
807  t == GA_TYPE_QUATERNION;
808  }
809 
811 {
812  switch (s)
813  {
814  case GA_STORE_INVALID:
815  return GA_STORECLASS_INVALID;
816  case GA_STORE_BOOL:
817  case GA_STORE_UINT8:
818  case GA_STORE_INT8:
819  case GA_STORE_INT16:
820  case GA_STORE_INT32:
821  case GA_STORE_INT64:
822  return GA_STORECLASS_INT;
823  case GA_STORE_REAL16:
824  case GA_STORE_REAL32:
825  case GA_STORE_REAL64:
826  return GA_STORECLASS_REAL;
827  case GA_STORE_STRING:
828  return GA_STORECLASS_STRING;
829  case GA_STORE_DICT:
830  return GA_STORECLASS_DICT;
831  }
832 
833  return GA_STORECLASS_OTHER;
834 }
835 
836 static inline GA_Storage GAgetDefaultStorage(GA_StorageClass s)
837 {
838  switch (s)
839  {
840  case GA_STORECLASS_INT:
841  return GA_STORE_INT32;
842  case GA_STORECLASS_REAL:
843  return GA_STORE_REAL32;
845  return GA_STORE_STRING;
846  case GA_STORECLASS_DICT:
847  return GA_STORE_DICT;
848  default:
849  // There's no default storage for this storage class
850  return GA_STORE_INVALID;
851  }
852 }
853 
854 static inline GA_Storage GAgetDefaultStorage(GA_StorageClass s, GA_Precision prec)
855 {
856  switch (s)
857  {
858  case GA_STORECLASS_INT:
859  switch (prec)
860  {
862  break;
863  case GA_PRECISION_1:
864  return GA_STORE_BOOL;
865  case GA_PRECISION_8:
866  return GA_STORE_UINT8;
867  case GA_PRECISION_16:
868  return GA_STORE_INT16;
869  case GA_PRECISION_32:
870  return GA_STORE_INT32;
871  case GA_PRECISION_64:
872  return GA_STORE_INT64;
873  }
874  return GA_STORE_INT32;
875  case GA_STORECLASS_REAL:
876  switch (prec)
877  {
879  break;
880  case GA_PRECISION_1:
881  case GA_PRECISION_8:
882  case GA_PRECISION_16:
883  return GA_STORE_REAL16;
884  case GA_PRECISION_32:
885  return GA_STORE_REAL32;
886  case GA_PRECISION_64:
887  return GA_STORE_REAL64;
888  }
889  return GA_STORE_REAL32;
891  return GA_STORE_STRING;
892  case GA_STORECLASS_DICT:
893  return GA_STORE_DICT;
894  default:
895  // There's no default storage for this storage class
896  return GA_STORE_INVALID;
897  }
898 }
899 #endif
GLdouble s
Definition: glew.h:1390
GA_API const char * GAtypeinfoLabel(GA_TypeInfo type)
Lookup the type-info label (descriptive name) from the type-info type.
GA_API const char * GAstorageClass(GA_StorageClass store)
Lookup the storage name from the storage type.
bool GAisFullPage(GA_Offset start, GA_Offset end)
Definition: GA_Types.h:662
Data has no numeric representation.
Definition: GA_Types.h:102
unsigned short uint16
Definition: SYS_Types.h:38
int int32
Definition: SYS_Types.h:39
GLsizei bufsize
Definition: glew.h:2581
GA_Size GA_PageOff
Definition: GA_Types.h:643
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:643
GA_StorageClass
Definition: GA_Types.h:71
GA_DataIdStrategy
Definition: GA_Types.h:208
int64 GA_DataId
Definition: GA_Types.h:685
GA_Precision
Definition: GA_Types.h:86
GLuint const GLfloat * val
Definition: glew.h:2794
bool GAisValid(GA_Size v)
Definition: GA_Types.h:647
GA_API const char * GAowner(GA_AttributeOwner owner)
Lookup the owner name from the owner type.
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
GA_API const char * GAgroupType(GA_GroupType owner)
Lookup the owner name from the owner type.
UT_ValArray< GA_Index > GA_IndexArray
Definition: GA_Types.h:682
Data represents a color. Token "color".
Definition: GA_Types.h:114
int64 exint
Definition: SYS_Types.h:125
GA_API const char * GAtypeinfo(GA_TypeInfo type)
Lookup the type-info name from the type-info type.
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
#define GA_API
Definition: GA_API.h:12
const GLdouble * v
Definition: glew.h:1391
Standard user attribute level.
Definition: GA_Types.h:147
unsigned long long uint64
Definition: SYS_Types.h:117
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:233
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
Definition: simd.h:4444
GA_PageOff GAgetPageOff(GA_Offset v)
Definition: GA_Types.h:658
GA_API size_t format(char *buffer, size_t buffer_size, const GA_AttributeOwner &v)
int GA_GlobalIntrinsic
Definition: GA_Types.h:693
GA_ParameterizationType
Definition: GA_Types.h:195
GA_API GA_Precision GAprecision(GA_Storage a)
Return the precision associated with the storage.
unsigned char uint8
Definition: SYS_Types.h:36
GA_Size GA_Offset
Definition: GA_Types.h:639
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GA_API const char * GAstorage(GA_Storage store)
Lookup the storage name from the storage type.
int GA_LocalIntrinsic
Definition: GA_Types.h:692
GA_AttributeScope
Definition: GA_Types.h:141
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
Definition: simd.h:4428
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
Definition: simd.h:4448
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
GLuint buffer
Definition: glew.h:1680
GLuint GLuint end
Definition: glew.h:1253
#define SYS_DECLARE_IS_POD(T)
Declare a type as POD.
GA_API int GAprecisionBits(GA_Precision precision)
Returns the nominal bits of provided precision, 0 for invalid.
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
long long int64
Definition: SYS_Types.h:116
Data has no numeric representation.
Definition: GA_Types.h:144
GA_API const char * GAstorageLabel(GA_Storage store)
Lookup the storage label (descriptive name) from the storage type.
#define GA_PAGE_MASK
Definition: GA_Types.h:223
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
signed char int8
Definition: SYS_Types.h:35
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
#define GA_PAGE_SIZE
Definition: GA_Types.h:222
GLuint start
Definition: glew.h:1253
GA_TypeInfo
Definition: GA_Types.h:99
GA_API int GAcomparePrecision(GA_Storage a, GA_Storage b)
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
Data represents a quaternion. Token "quaternion".
Definition: GA_Types.h:118
GA_AttributeOwner
Definition: GA_Types.h:33
GA_API const char * GAscope(GA_AttributeScope scope)
Lookup the scope name from the scope type.
short int16
Definition: SYS_Types.h:37
#define GA_API_TMPL
Definition: GA_API.h:13
Data represents a normal vector. Token "normal".
Definition: GA_Types.h:112
GA_Size GA_PageNum
Definition: GA_Types.h:642
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:159
#define GA_PAGE_BITS
Attributes may paritition their data in pages of GA_PAGE_SIZE offsets.
Definition: GA_Types.h:221
Data represents a direction vector. Token "vector".
Definition: GA_Types.h:110
unsigned int uint32
Definition: SYS_Types.h:40
Data represents a position in space. Token "point".
Definition: GA_Types.h:104
#define UT_IFNOT_ASSERT(ZZ)
Definition: UT_Assert.h:154
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
GA_GroupMaskType
Definition: GA_Types.h:173
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
#define const
Definition: zconf.h:214
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
Data represents an index-pair. Token "indexpair".
Definition: GA_Types.h:120
GA_API unsigned GAsizeof(GA_Storage store)
Lookup the size in bytes of a storage type (inaccurate for bool)
GLenum GLuint GLsizei const GLchar * buf
Definition: glew.h:2580
#define SYSmin(a, b)
Definition: SYS_Math.h:1515
size_t hash_value(const CH_ChannelRef &ref)
GA_KnotSpaceType
Definition: GA_Types.h:188
GLenum GLint GLint * precision
Definition: glew.h:3500
UT_ValArray< GA_Offset > GA_OffsetArray
Definition: GA_Types.h:683
unsigned int uint
Definition: SYS_Types.h:45
Data represents a transform matrix. Token "matrix".
Definition: GA_Types.h:116
GA_Offset GAgetPageBoundary(const GA_Offset &start, const GA_Offset &end)
Definition: GA_Types.h:669
GA_Storage
Definition: GA_Types.h:49
GLdouble GLdouble t
Definition: glew.h:1398
GA_PageNum GAgetPageNum(GA_Offset v)
Definition: GA_Types.h:654