HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_ATIDictArray.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_ATIDictArray.h ( GA Library, C++)
7  *
8  * COMMENTS: Dict Array ATI (Attribute Type Implementation)
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_ATIDictArray__
14 #define __GA_ATIDictArray__
15 
16 #include "GA_API.h"
17 #include "GA_Attribute.h"
18 #include "GA_ATIBlobArray.h"
19 #include "GA_AIFSharedDictTuple.h"
21 #include "GA_Types.h"
22 
23 #include <UT/UT_ArrayMap.h>
24 #include <UT/UT_Options.h>
25 #include <UT/UT_StringHolder.h>
26 #include <SYS/SYS_Inline.h>
27 #include <SYS/SYS_Types.h>
28 
29 
31 class GA_AIFJSON;
32 class GA_AttributeType;
33 class GA_IndexMap;
34 
35 template <typename T> class UT_Array;
36 
37 
39 {
40 public:
41  static void registerType();
42 
44  static const UT_StringHolder &getTypeName()
45  { return theAttributeType->getTypeName(); }
47  static const GA_AttributeType &getType() { return *theAttributeType; }
48 
50  static bool isType(const GA_Attribute *attrib)
51  {
52  return attrib && &attrib->getType() == theAttributeType;
53  }
56  {
57  if (attrib && &attrib->getType() == theAttributeType)
58  return static_cast<GA_ATIDictArray *>(attrib);
59  return nullptr;
60  }
62  static const GA_ATIDictArray *cast(const GA_Attribute *attrib)
63  {
64  if (attrib && &attrib->getType() == theAttributeType)
65  return static_cast<const GA_ATIDictArray *>(attrib);
66  return nullptr;
67  }
68 
69  static GA_Attribute *create(const GA_IndexMap &index_map,
70  GA_AttributeScope scope,
71  const UT_StringHolder &name,
73  *attribute_options = nullptr);
74  static GA_Attribute *create(const GA_IndexMap &index_map,
75  const UT_StringHolder &name)
76  { return create(index_map, GA_SCOPE_PUBLIC, name); }
77 
79  const GA_IndexMap &index_map,
80  GA_AttributeScope scope,
81  const UT_StringHolder &name,
82  int tuple_size);
83  ~GA_ATIDictArray() override;
84 
85  // AIFCopyData is implemented in GA_ATIBlob.
87  { return myAIFSharedDictArray; }
88 
89  /// @section JSON-GA_ATIDictArray JSON Schema: GA_ATIDictArray
90  /// @code
91  /// {
92  /// "name" : "GA_ATIDictArray",
93  /// "description" : "An tuple array of indexed strings",
94  /// "type" : "orderedmap",
95  /// "properties": {
96  /// "storage": {
97  /// "type" : "string",
98  /// "description" : "Tuple storage",
99  /// "enum" : [ "int8", "int16", "int32", "int64" ],
100  /// },
101  /// "strings": {
102  /// "type" : { "$ref":"GA_BlobData", },
103  /// "description" : "Array of strings used in the attribute",
104  /// },
105  /// "indices": {
106  /// "type" : {"$ref":"GA_DataArrayTuple"},
107  /// "description" : "Int index for each element of the array",
108  /// },
109  /// },
110  /// }
111  /// @endcode
112  /// @see @ref JSON_FileFormat
113  const GA_AIFJSON *getAIFJSON() const override { return myAIFJSON; }
114 
115  /// @{
116  /// Get a string
117  void getDict(UT_Array<UT_OptionsHolder> &strings, GA_Offset offset) const;
118  void getDictIndex(UT_Array<GA_DictIndexType> &indices, GA_Offset offset) const;
119  /// @}
120  /// @{
121  /// Set a string
122  void setDict(GA_Offset offset, const UT_Array<UT_OptionsHolder> &strings);
123  void setDictIndex(GA_Offset offset, const UT_Array<GA_DictIndexType> &indices);
124  /// @}
125 
126 protected:
127  // Create a new ATIBlob
128  GA_Attribute *doClone(const GA_IndexMap &index_map,
129  const UT_StringHolder &name) const override;
130 private:
131  UT_OptionsHolder lookupDict(GA_StringIndexType handle) const;
132  UT_OptionsHolder lookupOrderedDict(exint handle) const;
133  GA_DictIndexType lookupHandle(const UT_OptionsRef &s) const;
134  GA_DictIndexType validateHandle(GA_DictIndexType h) const;
135  bool replaceDict(GA_DictIndexType handle,
136  const UT_OptionsHolder &s);
137 
138  /// @{ GA_AIFDictTuple
139  /// @warning If you call addDictReference(), at some point, you must call
140  /// delHandleReference() on the string you added.
141  GA_DictIndexType addDictReference(const UT_OptionsHolder &s);
142  void delHandleReference(GA_DictIndexType handle);
143  bool tupleGet(GA_Offset di, GA_DictIndexType &v, int vi) const;
144  bool tupleSet(GA_Offset di, GA_DictIndexType v, int vi);
145  /// @}
146 
147  static GA_AIFSharedDictArray *myAIFSharedDictArray;
148  static GA_AIFJSON *myAIFJSON;
149 
150  static const GA_AttributeType *theAttributeType;
151 
152  /// @cond INTERNAL_DOX
153  friend class ga_DictArray;
154  friend class ga_DictJSON;
155  friend class GA_ATIDictArrayDelayedWriter;
156  /// @endcond
157 };
158 
159 //
160 // Designed to delay all the reference count adjustments
161 // until this object is flushed. Also maintains a local
162 // table for looking up the string indices with, thus avoiding
163 // concurrency issues.
164 //
166 {
167 public:
171 
172  void bind(GA_ATIDictArray *attrib);
173 
174 
175  // The index cache is provided to avoid having to potentially resize
176  // this inside this function.
178  // Directly set the index.
179  void setDictIndex(GA_Offset offset, const UT_Array<GA_DictIndexType> &idx);
180 
181  void flush();
182 
184  {
185  return myHasChanges;
186  }
187 
188 private:
189  void setDict(GA_Offset offset, const UT_OptionsHolder *strings, exint n, UT_Array<GA_DictIndexType> &indexcache);
190 
191  GA_ATIDictArray *myAttribute;
192  volatile bool myHasChanges;
193 
194  UT_ArrayMap<GA_DictIndexType, exint> myRefCountChanges;
196 };
197 
198 #endif
GLdouble s
Definition: glew.h:1390
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
static SYS_FORCE_INLINE const GA_AttributeType & getType()
static SYS_FORCE_INLINE const GA_ATIDictArray * cast(const GA_Attribute *attrib)
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
GLuint const GLchar * name
Definition: glew.h:1814
const GA_AIFJSON * getAIFJSON() const override
int64 exint
Definition: SYS_Types.h:125
static SYS_FORCE_INLINE GA_ATIDictArray * cast(GA_Attribute *attrib)
#define GA_API
Definition: GA_API.h:12
const GLdouble * v
Definition: glew.h:1391
Standard user attribute level.
Definition: GA_Types.h:147
GA_Size GA_Offset
Definition: GA_Types.h:639
GA_AttributeScope
Definition: GA_Types.h:141
GA_BlobIndex GA_DictIndexType
GLuint GLuint GLsizei GLenum const void * indices
Definition: glew.h:1253
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
static GA_Attribute * create(const GA_IndexMap &index_map, const UT_StringHolder &name)
SYS_FORCE_INLINE bool hasChanges() const
GLsizei n
Definition: glew.h:4040
GLsizei const GLchar *const * strings
Definition: glew.h:5883
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
static void registerType()
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:204
const GA_AIFSharedDictArray * getAIFSharedDictArray() const override
Return the attribute's shared options tuple interface or NULL.
A simple ATI to store aribtrary "blobs" of data in an attribute.
A specialization of GA_AIFDictArray to access "shared strings".
GA_BlobIndex GA_StringIndexType
static GA_Attribute * create(const GA_IndexMap &index_map, GA_AttributeScope scope, const UT_StringHolder &name, const GA_AttributeOptions *attribute_options=NULL)
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
GA_Attribute * doClone(const GA_IndexMap &index_map, const UT_StringHolder &name) const override
Create a new ATIBlob attribute. Sub-classes must implement this.
GLintptr offset
Definition: glew.h:1682