HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_AttributeRef.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_AttributeRef.h (GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_AttributeRef__
12 #define __GA_AttributeRef__
13 
14 #include "GA_API.h"
15 #include "GA_Attribute.h"
16 #include "GA_AIFStringTuple.h"
17 #include "GA_AIFSharedDictTuple.h"
18 #include "GA_AIFSharedDictArray.h"
20 #include "GA_AIFNumericArray.h"
21 #include "GA_AIFTuple.h"
22 #include "GA_Types.h"
23 
24 #include <SYS/SYS_Compiler.h>
25 #include <UT/UT_Array.h>
26 
27 class GA_AIFCopyData;
28 class GA_AIFIndexPair;
30 class GA_AIFInterp;
31 class GA_AIFMath;
32 class GA_Attribute;
33 
34 
35 /// @brief This class provides a way to manage a reference to an attribute
36 /// permitting Write-Only access.
38 {
39 public:
40  /// Default constructor. If an attribute is passed in, the ref will be
41  /// valid. Otherwise, it will be invalid.
42  GA_WOAttributeRef(GA_Attribute *attrib = 0);
43 
44  /// Define the * operator to dereference the attribute
46  { UT_ASSERT(myAttribute); return *myAttribute; }
47  /// Define the -> operator to access the attribute
49  { return myAttribute; }
50 
51  /// Assignment operator
52  GA_WOAttributeRef &operator=(GA_Attribute *attrib);
53 
54  /// Comparison operator
55  bool operator==(const GA_WOAttributeRef &src) const
56  {
57  return
58  (myAttribute == src.myAttribute);
59  }
60  /// Comparison operator
61  bool operator!=(const GA_WOAttributeRef &src) const
62  {
63  return
64  ( myAttribute != src.myAttribute);
65  }
66 
67  /// Test to see if the attribute reference refers to a valid attribute
68  bool isValid() const
69  {
70  return myAttribute;
71  }
72 
73  /// Test to see if the attribute reference refers to a valid attribute
74  bool isInvalid() const
75  {
76  return !myAttribute;
77  }
78 
79  /// Method to clear the handle (so that it is no longer valid)
80  void clear();
81 
82  /// Set type information on the attribute
83  bool setTypeInfo(GA_TypeInfo info);
84 
85  /// Determine the storage type of the underlying attribute.
86  bool isFloat() const
87  { if (!getAIFTuple()) return false;
88  return GAisFloatStorage(getAIFTuple()->getStorage(get())); }
89  bool isInt() const
90  { if (!getAIFTuple()) return false;
91  return GAisIntStorage(getAIFTuple()->getStorage(get())); }
92  bool isString() const
93  { if (getAIFTuple()) return false;
94  if (getAIFStringTuple()) return true;
95  if (getAIFSharedStringArray()) return true;
96  return false; }
97  bool isDict() const
98  { if (getAIFSharedDictTuple()) return true;
99  if (getAIFSharedDictArray()) return true;
100  return false; }
101 
103  { if (getAIFTuple()) { return GAstorageClass(getAIFTuple()->getStorage(get())); }
104  if (getAIFStringTuple()) return GA_STORECLASS_STRING;
105  if (getAIFSharedStringArray()) return GA_STORECLASS_STRING;
106  if (getAIFNumericArray()) { return GAstorageClass(getAIFNumericArray()->getStorage(get())); }
107  if (getAIFSharedDictTuple()) return GA_STORECLASS_DICT;
108  if (getAIFSharedDictArray()) return GA_STORECLASS_DICT;
109  return GA_STORECLASS_OTHER;
110  }
111 
112  /// Tuple size of the attribute. Non-tuple types are treated
113  /// as size one.
114  int getTupleSize() const
115  { if (getAIFTuple()) { return getAIFTuple()->getTupleSize(get()); }
116  if (getAIFStringTuple()) { return getAIFStringTuple()->getTupleSize(get()); }
117  if (getAIFSharedStringArray()) { return getAIFSharedStringArray()->getTupleSize(get()); }
118  if (getAIFNumericArray()) { return getAIFNumericArray()->getTupleSize(get()); }
119  if (getAIFSharedDictTuple()) { return getAIFSharedDictTuple()->getTupleSize(get()); }
120  if (getAIFSharedDictArray()) { return getAIFSharedDictArray()->getTupleSize(get()); }
121  return 1;
122  }
123  void setTupleSize(int size)
124  { if (getAIFTuple()) { getAIFTuple()->setTupleSize(get(), size); }
125  if (getAIFStringTuple()) { getAIFStringTuple()->setTupleSize(get(), size); }
126  if (getAIFNumericArray()) { getAIFNumericArray()->setTupleSize(get(), size); }
127  if (getAIFSharedDictTuple()) { getAIFSharedDictTuple()->setTupleSize(get(), size); }
128  }
129 
130  inline GA_Attribute *get() const { return myAttribute; }
131  inline operator GA_Attribute *() const { return myAttribute; }
132  SYS_SAFE_BOOL inline operator bool() const { return myAttribute != 0; }
133  inline GA_Attribute *getAttribute() const
134  {
135  return myAttribute;
136  }
137  inline const GA_AIFCopyData *getAIFCopyData() const
138  {
139  return myCopyData;
140  }
141  inline const GA_AIFMath *getAIFMath() const
142  {
143  return myMath;
144  }
145  inline const GA_AIFInterp *getAIFInterp() const
146  {
147  return myInterp;
148  }
149  inline const GA_AIFTuple *getAIFTuple() const
150  {
151  return myTuple;
152  }
154  {
155  return myStringTuple;
156  }
158  {
159  if (get())
160  return get()->getAIFSharedDictTuple();
161  return 0;
162  }
164  {
165  if (get())
166  return get()->getAIFSharedDictArray();
167  return 0;
168  }
169  inline const GA_AIFIndexPair*getAIFIndexPair() const
170  {
171  return myIndexPair;
172  }
174  {
175  if (get())
176  return get()->getAIFNumericArray();
177  return 0;
178  }
180  {
181  if (get())
182  return get()->getAIFSharedStringArray();
183  return 0;
184  }
185 
186 
187 private:
188  GA_Attribute *myAttribute;
189  const GA_AIFMath *myMath;
190  const GA_AIFInterp *myInterp;
191  const GA_AIFCopyData *myCopyData;
192  const GA_AIFTuple *myTuple;
193  const GA_AIFStringTuple *myStringTuple;
194  const GA_AIFIndexPair *myIndexPair;
195 
196  friend class GA_ROAttributeRef;
197 };
198 
199 
200 /// @brief This class provides a way to manage a reference to an attribute
201 /// permitting Read-Write access.
203 {
204 public:
205  /// Default constructor. If an attribute is passed in, the ref will be
206  /// valid. Otherwise, it will be invalid.
207  GA_RWAttributeRef(GA_Attribute *attrib = 0);
208 
209 private:
210  /// No additional data beyond the base classes so that splicing to the
211  /// base class in pass-by-value situations isn't an issue.
212 };
213 
214 
215 /// @brief This class provides a way to manage a reference to an attribute
216 /// permitting Read-Only access.
218 {
219 public:
220  /// Default constructor. If an attribute is passed in, the ref will be
221  /// valid. Otherwise, it will be invalid.
222  GA_ROAttributeRef(const GA_Attribute *attrib = 0);
223 
224  /// Conversion constructor (implicit)
226  {
227  myAttribute = src.myAttribute;
228  myMath = src.myMath;
229  myCopyData = src.myCopyData;
230  myInterp = src.myInterp;
231  myTuple = src.myTuple;
232  myStringTuple = src.myStringTuple;
233  myIndexPair = src.myIndexPair;
234  }
235 
236  /// Define the * operator to dereference the attribute
237  const GA_Attribute &operator*() const
238  { UT_ASSERT(myAttribute); return *myAttribute; }
239  /// An -> operator to access the attribute
240  const GA_Attribute *operator->() const
241  { return myAttribute; }
242 
243  /// Assignment operators
244  GA_ROAttributeRef &operator=(const GA_Attribute *attrib);
245 
247  {
248  myAttribute = src.myAttribute;
249  myMath = src.myMath;
250  myCopyData = src.myCopyData;
251  myInterp = src.myInterp;
252  myTuple = src.myTuple;
253  myStringTuple = src.myStringTuple;
254  myIndexPair = src.myIndexPair;
255 
256  return *this;
257  }
258 
259  /// Comparison operator
260  bool operator==(const GA_ROAttributeRef &src) const
261  { return
262  (myAttribute == src.myAttribute);
263  }
264  /// Comparison operator
265  bool operator!=(const GA_ROAttributeRef &src) const
266  {
267  return
268  (myAttribute != src.myAttribute);
269  }
270 
271  /// Test to see if the attribute reference refers to a valid attribute
272  inline bool isValid() const
273  {
274  return myAttribute;
275  }
276 
277  /// Test to see if the attribute reference refers to a valid attribute
278  inline bool isInvalid() const
279  {
280  return !myAttribute;
281  }
282 
283  /// Method to clear the handle (so that it is no longer valid)
284  void clear();
285 
286  /// Get type information on the attribute, with invalid references
287  /// returning GA_TYPE_VOID.
288  GA_TypeInfo getTypeInfo() const;
289 
290  /// Determine the storage type of the underlying attribute.
291  bool isFloat() const
292  { if (!getAIFTuple()) return false;
293  return GAisFloatStorage(getAIFTuple()->getStorage(get())); }
294  bool isInt() const
295  { if (!getAIFTuple()) return false;
296  return GAisIntStorage(getAIFTuple()->getStorage(get())); }
297  bool isString() const
298  { if (getAIFTuple()) return false;
299  if (getAIFStringTuple()) return true;
300  if (getAIFSharedStringArray()) return true;
301  return false; }
302  bool isDict() const
303  { if (getAIFSharedDictTuple()) return true;
304  return false; }
305 
306 
308  {
309  if (getAIFTuple())
310  return GAstorageClass(getAIFTuple()->getStorage(get()));
311  if (getAIFStringTuple())
312  return GA_STORECLASS_STRING;
313  if (getAIFSharedStringArray())
314  return GA_STORECLASS_STRING;
315  if (getAIFSharedDictTuple())
316  return GA_STORECLASS_DICT;
317  if (getAIFNumericArray())
318  return GAstorageClass(getAIFNumericArray()->getStorage(get()));
319  return GA_STORECLASS_OTHER;
320  }
321 
322  /// Tuple size of the attribute. Non-tuple types are treated
323  /// as size one.
324  int getTupleSize() const
325  {
326  if (getAIFTuple())
327  return getAIFTuple()->getTupleSize(get());
328  if (getAIFSharedStringArray())
329  return getAIFSharedStringArray()->getTupleSize(get());
330  if (getAIFStringTuple())
331  return getAIFStringTuple()->getTupleSize(get());
332  if (getAIFNumericArray())
333  return getAIFNumericArray()->getTupleSize(get());
334  if (getAIFSharedDictTuple())
335  return getAIFSharedDictTuple()->getTupleSize(get());
336  return 1;
337  }
338 
339  inline const GA_Attribute *get() const { return myAttribute; }
340  inline operator const GA_Attribute *() const { return myAttribute; }
341  SYS_SAFE_BOOL inline operator bool() const { return myAttribute != 0; }
342  inline const GA_Attribute *getAttribute() const
343  {
344  return myAttribute;
345  }
346  inline const GA_AIFCopyData *getAIFCopyData() const
347  {
348  return myCopyData;
349  }
350  inline const GA_AIFMath *getAIFMath() const
351  {
352  return myMath;
353  }
354  inline const GA_AIFInterp *getAIFInterp() const
355  {
356  return myInterp;
357  }
358  inline const GA_AIFTuple *getAIFTuple() const
359  {
360  return myTuple;
361  }
362  inline const GA_AIFStringTuple*getAIFStringTuple() const
363  {
364  return myStringTuple;
365  }
367  {
368  if (get())
369  return get()->getAIFNumericArray();
370  return 0;
371  }
373  {
374  if (get())
375  return get()->getAIFSharedStringArray();
376  return 0;
377  }
378 
380  {
381  if (get())
382  return get()->getAIFSharedDictTuple();
383  return 0;
384  }
385 
386  /// Shared String Tuple Interface. This allows you to get integer or
387  /// string values out of the attribute.
388  const GA_AIFSharedStringTuple *getAIFSharedStringTuple() const;
389  inline const GA_AIFIndexPair*getAIFIndexPair() const
390  {
391  return myIndexPair;
392  }
393 
394  /// Look up the AIFStringTuple and evaluate the string. If there is no AIF
395  /// support, this will return a NULL pointer
396  const char *getString(GA_Offset element_index,
397  int tuple_index=0) const;
398 
399 private:
400  const GA_Attribute *myAttribute;
401  const GA_AIFMath *myMath;
402  const GA_AIFInterp *myInterp;
403  const GA_AIFCopyData *myCopyData;
404  const GA_AIFTuple *myTuple;
405  const GA_AIFStringTuple *myStringTuple;
406  const GA_AIFIndexPair *myIndexPair;
407 };
408 
409 #endif
const GA_AIFIndexPair * getAIFIndexPair() const
const GA_AIFSharedStringArray * getAIFSharedStringArray() const
void setTupleSize(int size)
GA_API const char * GAstorageClass(GA_StorageClass store)
Lookup the storage name from the storage type.
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
const GA_AIFIndexPair * getAIFIndexPair() const
const GA_AIFNumericArray * getAIFNumericArray() const
const GA_AIFSharedDictTuple * getAIFSharedDictTuple() const
Generic Attribute Interface class to access an attribute as a array.
Generic Attribute Interface class to get/set data as index pairs.
GA_Attribute * getAttribute() const
A specialization of GA_AIFDictTuple to access "shared strings".
GA_StorageClass
Definition: GA_Types.h:72
This class provides a way to manage a reference to an attribute permitting Write-Only access...
Attribute Interface class to perform numeric operations on attributes.
Definition: GA_AIFMath.h:88
bool isInvalid() const
Test to see if the attribute reference refers to a valid attribute.
const GA_AIFStringTuple * getAIFStringTuple() const
GA_Attribute & operator*() const
Define the * operator to dereference the attribute.
const GA_AIFStringTuple * getAIFStringTuple() const
#define GA_API
Definition: GA_API.h:14
bool isInt() const
const GA_AIFMath * getAIFMath() const
int getTupleSize() const
const GA_Attribute * operator->() const
An -> operator to access the attribute.
const GA_AIFTuple * getAIFTuple() const
bool isValid() const
Test to see if the attribute reference refers to a valid attribute.
bool isString() const
const GA_AIFTuple * getAIFTuple() const
GA_Size GA_Offset
Definition: GA_Types.h:641
bool isInvalid() const
Test to see if the attribute reference refers to a valid attribute.
This class provides a way to manage a reference to an attribute permitting Read-Write access...
bool isInt() const
GA_ROAttributeRef & operator=(const GA_RWAttributeRef &src)
GA_ROAttributeRef(const GA_RWAttributeRef &src)
Conversion constructor (implicit)
const GA_AIFCopyData * getAIFCopyData() const
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
This class provides a way to manage a reference to an attribute permitting Read-Only access...
const GA_AIFSharedStringArray * getAIFSharedStringArray() const
const GA_AIFCopyData * getAIFCopyData() const
int getTupleSize() const
bool isString() const
A specialization of GA_AIFStringArray to access "shared strings".
const GA_AIFNumericArray * getAIFNumericArray() const
bool isFloat() const
Determine the storage type of the underlying attribute.
const GA_Attribute & operator*() const
Define the * operator to dereference the attribute.
GA_TypeInfo
Definition: GA_Types.h:100
bool operator==(const GA_ROAttributeRef &src) const
Comparison operator.
GA_Attribute * operator->() const
Define the -> operator to access the attribute.
const GA_AIFSharedDictTuple * getAIFSharedDictTuple() const
GLsizeiptr size
Definition: glcorearb.h:664
bool isDict() const
bool isFloat() const
Determine the storage type of the underlying attribute.
bool isDict() const
A specialization of GA_AIFDictArray to access "shared strings".
A specialization of GA_AIFStringTuple to access "shared strings".
const GA_AIFSharedDictArray * getAIFSharedDictArray() const
const GA_AIFInterp * getAIFInterp() const
GA_StorageClass getStorageClass() const
GA_StorageClass getStorageClass() const
Attribute Interface class to copy attribute data.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
bool operator==(const GA_WOAttributeRef &src) const
Comparison operator.
bool operator!=(const GA_WOAttributeRef &src) const
Comparison operator.
const GA_AIFInterp * getAIFInterp() const
const GA_AIFMath * getAIFMath() const
bool isValid() const
Test to see if the attribute reference refers to a valid attribute.
Generic Attribute Interface class to work with string indices directly, rather than string values...
const GA_Attribute * getAttribute() const
GLenum src
Definition: glcorearb.h:1793
bool operator!=(const GA_ROAttributeRef &src) const
Comparison operator.