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