HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_ATIStringArray.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_ATIStringArray.h ( GA Library, C++)
7  *
8  * COMMENTS: String Array ATI (Attribute Type Implementation)
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_ATIStringArray__
14 #define __GA_ATIStringArray__
15 
16 #include "GA_API.h"
17 #include "GA_ATIBlobArray.h"
18 #include "GA_AIFSharedStringArray.h" // For GA_StringIndexType type
19 #include "GA_Types.h"
20 
21 #include <UT/UT_Array.h>
22 #include <UT/UT_Map.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_StringMap.h>
25 #include <UT/UT_VectorTypes.h>
26 
27 #include <iosfwd>
28 #include <stddef.h>
29 
30 
31 class GA_AIFJSON;
32 class GA_AIFStringArray;
33 class GA_Attribute;
34 class GA_AttributeType;
35 class GA_IndexMap;
36 
37 class UT_StringArray;
38 class UT_IStream;
39 class UT_Options;
40 
42 {
43 public:
44  static void registerType();
45 
47  static const UT_StringHolder &getTypeName()
48  { return theAttributeType->getTypeName(); }
50  static const GA_AttributeType &getType() { return *theAttributeType; }
51 
53  static bool isType(const GA_Attribute *attrib)
54  {
55  return attrib && &attrib->getType() == theAttributeType;
56  }
59  {
60  if (attrib && &attrib->getType() == theAttributeType)
61  return static_cast<GA_ATIStringArray *>(attrib);
62  return NULL;
63  }
65  static const GA_ATIStringArray *cast(const GA_Attribute *attrib)
66  {
67  if (attrib && &attrib->getType() == theAttributeType)
68  return static_cast<const GA_ATIStringArray *>(attrib);
69  return NULL;
70  }
71 
72  static GA_Attribute *create(const GA_IndexMap &index_map,
73  GA_AttributeScope scope,
74  const UT_StringHolder &name,
75  const GA_AttributeOptions *attribute_options=NULL);
76  static GA_Attribute *create(const GA_IndexMap &index_map,
77  const UT_StringHolder &name)
78  { return create(index_map, GA_SCOPE_PUBLIC, name); }
79 
81  const GA_IndexMap &index_map,
82  GA_AttributeScope scope,
83  const UT_StringHolder &name,
84  int tuple_size);
85  virtual ~GA_ATIStringArray();
86 
87  // AIFCopyData is implemented in GA_ATIBlob.
89  { return myAIFSharedStringArray; }
90 
91  /// @section JSON-GA_ATIStringArray JSON Schema: GA_ATIStringArray
92  /// @code
93  /// {
94  /// "name" : "GA_ATIStringArray",
95  /// "description" : "An tuple array of indexed strings",
96  /// "type" : "orderedmap",
97  /// "properties": {
98  /// "storage": {
99  /// "type" : "string",
100  /// "description" : "Tuple storage",
101  /// "enum" : [ "int8", "int16", "int32", "int64" ],
102  /// },
103  /// "strings": {
104  /// "type" : { "$ref":"GA_BlobData", },
105  /// "description" : "Array of strings used in the attribute",
106  /// },
107  /// "indices": {
108  /// "type" : {"$ref":"GA_DataArrayTuple"},
109  /// "description" : "Int index for each element of the array",
110  /// },
111  /// },
112  /// }
113  /// @endcode
114  /// @see @ref JSON_FileFormat
115  virtual const GA_AIFJSON *getAIFJSON() const { return myAIFJSON; }
116 
117  /// @{
118  /// Get a string
119  void getString(UT_StringArray &strings, GA_Offset offset) const;
120  void getString(UT_Array<UT_StringHolder> &strings, GA_Offset offset) const;
121  void getStringIndex(UT_Array<GA_StringIndexType> &indices, GA_Offset offset) const;
122  /// @}
123  /// @{
124  /// Set a string
125  void setString(GA_Offset offset, const UT_StringArray &strings);
126  void setString(GA_Offset offset, const UT_Array<UT_StringHolder> &strings);
127  void setStringIndex(GA_Offset offset, const UT_Array<GA_StringIndexType> &indices);
128  /// @}
129 
130 protected:
131  // Create a new ATIBlob
132  virtual GA_Attribute *doClone(const GA_IndexMap &index_map,
133  const UT_StringHolder &name) const;
134 private:
135  const char *lookupString(GA_StringIndexType handle) const;
136  const char *lookupOrderedString(exint handle) const;
137  GA_StringIndexType lookupHandle(const char *s) const;
138  GA_StringIndexType validateHandle(GA_StringIndexType h) const;
139  bool replaceString(GA_StringIndexType handle,
140  const char *string);
141 
142  /// @{ GA_AIFStringTuple
143  /// @warning If you call addStringReference(), at some point, you must call
144  /// delHandleReference() on the string you added.
145  GA_StringIndexType addStringReference(const char *str);
146  void delHandleReference(GA_StringIndexType handle);
147  bool tupleGet(GA_Offset di, GA_StringIndexType &v, int vi) const;
148  bool tupleSet(GA_Offset di, GA_StringIndexType v, int vi);
149  /// @}
150 
151  static GA_AIFSharedStringArray *myAIFSharedStringArray;
152  static GA_AIFJSON *myAIFJSON;
153 
154  static const GA_AttributeType *theAttributeType;
155 
156  /// @cond INTERNAL_DOX
157  friend class ga_StringArray;
158  friend class ga_StringJSON;
159  friend class GA_ATIStringArrayDelayedWriter;
160  /// @endcond
161 };
162 
163 //
164 // Designed to delay all the reference count adjustments
165 // until this object is flushed. Also maintains a local
166 // table for looking up the string indices with, thus avoiding
167 // concurrency issues.
168 //
170 {
171 public:
175 
176  void bind(GA_ATIStringArray *attrib);
177 
178 
179  // The index cache is provided to avoid having to potentially resize
180  // this inside this function.
181  void setString(GA_Offset offset, const UT_StringArray &strings, UT_Array<GA_StringIndexType> &indexcache);
182  void setString(GA_Offset offset, const UT_Array<UT_StringHolder> &strings, UT_Array<GA_StringIndexType> &indexcache);
183  // Directly set the index.
184  void setStringIndex(GA_Offset offset, const UT_Array<GA_StringIndexType> &idx);
185 
186  void flush();
187 
188 private:
189  void setString(GA_Offset offset, const UT_StringHolder *strings, exint n, UT_Array<GA_StringIndexType> &indexcache);
190 
191  GA_ATIStringArray *myAttribute;
192 
193  UT_Map<GA_StringIndexType, exint> myRefCountChanges;
194  UT_StringMap<GA_StringIndexType> myStringToIndex;
195 };
196 
197 // NOTE: It may seem strange to define GA_ATIBlobArray::isType() and cast()
198 // in GA_ATIStringArray.h, but GA_ATIBlobArray::isType() and cast() need
199 // GA_ATIStringArray::isType(), and GA_ATIStringArray inherits from GA_ATIBlobArray,
200 // so these are defined here, and GA_ATIStringArray.h is included
201 // in GA_ATIBlobArray.h, below the class.
202 bool
204 {
205  return attrib && (&attrib->getType() == theAttributeType || GA_ATIStringArray::isType(attrib));
206 }
209 {
210  if (attrib && (&attrib->getType() == theAttributeType || GA_ATIStringArray::isType(attrib)))
211  return static_cast<GA_ATIBlobArray *>(attrib);
212  return NULL;
213 }
214 const GA_ATIBlobArray *
216 {
217  if (attrib && (&attrib->getType() == theAttributeType || GA_ATIStringArray::isType(attrib)))
218  return static_cast<const GA_ATIBlobArray *>(attrib);
219  return NULL;
220 }
221 
222 #endif
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
virtual const GA_AIFSharedStringArray * getAIFSharedStringArray() const
Return the attribute's shared string array interface or NULL.
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
GLsizei GLenum const void * indices
Definition: glcorearb.h:405
const GLdouble * v
Definition: glcorearb.h:836
static SYS_FORCE_INLINE const GA_ATIStringArray * cast(const GA_Attribute *attrib)
#define GA_API
Definition: GA_API.h:12
Standard user attribute level.
Definition: GA_Types.h:127
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_AttributeScope
Definition: GA_Types.h:121
GLdouble n
Definition: glcorearb.h:2007
static SYS_FORCE_INLINE GA_ATIStringArray * cast(GA_Attribute *attrib)
virtual const GA_AIFJSON * getAIFJSON() const
int64 exint
Definition: SYS_Types.h:115
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLintptr offset
Definition: glcorearb.h:664
A specialization of GA_AIFStringArray to access "shared strings".
static SYS_FORCE_INLINE const GA_AttributeType & getType()
GLuint const GLchar * name
Definition: glcorearb.h:785
GLsizei const GLchar *const * strings
Definition: glcorearb.h:1932
static void registerType()
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:197
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
A map of string to various well defined value types.
Definition: UT_Options.h:42
A simple ATI to store aribtrary "blobs" of data in an attribute.
static SYS_FORCE_INLINE GA_ATIBlobArray * cast(GA_Attribute *attrib)
GA_BlobIndex GA_StringIndexType
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
static GA_Attribute * create(const GA_IndexMap &index_map, GA_AttributeScope scope, const UT_StringHolder &name, const GA_AttributeOptions *attribute_options=NULL)
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
static GA_Attribute * create(const GA_IndexMap &index_map, const UT_StringHolder &name)
virtual GA_Attribute * doClone(const GA_IndexMap &index_map, const UT_StringHolder &name) const
Create a new ATIBlob attribute. Sub-classes must implement this.
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)