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