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,
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
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  virtual bool setTupleSize(GA_Attribute *attrib, int size) const = 0;
224 
225  virtual GA_Storage getStorage(const GA_Attribute *attrib) const = 0;
226 
227  /// Get a single string from the array for a single tuple of an element.
228  virtual void getString(const GA_Attribute *attribute, GA_Offset offset, UT_StringArray &strings) const = 0;
229  virtual void getString(const GA_Attribute *attribute, GA_Offset offset, UT_Array<UT_StringHolder> &strings) const = 0;
230 
231  /// Get the handle from the array for a single tuple of an element
233 
234  /// Set a single component for a single element.
235  virtual void setString(GA_Attribute *attribute, GA_Offset offset, const UT_StringArray &strings) const = 0;
236  virtual void setString(GA_Attribute *attribute, GA_Offset offset, const UT_Array<UT_StringHolder> &strings) const = 0;
237  /// Set a single component for a range of elements.
239 
240  /// Return the size of the array for the GA_Offset
241  virtual exint arraySize(const GA_Attribute *atr, GA_Offset off) const = 0;
242 
243  /// Get a UT_StringArray at specific GA_Offset. This is an alias for
244  /// getString() so that we can treat this AIF similar to
245  /// GA_AIFNumericArray.
246  bool get(const GA_Attribute *attrib, GA_Offset o, UT_StringArray &v) const
247  {
248  getString(attrib, o, v);
249  return true;
250  }
251 
252  /// Set a UT_StringArray at specific GA_Offset. This is an alias for
253  /// setString() so that we can treat this AIF similar to
254  /// GA_AIFNumericArray.
255  bool set(GA_Attribute *attrib, GA_Offset o, const UT_StringArray &v) const
256  {
257  setString(attrib, o, v);
258  return true;
259  }
260 
261 };
262 
263 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
bool set(GA_Attribute *attrib, GA_Offset o, const UT_StringArray &v) const
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
virtual void delHandleReference(GA_Attribute *attribute, GA_StringIndexType handle) const =0
Decrement reference to a handle.
const GLdouble * v
Definition: glcorearb.h:837
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define GA_API
Definition: GA_API.h:14
GA_StringIndexType getHandle() const
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
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:646
virtual exint arraySize(const GA_Attribute *atr, GA_Offset off) const =0
Return the size of the array for the GA_Offset.
GLintptr offset
Definition: glcorearb.h:665
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.
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.
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:1933
GLsizeiptr size
Definition: glcorearb.h:664
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:786
virtual bool setTupleSize(GA_Attribute *attrib, int size) const =0
GA_BlobIndex GA_StringIndexType
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
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:51
iterator & operator=(const iterator &src)
GLenum src
Definition: glcorearb.h:1793