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