HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_AIFSharedStringArray.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_AIFSharedStringArray.h ( GA Library, C++)
7  *
8  * COMMENTS: Attribute Interface class for string index table methods
9  */
10 
11 #ifndef __GA_AIFSharedStringArray__
12 #define __GA_AIFSharedStringArray__
13 
14 #include "GA_API.h"
15 
16 #include "GA_BlobContainer.h"
17 // Following for the Index Type
19 #include "GA_Types.h"
20 
21 #include <UT/UT_Array.h>
22 #include <UT/UT_VectorTypes.h>
23 
24 #include <stddef.h>
25 
26 class GA_Attribute;
27 class GA_Range;
28 class UT_StringArray;
29 
30 /// @brief A specialization of GA_AIFStringArray to access "shared strings"
31 ///
32 /// This class provides the interface to access string table data. Each
33 /// attribute type may provide this interface if it makes sense.
35 {
36 public:
38  virtual ~GA_AIFSharedStringArray();
39 
40  /// Query information about the string storage.
41  virtual bool getStatistics(const GA_Attribute *attrib,
42  GA_StringTableStatistics &stats) const = 0;
43 
44  /// Compact the string storage
45  virtual bool compactStorage(GA_Attribute *attrib) const = 0;
46 
47  /// Extract data from the string table. This will extract all the unique
48  /// strings which are referenced by the attribute.
49  /// The string handles are guaranteed to be in ascending order, but
50  /// may or may not be contiguous.
51  virtual bool extractStrings(const GA_Attribute *attrib,
53  UT_IntArray &handles) const = 0;
54 
55  /// Extract all of the unique string handles of the attribute.
56  /// The string handles are guaranteed to be in ascending order, but
57  /// may or may not be contiguous.
58  virtual bool extractHandles(const GA_Attribute *attrib,
59  UT_IntArray &handles) const = 0;
60 
61  /// @{
62  /// Return the length of longest array
63  virtual exint findMaximumArrayLength(const GA_Attribute *attrib) const = 0;
64  /// @}
65 
66 public:
67  // --------------------------------------------------------------
68  // Interface to deal with string handles.
69  // --------------------------------------------------------------
70 
71  /// Return the number of entries in the shared string table
72  GA_Size getTableEntries(const GA_Attribute *attrib) const
73  {
75  if (attrib && getStatistics(attrib, stats))
76  return stats.getCapacity();
77  return 0;
78  }
79 
80  /// It's possible that there are invalid handle indexes mixed with the
81  /// valid handles. When iterating over all the handles, you can call @c
82  /// validateTableHandle() which will ensure that there's a string
83  /// associated with the given handle.
84  virtual GA_StringIndexType validateTableHandle(const GA_Attribute *attrib,
85  GA_StringIndexType index) const = 0;
86 
87  /// Get a string from the string table (without going through an attribute)
88  virtual const char *getTableString(const GA_Attribute *attrib,
89  GA_StringIndexType handle) const = 0;
90 
91  /// Get the handle (index) corresponding to the given string, returning -1
92  /// if none.
93  virtual GA_StringIndexType getTableHandle(const GA_Attribute *attrib,
94  const char *string) const = 0;
95 
96  /// GA_StringIndexType indices may not be contiguous, this method allows
97  /// you to get a string given an ordered index. Strings will be defined
98  /// for all contiguous strings. This may be an expensive operation, it's
99  /// better to access strings by their index if possible.
100  ///
101  /// This method will return a NULL pointer past the end of the string table
102  virtual const char *getTableOrderedString(const GA_Attribute *a,
103  exint index) const = 0;
104 
105 
106  /// Replace a string in the shared string table with a new value. Warning,
107  /// it's possible that the table will "collapse" after the replacement.
108  /// For example: @code
109  /// table := [ "foo", "bar" ]
110  /// table.replaceString(1, "foo") # Replace "bar" with "foo"
111  /// table := [ "foo" ]
112  /// @endcode
113  /// In the above example, all elements which originally referenced "bar"
114  /// will now reference "foo". This means that trying to swap two values
115  /// will not work as expected.
116  virtual bool replaceTableString(GA_Attribute *attrib,
117  GA_StringIndexType handle,
118  const char *string) const = 0;
119 
120  /// Class to iterate over all the strings in the shared string table
122  {
123  public:
125  : myAIF(NULL)
126  , myAttrib(NULL)
127  , myString(NULL)
128  , myCount(0)
129  , myIndex(0)
130  {
131  }
134  {
135  myAIF = src.myAIF;
136  myAttrib = src.myAttrib;
137  myString = src.myString;
138  myCount = src.myCount;
139  myIndex = src.myIndex;
140  return *this;
141  }
142  bool operator==(const iterator &src)
143  {
144  if (!src.myAIF)
145  return atEnd();
146  if (!myAIF)
147  return src.atEnd();
148  return myAIF == src.myAIF &&
149  myAttrib == src.myAttrib &&
150  myCount == src.myCount &&
151  myIndex == src.myIndex;
152  }
153  iterator &operator++() { advance(); return *this; }
154  iterator &operator++(int) { advance(); return *this; }
155 
156  void rewind()
157  {
158  myIndex = 0;
159  setupString();
160  }
161  bool atEnd() const { return myIndex >= myCount; }
162  void advance()
163  {
164  myIndex++;
165  setupString();
166  }
167  GA_Size getCount() const { return myCount; }
168  GA_Size getIndex() const { return myIndex; }
170  { return GA_StringIndexType(myIndex); }
171  const char *getString() const { return myString; }
172  private:
173  void setupString()
174  {
175  while (myIndex < myCount)
176  {
177  myString = myAIF->getTableString(myAttrib,
178  GA_StringIndexType(myIndex));
179  if (myString)
180  break;
181  myIndex++;
182  }
183  }
184  iterator(const GA_AIFSharedStringArray *aif,
185  const GA_Attribute *a)
186  : myAIF(aif)
187  , myAttrib(a)
188  , myString(NULL)
189  , myIndex(0)
190  , myCount(aif ? aif->getTableEntries(a) : 0)
191  {
192  setupString();
193  }
194 
195  const GA_AIFSharedStringArray *myAIF;
196  const GA_Attribute *myAttrib;
197  const char *myString;
198  GA_Size myCount;
199  GA_Size myIndex;
201  };
202 
203  iterator begin(const GA_Attribute *a) const
204  { return iterator(this, a); }
205  iterator end() const
206  { return iterator(); }
207 
208 protected:
209  /// Add (or increment) reference to a string
211  const char *string) const = 0;
212  /// Decrement reference to a handle
213  virtual void delHandleReference(GA_Attribute *attribute,
214  GA_StringIndexType handle) const = 0;
215 
216 public:
217  // --------------------------------------------------------------
218  // Array Interface
219  // --------------------------------------------------------------
220 
221  virtual int getTupleSize(const GA_Attribute *attrib) const = 0;
222 
223  virtual GA_Storage getStorage(const GA_Attribute *attrib) const = 0;
224 
225  /// Get a single string from the array for a single tuple of an element.
226  virtual void getString(const GA_Attribute *attribute, GA_Offset offset, UT_StringArray &strings) const = 0;
227  virtual void getString(const GA_Attribute *attribute, GA_Offset offset, UT_Array<UT_StringHolder> &strings) const = 0;
228 
229  /// Get the handle from the array for a single tuple of an element
230  virtual void getStringIndex(const GA_Attribute *attribute, GA_Offset offset, UT_Array<GA_StringIndexType> &indices) const = 0;
231 
232  /// Set a single component for a single element.
233  virtual void setString(GA_Attribute *attribute, GA_Offset offset, const UT_StringArray &strings) const = 0;
234  virtual void setString(GA_Attribute *attribute, GA_Offset offset, const UT_Array<UT_StringHolder> &strings) const = 0;
235  /// Set a single component for a range of elements.
236  virtual void setStringIndex(GA_Attribute *attribute, GA_Offset offset, const UT_Array<GA_StringIndexType> &indices) const = 0;
237 
238  /// Return the size of the array for the GA_Offset
239  virtual exint arraySize(const GA_Attribute *atr, GA_Offset off) const = 0;
240 
241  /// Get a UT_StringArray at specific GA_Offset. This is an alias for
242  /// getString() so that we can treat this AIF similar to
243  /// GA_AIFNumericArray.
244  bool get(const GA_Attribute *attrib, GA_Offset o, UT_StringArray &v) const
245  {
246  getString(attrib, o, v);
247  return true;
248  }
249 
250  /// Set a UT_StringArray at specific GA_Offset. This is an alias for
251  /// setString() so that we can treat this AIF similar to
252  /// GA_AIFNumericArray.
253  bool set(GA_Attribute *attrib, GA_Offset o, const UT_StringArray &v) const
254  {
255  setString(attrib, o, v);
256  return true;
257  }
258 
259 };
260 
261 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
bool set(GA_Attribute *attrib, GA_Offset o, const UT_StringArray &v) const
GLsizei GLenum const void * indices
Definition: glcorearb.h:405
virtual void delHandleReference(GA_Attribute *attribute, GA_StringIndexType handle) const =0
Decrement reference to a handle.
const GLdouble * v
Definition: glcorearb.h:836
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define GA_API
Definition: GA_API.h:12
GA_StringIndexType getHandle() const
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GA_Size getTableEntries(const GA_Attribute *attrib) const
Return the number of entries in the shared string table.
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual exint arraySize(const GA_Attribute *atr, GA_Offset off) const =0
Return the size of the array for the GA_Offset.
virtual GA_StringIndexType addStringReference(GA_Attribute *attribute, const char *string) const =0
Add (or increment) reference to a string.
virtual GA_Storage getStorage(const GA_Attribute *attrib) const =0
virtual void getStringIndex(const GA_Attribute *attribute, GA_Offset offset, UT_Array< GA_StringIndexType > &indices) const =0
Get the handle from the array for a single tuple of an element.
int64 exint
Definition: SYS_Types.h:109
virtual int getTupleSize(const GA_Attribute *attrib) const =0
virtual void setStringIndex(GA_Attribute *attribute, GA_Offset offset, const UT_Array< GA_StringIndexType > &indices) const =0
Set a single component for a range of elements.
GLintptr offset
Definition: glcorearb.h:664
A specialization of GA_AIFStringArray to access "shared strings".
virtual void setString(GA_Attribute *attribute, GA_Offset offset, const UT_StringArray &strings) const =0
Set a single component for a single element.
GLsizei const GLchar *const * strings
Definition: glcorearb.h:1932
virtual void getString(const GA_Attribute *attribute, GA_Offset offset, UT_StringArray &strings) const =0
Get a single string from the array for a single tuple of an element.
GLuint index
Definition: glcorearb.h:785
GA_BlobIndex GA_StringIndexType
Class to iterate over all the strings in the shared string table.
iterator begin(const GA_Attribute *a) const
GA_Storage
Definition: GA_Types.h:48
iterator & operator=(const iterator &src)
GLenum src
Definition: glcorearb.h:1792