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