HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_AIFBlob.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_AIFBlob.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_AIFBlob__
12 #define __GA_AIFBlob__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include "GA_BlobData.h"
17 #include "GA_BlobContainer.h"
18 
19 #include <UT/UT_Array.h>
20 #include <UT/UT_ValArray.h>
21 
22 #include <SYS/SYS_Types.h>
23 
24 #include <stddef.h>
25 
26 
27 class GA_Range;
29 
30 
33 
34 
35 /// @brief Attribute Interface for accessing generic blob data
36 ///
37 /// This attribute interface allows access to blob data on an attribute.
38 /// This is provided automatically if you inherit from GA_ATIBlob.
40 {
41 public:
42  GA_AIFBlob();
43  virtual ~GA_AIFBlob();
44 
45  /// Return the number of blobs per element
46  virtual int getTupleSize(const GA_Attribute *attrib) const = 0;
47 
48  /// Set the tuple size
49  virtual bool setTupleSize(GA_Attribute *attrib, int size) const = 0;
50 
51  /// Return the total number of unique blobs stored in the attribute
52  virtual GA_Size getBlobCount(const GA_Attribute *attrib) const = 0;
53 
54  /// Given a blob integer identifier, return a handle to the actual blob data
55  virtual GA_BlobRef lookupBlob(const GA_Attribute *attrib,
56  GA_BlobIndex handle) const = 0;
57 
58  /// Blob handles (GA_BlobIndex) may not be contiguous.
59  /// This may be an expensive operation.
60  virtual GA_BlobRef lookupOrderedBlob(const GA_Attribute *attrib,
61  exint index) const = 0;
62 
63  /// Get the integer identifier for the blob associated with the tuple index
64  /// of the given element. An element with no blob data will have an index
65  /// less than 0.
66  virtual GA_BlobIndex getBlobIndex(const GA_Attribute *atr,
68  int tuple_index=0) const = 0;
69  /// Get the blob data associated with the tuple index of the given element.
70  virtual GA_BlobRef getBlob(const GA_Attribute *attrib,
71  GA_Offset offset,
72  int tuple_index=0) const = 0;
73  /// Store a blob on the given element
74  virtual bool setBlob(GA_Attribute *attrib,
75  const GA_BlobRef &blob,
76  GA_Offset offset,
77  int tuple_index=0) const = 0;
78 
79  /// Replace the value of the blob at the given index with a new value.
80  /// Implementors should be careful to check whether the @c new_blob exists
81  /// (i.e. renaming an existing blob to another existing blob).
82  /// All blobs which reference the original handle will now reference the
83  /// new blob.
84  virtual bool replaceBlob(GA_Attribute *attrib,
85  GA_BlobIndex handle,
86  const GA_BlobRef &new_blob) const =0;
87 
88  /// Compact the storage by removing empty indexes
89  virtual void compactStorage(GA_Attribute *attrib) const = 0;
90 
91  /// @brief Class which holds temporary references to blobs
92  ///
93  /// In some cases, it's expedient to add multiple blobs to the attribute
94  /// and then assign the handle values after the fact. This class is
95  /// similar to the GA_AIFBlob::StringBuffer class.
96  class BlobBuffer
97  {
98  public:
99  BlobBuffer(GA_Attribute *attribute = NULL,
100  const GA_AIFBlob *aif=NULL)
101  : myAttribute(attribute)
102  , myAIFBlob(aif)
103  {
104  }
106  : myAttribute(NULL)
107  , myAIFBlob(NULL)
108  {
109  *this = src;
110  }
112  {
113  clear();
114  }
115 
117  {
118  if (&src != this)
119  {
120  clear();
121  myAttribute = src.myAttribute;
122  myAIFBlob = src.myAIFBlob;
123  for (exint i = 0; i < src.entries(); ++i)
124  append(src.getBlob(i));
125  }
126  return *this;
127  }
128 
129  /// Return number of strings referenced in the string buffer
130  GA_Size entries() const { return myIndexList.entries(); }
131 
132  /// Add a string to the attribute. Returns the handle of the string in
133  /// the attribute (not the string's index in the buffer).
134  GA_BlobIndex append(const GA_BlobRef &blob);
135 
136  /// Return the string index from the buffer. The index refers to the
137  /// buffer index (not the blob handle).
139  { return myIndexList(i); }
140  /// Return a string handle from the buffer. The index refers to the
141  /// buffer index (not the blob handle).
142  GA_BlobRef getBlob(exint i) const;
143 
144  /// Clear references to all strings contained in the buffer.
145  void clear();
146  private:
147  GA_BlobIndexList myIndexList;
148  const GA_AIFBlob *myAIFBlob;
149  GA_Attribute *myAttribute;
150  };
151 
152 public:
153  /// The Array API. This API allows the attribute to store an "array" on
154  /// each data element. This is done by changing the tuple size to match
155  /// the array length. Each tuple, therefore, represents an array. The
156  /// length is determined by the occupied entries in the tuple.
157  ///
158  /// These methods can all be implemented using the other API functions.
159  /// However, they provide a simpler interface.
160 
161  /// Reserve space for an array of the given size
162  virtual bool arrayReserve(GA_Attribute *attrib, int length) const
163  {
164  if (length <= getTupleSize(attrib))
165  return true;
166  return setTupleSize(attrib, length);
167  }
168 
169  /// Truncate the array to the given entries
170  virtual bool arrayTruncate(GA_Attribute *attrib, int length) const
171  {
172  if (length >= getTupleSize(attrib))
173  return true;
174  return setTupleSize(attrib, length);
175  }
176 
177  /// Trim the array to the minimum required size. This may be an expensive
178  /// operation as it traverses all elements to compute the minimum size,
179  /// then calls truncate. The method returns the new size.
180  virtual int arrayTrim(GA_Attribute *attrib) const;
181 
182  /// Append an element to the end of the array for the given element
183  virtual int arrayAppendBlob(GA_Attribute *attrib,
184  const GA_BlobRef &blob,
185  GA_Offset element_index=GA_Offset(0)) const;
186 
187  /// Append an element to the array, but only if the element is unique in
188  /// the array.
189  virtual int arrayAppendUniqueBlob(GA_Attribute *attrib,
190  const GA_BlobRef &blob,
191  GA_Offset element_index=GA_Offset(0)) const;
192 
193  /// Append an element to the end of the array for the given element
194  virtual int arrayAppendBlobIndex(GA_Attribute *attrib,
195  GA_BlobIndex handle,
196  GA_Offset element_index=GA_Offset(0)) const
197  {
198  return arrayAppendBlob(attrib,
199  lookupBlob(attrib, handle),
200  element_index);
201  }
202 
203  /// Append an element to the array, but only if the element is unique in
204  /// the array.
206  GA_BlobIndex handle,
207  GA_Offset element_index=GA_Offset(0)) const
208  {
209  return arrayAppendUniqueBlob(attrib,
210  lookupBlob(attrib, handle),
211  element_index);
212  }
213 
214 
215  /// Return the length of occupied blobs in the array. This is primarily
216  /// useful for global attributes.
217  virtual int arrayGetLength(const GA_Attribute *attrib,
218  GA_Offset element_index=GA_Offset(0)) const;
219 
220  /// Return the maximum length of all elements in the range
221  virtual int arrayGetMaxLength(const GA_Attribute *attrib,
222  const GA_Range &range) const;
223 
224  /// Return the blob handle for the item at the given array index.
226  int array_index,
227  GA_Offset element_index=GA_Offset(0)) const
228  {
229  return getBlobIndex(attrib, element_index,
230  array_index);
231  }
232  /// Return the blob for the item at the given array index.
233  virtual GA_BlobRef arrayGetBlob(const GA_Attribute *attrib,
234  int array_index,
235  GA_Offset element_index=GA_Offset(0)) const
236  {
237  return getBlob(attrib, element_index, array_index);
238  }
239  virtual int arrayGetBlobs(GA_BlobRefList &list,
240  const GA_Attribute *attrib,
241  GA_Offset element_index=GA_Offset(0)) const;
242 
243  /// Find a blob in the array, returning its index. Returns -1 if the blob
244  /// isn't found.
245  virtual int arrayFindBlob(const GA_Attribute *attrib,
246  const GA_BlobRef &blob,
247  GA_Offset element_index=GA_Offset(0)) const;
248  /// Delete a blob from the index. This will shift occupied blobs after the
249  /// deleted blob so that the tuple contains a contiguous array of occupied
250  /// tuple indices.
251  virtual bool arrayDestroyBlob(GA_Attribute *attrib,
252  int array_index,
253  GA_Offset element_index=GA_Offset(0)) const;
254 
255  /// Remove duplicate blobs from the array
256  /// The @c element_index specifies the point, primitive, vertex etc.
257  virtual int arrayRemoveDuplicates(GA_Attribute *attrib,
258  GA_Offset element_index=GA_Offset(0)) const;
259 protected:
260  /// Methods used by the BlobBuffer methods to add an unreferenced blob to
261  /// the attribute.
262  virtual GA_BlobIndex addBlobReference(GA_Attribute *attrib,
263  const GA_BlobRef &blob) const = 0;
264  virtual void delBlobReference(GA_Attribute *attrib,
265  GA_BlobIndex handle) const=0;
266  friend class BlobBuffer;
267 };
268 
269 #endif
GA_BlobIndex getBlobIndex(exint i) const
Definition: GA_AIFBlob.h:138
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
GLenum GLint * range
Definition: glcorearb.h:1924
GA_BlobRef getBlob(exint i) const
virtual int arrayAppendUniqueBlobIndex(GA_Attribute *attrib, GA_BlobIndex handle, GA_Offset element_index=GA_Offset(0)) const
Definition: GA_AIFBlob.h:205
#define GA_API
Definition: GA_API.h:12
Class which holds temporary references to blobs.
Definition: GA_AIFBlob.h:96
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual GA_BlobIndex arrayGetBlobIndex(const GA_Attribute *attrib, int array_index, GA_Offset element_index=GA_Offset(0)) const
Return the blob handle for the item at the given array index.
Definition: GA_AIFBlob.h:225
GLsizeiptr size
Definition: glcorearb.h:663
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
BlobBuffer(const BlobBuffer &src)
Definition: GA_AIFBlob.h:105
Attribute Interface for accessing generic blob data.
Definition: GA_AIFBlob.h:39
BlobBuffer & operator=(const BlobBuffer &src)
Definition: GA_AIFBlob.h:116
virtual GA_BlobRef arrayGetBlob(const GA_Attribute *attrib, int array_index, GA_Offset element_index=GA_Offset(0)) const
Return the blob for the item at the given array index.
Definition: GA_AIFBlob.h:233
UT_IndexedHashMapItemId GA_BlobIndex
int64 exint
Definition: SYS_Types.h:109
GLintptr offset
Definition: glcorearb.h:664
GA_Size entries() const
Return number of strings referenced in the string buffer.
Definition: GA_AIFBlob.h:130
UT_ValArray< GA_BlobIndex > GA_BlobIndexList
Definition: GA_AIFBlob.h:28
BlobBuffer(GA_Attribute *attribute=NULL, const GA_AIFBlob *aif=NULL)
Definition: GA_AIFBlob.h:99
virtual bool arrayTruncate(GA_Attribute *attrib, int length) const
Truncate the array to the given entries.
Definition: GA_AIFBlob.h:170
virtual int arrayAppendBlobIndex(GA_Attribute *attrib, GA_BlobIndex handle, GA_Offset element_index=GA_Offset(0)) const
Append an element to the end of the array for the given element.
Definition: GA_AIFBlob.h:194
GLuint index
Definition: glcorearb.h:785
virtual bool arrayReserve(GA_Attribute *attrib, int length) const
Reserve space for an array of the given size.
Definition: GA_AIFBlob.h:162
UT_Array< GA_BlobRef > GA_BlobRefList
Definition: GA_AIFBlob.h:32
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
GLenum src
Definition: glcorearb.h:1792