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