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