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  iterator &operator++(int) { advance(); return *this; }
152 
153  void rewind()
154  {
155  myIndex = 0;
156  setupDict();
157  }
158  bool atEnd() const { return myIndex >= myCount; }
159  void advance()
160  {
161  myIndex++;
162  setupDict();
163  }
164  GA_Size getCount() const { return myCount; }
165  GA_Size getIndex() const { return myIndex; }
167  { return GA_DictIndexType(myIndex); }
168  UT_OptionsHolder getDict() const { return myDict; }
169  private:
170  void setupDict()
171  {
172  while (myIndex < myCount)
173  {
174  myDict = myAIF->getTableDict(myAttrib,
175  GA_DictIndexType(myIndex));
176  if (myDict)
177  break;
178  myIndex++;
179  }
180  }
181  iterator(const GA_AIFSharedDictArray *aif,
182  const GA_Attribute *a)
183  : myAIF(aif)
184  , myAttrib(a)
185  , myIndex(0)
186  , myCount(aif ? aif->getTableEntries(a) : 0)
187  {
188  setupDict();
189  }
190 
191  const GA_AIFSharedDictArray *myAIF;
192  const GA_Attribute *myAttrib;
193  UT_OptionsHolder myDict;
194  GA_Size myCount;
195  GA_Size myIndex;
196  friend class GA_AIFSharedDictArray;
197  };
198 
199  iterator begin(const GA_Attribute *a) const
200  { return iterator(this, a); }
201  iterator end() const
202  { return iterator(); }
203 
204 protected:
205  /// Add (or increment) reference to a string
207  const UT_OptionsHolder &string) const = 0;
208  /// Decrement reference to a handle
210  GA_DictIndexType handle) const = 0;
211 
212 public:
213  // --------------------------------------------------------------
214  // Array Interface
215  // --------------------------------------------------------------
216 
217  virtual int getTupleSize(const GA_Attribute *attrib) const = 0;
218  virtual bool setTupleSize(GA_Attribute *attrib, int size) const = 0;
219 
220  virtual GA_Storage getStorage(const GA_Attribute *attrib) const = 0;
221 
222  /// Get a single string from the array for a single tuple of an element.
223  virtual void getDict(const GA_Attribute *attribute, GA_Offset offset, UT_Array<UT_OptionsHolder> &strings) const = 0;
224 
225  /// Get the handle from the array for a single tuple of an element
227 
228  /// Set a single component for a single element.
229  virtual void setDict(GA_Attribute *attribute, GA_Offset offset, const UT_Array<UT_OptionsHolder> &strings) const = 0;
230  /// Set a single component for a range of elements.
232 
233  /// Return the size of the array for the GA_Offset
234  virtual exint arraySize(const GA_Attribute *atr, GA_Offset off) const = 0;
235 
236  /// Get a UT_Array<UT_OptionsHolder> at specific GA_Offset. This is an
237  /// alias for getDict() so that we can treat this AIF similar to
238  /// GA_AIFNumericArray.
239  bool get(const GA_Attribute *attrib, GA_Offset o, UT_Array<UT_OptionsHolder> &v) const
240  {
241  getDict(attrib, o, v);
242  return true;
243  }
244 
245  /// Set a UT_DictArray at specific GA_Offset. This is an alias for
246  /// setDict() so that we can treat this AIF similar to
247  /// GA_AIFNumericArray.
248  bool set(GA_Attribute *attrib, GA_Offset o, const UT_Array<UT_OptionsHolder> &v) const
249  {
250  setDict(attrib, o, v);
251  return true;
252  }
253 
254 };
255 
256 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
GLsizeiptr size
Definition: glew.h:1681
GLenum src
Definition: glew.h:2410
virtual GA_DictIndexType addDictReference(GA_Attribute *attribute, const UT_OptionsHolder &string) const =0
Add (or increment) reference to a string.
GLuint index
Definition: glew.h:1814
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
int64 exint
Definition: SYS_Types.h:125
#define GA_API
Definition: GA_API.h:12
const GLdouble * v
Definition: glew.h:1391
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:233
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:639
bool set(GA_Attribute *attrib, GA_Offset o, const UT_Array< UT_OptionsHolder > &v) const
iterator begin(const GA_Attribute *a) const
GA_BlobIndex GA_DictIndexType
UT_OptionsHolder getDict() const
GLuint GLuint GLsizei GLenum const void * indices
Definition: glew.h:1253
virtual int getTupleSize(const GA_Attribute *attrib) const =0
GLsizei const GLchar *const * strings
Definition: glew.h:5883
virtual void delHandleReference(GA_Attribute *attribute, GA_DictIndexType handle) const =0
Decrement reference to a handle.
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.
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:49
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.
GLintptr offset
Definition: glew.h:1682