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