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"
18 #include "GA_AIFNumericArray.h"
19 #include "GA_AIFTuple.h"
20 #include "GA_Types.h"
21 
22 #include <SYS/SYS_Compiler.h>
23 #include <UT/UT_Array.h>
24 
25 class GA_AIFCopyData;
26 class GA_AIFIndexPair;
28 class GA_AIFInterp;
29 class GA_AIFMath;
30 class GA_Attribute;
31 
32 
33 /// @brief This class provides a way to manage a reference to an attribute
34 /// permitting Write-Only access.
36 {
37 public:
38  /// Default constructor. If an attribute is passed in, the ref will be
39  /// valid. Otherwise, it will be invalid.
40  GA_WOAttributeRef(GA_Attribute *attrib = 0);
41 
42  /// Define the * operator to dereference the attribute
44  { UT_ASSERT(myAttribute); return *myAttribute; }
45  /// Define the -> operator to access the attribute
47  { return myAttribute; }
48 
49  /// Assignment operator
50  GA_WOAttributeRef &operator=(GA_Attribute *attrib);
51 
52  /// Comparison operator
53  bool operator==(const GA_WOAttributeRef &src) const
54  {
55  return
56  (myAttribute == src.myAttribute);
57  }
58  /// Comparison operator
59  bool operator!=(const GA_WOAttributeRef &src) const
60  {
61  return
62  ( myAttribute != src.myAttribute);
63  }
64 
65  /// Test to see if the attribute reference refers to a valid attribute
66  bool isValid() const
67  {
68  return myAttribute;
69  }
70 
71  /// Test to see if the attribute reference refers to a valid attribute
72  bool isInvalid() const
73  {
74  return !myAttribute;
75  }
76 
77  /// Method to clear the handle (so that it is no longer valid)
78  void clear();
79 
80  /// Set type information on the attribute
81  bool setTypeInfo(GA_TypeInfo info);
82 
83  /// Determine the storage type of the underlying attribute.
84  bool isFloat() const
85  { if (!getAIFTuple()) return false;
86  return GAisFloatStorage(getAIFTuple()->getStorage(get())); }
87  bool isInt() const
88  { if (!getAIFTuple()) return false;
89  return GAisIntStorage(getAIFTuple()->getStorage(get())); }
90  bool isString() const
91  { if (getAIFTuple()) return false;
92  if (getAIFStringTuple()) return true;
93  if (getAIFSharedStringArray()) return true;
94  return false; }
95 
97  { if (getAIFTuple()) { return GAstorageClass(getAIFTuple()->getStorage(get())); }
98  if (getAIFStringTuple()) return GA_STORECLASS_STRING;
99  if (getAIFSharedStringArray()) return GA_STORECLASS_STRING;
100  if (getAIFNumericArray()) { return GAstorageClass(getAIFNumericArray()->getStorage(get())); }
101  return GA_STORECLASS_OTHER;
102  }
103 
104  /// Tuple size of the attribute. Non-tuple types are treated
105  /// as size one.
106  int getTupleSize() const
107  { if (getAIFTuple()) { return getAIFTuple()->getTupleSize(get()); }
108  if (getAIFStringTuple()) { return getAIFStringTuple()->getTupleSize(get()); }
109  if (getAIFSharedStringArray()) { return getAIFSharedStringArray()->getTupleSize(get()); }
110  if (getAIFNumericArray()) { return getAIFNumericArray()->getTupleSize(get()); }
111  return 1;
112  }
113  void setTupleSize(int size)
114  { if (getAIFTuple()) { getAIFTuple()->setTupleSize(get(), size); }
115  if (getAIFStringTuple()) { getAIFStringTuple()->setTupleSize(get(), size); }
116  if (getAIFNumericArray()) { getAIFNumericArray()->setTupleSize(get(), size); }
117  }
118 
119  inline GA_Attribute *get() const { return myAttribute; }
120  inline operator GA_Attribute *() const { return myAttribute; }
121  SYS_SAFE_BOOL inline operator bool() const { return myAttribute != 0; }
122  inline GA_Attribute *getAttribute() const
123  {
124  return myAttribute;
125  }
126  inline const GA_AIFCopyData *getAIFCopyData() const
127  {
128  return myCopyData;
129  }
130  inline const GA_AIFMath *getAIFMath() const
131  {
132  return myMath;
133  }
134  inline const GA_AIFInterp *getAIFInterp() const
135  {
136  return myInterp;
137  }
138  inline const GA_AIFTuple *getAIFTuple() const
139  {
140  return myTuple;
141  }
143  {
144  return myStringTuple;
145  }
146  inline const GA_AIFIndexPair*getAIFIndexPair() const
147  {
148  return myIndexPair;
149  }
151  {
152  if (get())
153  return get()->getAIFNumericArray();
154  return 0;
155  }
157  {
158  if (get())
159  return get()->getAIFSharedStringArray();
160  return 0;
161  }
162 
163 
164 private:
165  GA_Attribute *myAttribute;
166  const GA_AIFMath *myMath;
167  const GA_AIFInterp *myInterp;
168  const GA_AIFCopyData *myCopyData;
169  const GA_AIFTuple *myTuple;
170  const GA_AIFStringTuple *myStringTuple;
171  const GA_AIFIndexPair *myIndexPair;
172 
173  friend class GA_ROAttributeRef;
174 };
175 
176 
177 /// @brief This class provides a way to manage a reference to an attribute
178 /// permitting Read-Write access.
180 {
181 public:
182  /// Default constructor. If an attribute is passed in, the ref will be
183  /// valid. Otherwise, it will be invalid.
184  GA_RWAttributeRef(GA_Attribute *attrib = 0);
185 
186 private:
187  /// No additional data beyond the base classes so that splicing to the
188  /// base class in pass-by-value situations isn't an issue.
189 };
190 
191 
192 /// @brief This class provides a way to manage a reference to an attribute
193 /// permitting Read-Only access.
195 {
196 public:
197  /// Default constructor. If an attribute is passed in, the ref will be
198  /// valid. Otherwise, it will be invalid.
199  GA_ROAttributeRef(const GA_Attribute *attrib = 0);
200 
201  /// Conversion constructor (implicit)
203  {
204  myAttribute = src.myAttribute;
205  myMath = src.myMath;
206  myCopyData = src.myCopyData;
207  myInterp = src.myInterp;
208  myTuple = src.myTuple;
209  myStringTuple = src.myStringTuple;
210  myIndexPair = src.myIndexPair;
211  }
212 
213  /// Define the * operator to dereference the attribute
214  const GA_Attribute &operator*() const
215  { UT_ASSERT(myAttribute); return *myAttribute; }
216  /// An -> operator to access the attribute
217  const GA_Attribute *operator->() const
218  { return myAttribute; }
219 
220  /// Assignment operators
221  GA_ROAttributeRef &operator=(const GA_Attribute *attrib);
222 
224  {
225  myAttribute = src.myAttribute;
226  myMath = src.myMath;
227  myCopyData = src.myCopyData;
228  myInterp = src.myInterp;
229  myTuple = src.myTuple;
230  myStringTuple = src.myStringTuple;
231  myIndexPair = src.myIndexPair;
232 
233  return *this;
234  }
235 
236  /// Comparison operator
237  bool operator==(const GA_ROAttributeRef &src) const
238  { return
239  (myAttribute == src.myAttribute);
240  }
241  /// Comparison operator
242  bool operator!=(const GA_ROAttributeRef &src) const
243  {
244  return
245  (myAttribute != src.myAttribute);
246  }
247 
248  /// Test to see if the attribute reference refers to a valid attribute
249  inline bool isValid() const
250  {
251  return myAttribute;
252  }
253 
254  /// Test to see if the attribute reference refers to a valid attribute
255  inline bool isInvalid() const
256  {
257  return !myAttribute;
258  }
259 
260  /// Method to clear the handle (so that it is no longer valid)
261  void clear();
262 
263  /// Get type information on the attribute, with invalid references
264  /// returning GA_TYPE_VOID.
265  GA_TypeInfo getTypeInfo() const;
266 
267  /// Determine the storage type of the underlying attribute.
268  bool isFloat() const
269  { if (!getAIFTuple()) return false;
270  return GAisFloatStorage(getAIFTuple()->getStorage(get())); }
271  bool isInt() const
272  { if (!getAIFTuple()) return false;
273  return GAisIntStorage(getAIFTuple()->getStorage(get())); }
274  bool isString() const
275  { if (getAIFTuple()) return false;
276  if (getAIFStringTuple()) return true;
277  if (getAIFSharedStringArray()) return true;
278  return false; }
279 
281  {
282  if (getAIFTuple())
283  return GAstorageClass(getAIFTuple()->getStorage(get()));
284  if (getAIFStringTuple())
285  return GA_STORECLASS_STRING;
286  if (getAIFSharedStringArray())
287  return GA_STORECLASS_STRING;
288  if (getAIFNumericArray())
289  return GAstorageClass(getAIFNumericArray()->getStorage(get()));
290  return GA_STORECLASS_OTHER;
291  }
292 
293  /// Tuple size of the attribute. Non-tuple types are treated
294  /// as size one.
295  int getTupleSize() const
296  {
297  if (getAIFTuple())
298  return getAIFTuple()->getTupleSize(get());
299  if (getAIFSharedStringArray())
300  return getAIFSharedStringArray()->getTupleSize(get());
301  if (getAIFStringTuple())
302  return getAIFStringTuple()->getTupleSize(get());
303  if (getAIFNumericArray())
304  return getAIFNumericArray()->getTupleSize(get());
305  return 1;
306  }
307 
308  inline const GA_Attribute *get() const { return myAttribute; }
309  inline operator const GA_Attribute *() const { return myAttribute; }
310  SYS_SAFE_BOOL inline operator bool() const { return myAttribute != 0; }
311  inline const GA_Attribute *getAttribute() const
312  {
313  return myAttribute;
314  }
315  inline const GA_AIFCopyData *getAIFCopyData() const
316  {
317  return myCopyData;
318  }
319  inline const GA_AIFMath *getAIFMath() const
320  {
321  return myMath;
322  }
323  inline const GA_AIFInterp *getAIFInterp() const
324  {
325  return myInterp;
326  }
327  inline const GA_AIFTuple *getAIFTuple() const
328  {
329  return myTuple;
330  }
331  inline const GA_AIFStringTuple*getAIFStringTuple() const
332  {
333  return myStringTuple;
334  }
336  {
337  if (get())
338  return get()->getAIFNumericArray();
339  return 0;
340  }
342  {
343  if (get())
344  return get()->getAIFSharedStringArray();
345  return 0;
346  }
347 
348  /// Shared String Tuple Interface. This allows you to get integer or
349  /// string values out of the attribute.
350  const GA_AIFSharedStringTuple *getAIFSharedStringTuple() const;
351  inline const GA_AIFIndexPair*getAIFIndexPair() const
352  {
353  return myIndexPair;
354  }
355 
356  /// Look up the AIFStringTuple and evaluate the string. If there is no AIF
357  /// support, this will return a NULL pointer
358  const char *getString(GA_Offset element_index,
359  int tuple_index=0) const;
360 
361 private:
362  const GA_Attribute *myAttribute;
363  const GA_AIFMath *myMath;
364  const GA_AIFInterp *myInterp;
365  const GA_AIFCopyData *myCopyData;
366  const GA_AIFTuple *myTuple;
367  const GA_AIFStringTuple *myStringTuple;
368  const GA_AIFIndexPair *myIndexPair;
369 };
370 
371 #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:190
const GA_AIFIndexPair * getAIFIndexPair() const
const GA_AIFNumericArray * getAIFNumericArray() 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
GA_StorageClass
Definition: GA_Types.h:68
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:12
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
GLsizeiptr size
Definition: glcorearb.h:663
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:617
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:62
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:80
bool operator==(const GA_ROAttributeRef &src) const
Comparison operator.
GA_Attribute * operator->() const
Define the -> operator to access the attribute.
bool isFloat() const
Determine the storage type of the underlying attribute.
A specialization of GA_AIFStringTuple to access "shared strings".
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:126
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:1792
bool operator!=(const GA_ROAttributeRef &src) const
Comparison operator.