HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_ATIBlindData.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_ATIBlindData.h ( GA Library, C++)
7  *
8  * COMMENTS: Blind Data ATI (Attribute Type Implementation)
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_ATIBlindData__
14 #define __GA_ATIBlindData__
15 
16 #include "GA_API.h"
17 #include "GA_Attribute.h"
18 #include "GA_AttributeType.h" // for GA_AttributeType
19 #include "GA_Types.h" // for GA_Size, GA_Offset, etc
20 #include <UT/UT_StringHolder.h>
21 #include <SYS/SYS_Types.h> // for uint8, int64
22 
23 #include <stddef.h> // for NULL
24 
25 
26 class GA_AIFBlindData;
27 class GA_AIFCompare;
28 class GA_AIFCopyData;
29 class GA_AIFJSON;
30 class GA_AIFMerge;
31 class GA_AIFStat;
32 class GA_Defragment;
33 class GA_IndexMap;
34 class GA_LoadMap;
35 class GA_MergeMap;
36 class GA_Range;
37 class GA_SaveMap;
38 
39 class UT_JSONParser;
40 class UT_JSONWriter;
41 class UT_Options;
42 
43 
44 /// @brief Attribute type implementation to store blind data per element
45 ///
46 /// This attribute type allocates a chunk of data per element (point, vertex or
47 /// detail). The data is typeless. Users can write any data to this
48 ///
49 /// Creation options may contain:
50 /// "blinddata:size" - The initial size of the attribute (default 0)
51 /// "blinddata:align" - The initial alignment (default sizeof(void *))
52 /// "blinddata:copy" - Copy data from element to element (default false)
54 {
55 public:
56  static void registerType();
58  static const UT_StringHolder &getTypeName()
59  { return theAttributeType->getTypeName(); }
61  static const GA_AttributeType &getType() { return *theAttributeType; }
62 
64  static bool isType(const GA_Attribute *attrib)
65  {
66  return attrib && &attrib->getType() == theAttributeType;
67  }
70  {
71  if (attrib && &attrib->getType() == theAttributeType)
72  return static_cast<GA_ATIBlindData *>(attrib);
73  return NULL;
74  }
76  static const GA_ATIBlindData *cast(const GA_Attribute *attrib)
77  {
78  if (attrib && &attrib->getType() == theAttributeType)
79  return static_cast<const GA_ATIBlindData *>(attrib);
80  return NULL;
81  }
82  static GA_Attribute *create(const GA_IndexMap &index_map,
83  GA_AttributeScope scope,
84  const UT_StringHolder &name,
85  GA_Size bytes=-1,
86  GA_Size align=-1,
87  const GA_AttributeOptions *attribute_options=NULL);
88 
89  /// Create blind data attribute
91  const GA_IndexMap &index_map,
92  GA_AttributeScope scope,
93  const UT_StringHolder &name,
94  GA_Size size,
95  GA_Size align,
96  bool copy_flag,
97  bool little_endian);
98  virtual ~GA_ATIBlindData();
99 
100  /// Report memory usage
101  virtual int64 getMemoryUsage(bool inclusive) const;
102 
103  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
104 
105  /// @{
106  /// Interface for defragmentation
107  virtual void defragment(const GA_Defragment &defrag);
108  /// @}
109 
110  /// Supports concurrent writes to separate elements.
112  { return WRITE_CONCURRENCE_ELEMENT; }
113 
114  virtual const GA_AIFStat *getAIFStat() const
115  { return myAIFStat; }
116  virtual const GA_AIFBlindData *getAIFBlindData() const
117  { return myAIFBlindData; }
118  virtual const GA_AIFCopyData *getAIFCopyData() const
119  {
120  return myCopyFlag
121  ? myAIFCopyData
122  : NULL;
123  }
125  {
126  return myAIFCopyData;
127  }
128  virtual const GA_AIFCompare *getAIFCompare() const
129  {
130  return myAIFCompare;
131  }
132  virtual const GA_AIFMerge *getAIFMerge() const;
133 
134  /// @section JSON-GA_ATIBlindData JSON Schema: GA_ATIBlindData
135  /// @code
136  /// {
137  /// "name" : "GA_ATIBlindData",
138  /// "description" : "An array of blind data",
139  /// "type" : "orderedmap",
140  /// "properties": {
141  /// "size": {
142  /// "type" : "integer",
143  /// "minimum" : 1,
144  /// "description" : "Bytes per element",
145  /// },
146  /// "alignment": {
147  /// "type" : "integer",
148  /// "description" : "Data alignment: 0 indicates sizeof(void*)",
149  /// },
150  /// "defaultsize": {
151  /// "type" : "integer",
152  /// "minimum" : 1,
153  /// "description" : "Bytes stored in the defualt",
154  /// },
155  /// "endian": {
156  /// "type" : "string",
157  /// "description" : "Endian storage of binary data",
158  /// "enum" : [ "little", "big" ],
159  /// },
160  /// "defaults": {
161  /// "type" : "array",
162  /// "description" : "binary data (bytes)",
163  /// "items" : "number",
164  /// },
165  /// "values": {
166  /// "type" : "array",
167  /// "description" : "binary data (bytes)",
168  /// "items" : "number",
169  /// },
170  /// },
171  /// }
172  /// @endcode
173  /// @see @ref JSON_FileFormat
174  virtual const GA_AIFJSON *getAIFJSON() const { return myAIFJSON; }
175 
176  /// Grow data
177  virtual bool setArraySize(GA_Offset new_size);
178 
179  /// Compressing data pages is not applicable to blind data,
180  /// so this does nothing.
181  virtual void tryCompressAllPages(
182  GA_Offset start_offset = GA_Offset(0),
183  GA_Offset end_offset = GA_INVALID_OFFSET) {}
184  /// Hardening data pages is not applicable to blind data,
185  /// so this does nothing.
186  virtual void hardenAllPages(
187  GA_Offset start_offset = GA_Offset(0),
188  GA_Offset end_offset = GA_INVALID_OFFSET) {}
189 
190  /// Returns true iff that is an attribute whose content can be copied
191  /// from this without any type conversions. This is important to
192  /// avoid reallocation of an attribute if its storage type,
193  /// including tuple size, matches the source attribute exactly.
194  virtual bool matchesStorage(const GA_Attribute *that) const
195  {
196  if (!GA_Attribute::matchesStorage(that))
197  return false;
198  const GA_ATIBlindData *thatn = UTverify_cast<const GA_ATIBlindData *>(that);
199  if (getDataSize() != thatn->getDataSize())
200  return false;
201  if (getAlignedSize() != thatn->getAlignedSize())
202  return false;
203  if (getAlignment() != thatn->getAlignment())
204  return false;
205  return true;
206  }
207  /// In the case that we're copying from an attribute whose storage
208  /// type matches this exactly, this function copies the metadata
209  /// not associated with the storage, e.g. myOptions,
210  /// *excluding* the name and the data ID.
211  virtual void copyNonStorageMetadata(const GA_Attribute *that)
212  {
214  const GA_ATIBlindData *thatn = UTverify_cast<const GA_ATIBlindData *>(that);
215  myCopyFlag = thatn->myCopyFlag;
216  myLittleEndian = thatn->myLittleEndian;
217  setDefault(thatn->myDefault, thatn->myDefaultSize);
218  }
219 
220  /// This replaces the entirety of this attribute's content and non-
221  /// storage metadata (except the name) with that of the src attribute.
222  /// The matchesStorage(src) should already return true.
223  /// This is primarily for use by GA_AttributeSet::replace().
224  /// NOTE: The internal content sizes may not match exactly if the
225  /// attribute type may overallocate, but the sizes should be such
226  /// that any real data will fit in the destination, so be careful
227  /// and deal with the myTailInitialize flag appropriately if
228  /// any extra elements aren't equal to the default.
229  virtual void replace(const GA_Attribute &src);
230 
231  /// Get read-only access to the data for the specified offset
232  const void *getRead(GA_Offset offset) const;
233 
234  /// Get read-write access to the data for the specified offset
235  void *getWrite(GA_Offset offset);
236 
237 protected:
238  // Create a new ATI_BlindData
239  virtual GA_Attribute *doClone(const GA_IndexMap &index_map,
240  const UT_StringHolder &name) const;
241 
242  /// Re-initialize data for a deleted element
243  virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements);
244 private:
245  void setDefault(const void *data, GA_Size size);
246  bool growArraySize(GA_Offset new_size);
247  void growDataSize(GA_Size size=-1, GA_Size align=-1);
248  GA_Size getDataSize() const { return mySize; }
249  GA_Size getAlignedSize() const { return myAlignSize; }
250  GA_Size getAlignment() const { return myAlignment; }
251  bool getCopyFlag() const { return myCopyFlag; }
252  void setCopyFlag(bool f) { myCopyFlag = f; }
253  bool getLittleEndian() const { return myLittleEndian; }
254  void swapEndian() { myLittleEndian = !myLittleEndian; }
255  bool copyData(GA_Offset di,
256  const GA_ATIBlindData &src, GA_Offset si);
257  bool copyData(const GA_Range &di,
258  const GA_ATIBlindData &src, const GA_Range &si);
259  bool isEqual(GA_Offset di,
260  const GA_ATIBlindData &src,
261  GA_Offset si) const;
262  bool isEqual(const GA_Range &di,
263  const GA_ATIBlindData &src,
264  const GA_Range &si) const;
265 
266  void mergeDestroyDestination(const GA_MergeMap &map,
267  GA_Attribute *dattrib) const;
268  GA_Attribute *mergeAddDestination(const GA_MergeMap &map,
269  GA_Attribute *dattrib) const;
270  bool mergeAppendData(const GA_MergeMap &map,
271  const GA_ATIBlindData *sattrib);
272 
273  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &s) const;
274  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &map,
275  GA_Size size,
276  GA_Size alignment,
277  bool endian);
278 
279  static GA_AIFBlindData *myAIFBlindData;
280  static GA_AIFCopyData *myAIFCopyData;
281  static GA_AIFStat *myAIFStat;
282  static GA_AIFJSON *myAIFJSON;
283  static GA_AIFCompare *myAIFCompare;
284  static GA_AIFMerge *myAIFMerge;
285 
286  static const GA_AttributeType *theAttributeType;
287 
288  GA_Size mySize;
289  GA_Size myAlignSize;
290  GA_Size myDefaultSize;
291  GA_Size myAlignment;
292  GA_Offset myElementCapacity;
293  uint8 *myData;
294  uint8 *myDefault;
295  bool myCopyFlag;
296  bool myLittleEndian;
297 
298  /// @cond INTERNAL_DOX
299  friend class ga_BlindDataAccess;
300  friend class ga_BlindCopyData;
301  friend class ga_BlindDataStat;
302  friend class ga_BlindJSON;
303  friend class ga_BlindCompare;
304  friend class ga_BlindMerge;
305  /// @endcond
306 };
307 
308 #endif
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
virtual const GA_AIFCompare * getAIFCompare() const
Return the attribute's comparison interface or NULL.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
static SYS_FORCE_INLINE const GA_AttributeType & getType()
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
static SYS_FORCE_INLINE const GA_ATIBlindData * cast(const GA_Attribute *attrib)
virtual const GA_AIFBlindData * getAIFBlindData() const
Return the attribute's blind data interface or NULL.
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
virtual bool setArraySize(GA_Offset size)=0
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
virtual const GA_AIFCopyData * getAIFCopyData() const
Return the attribute's copy interface or NULL.
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
virtual int64 getMemoryUsage(bool inclusive) const =0
virtual bool matchesStorage(const GA_Attribute *that) const
Definition: GA_Attribute.h:680
virtual bool matchesStorage(const GA_Attribute *that) const
Attribute type implementation to store blind data per element.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GLsizeiptr size
Definition: glcorearb.h:663
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
Concurrent writes to separate elements supported.
Definition: GA_Attribute.h:340
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
GA_AttributeScope
Definition: GA_Types.h:121
GLfloat f
Definition: glcorearb.h:1925
virtual void tryCompressAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)
virtual void replace(const GA_Attribute &src)=0
Attribute Interface for merging attribute data between details.
Definition: GA_AIFMerge.h:56
virtual void copyNonStorageMetadata(const GA_Attribute *that)
static SYS_FORCE_INLINE GA_ATIBlindData * cast(GA_Attribute *attrib)
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Class to fill GA_Stat information about an attribute. This AIF is used to fill GA_Stat type informati...
Definition: GA_AIFStat.h:30
GLintptr offset
Definition: glcorearb.h:664
virtual const GA_AIFJSON * getAIFJSON() const
Attribute Interface class to perform comparisons on attributes.
Definition: GA_AIFCompare.h:27
virtual const GA_AIFStat * getAIFStat() const
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:175
virtual void copyNonStorageMetadata(const GA_Attribute *that)
Definition: GA_Attribute.h:694
virtual const GA_AIFMerge * getAIFMerge() const
Return the attribute's merge interface or NULL.
virtual WriteConcurrence getSupportedWriteConcurrence() const
Supports concurrent writes to separate elements.
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:197
A map of string to various well defined value types.
Definition: UT_Options.h:42
unsigned char uint8
Definition: SYS_Types.h:31
Attribute Interface for blind data per element.
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Attribute Interface class to copy attribute data.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
virtual void hardenAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)
const GA_AIFCopyData * getAIFCopyDataAnyway() const
virtual void defragment(const GA_Defragment &defrag)=0
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
GLenum src
Definition: glcorearb.h:1792
virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements)