HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~GA_ATIBlindData() override;
99 
100  /// Report memory usage
101  int64 getMemoryUsage(bool inclusive) const override;
102 
103  void countMemory(UT_MemoryCounter &counter, bool inclusive) const override;
104 
105  /// @{
106  /// Interface for defragmentation
107  void defragment(const GA_Defragment &defrag) override;
108  /// @}
109 
110  /// Supports concurrent writes to separate elements.
112  { return WRITE_CONCURRENCE_ELEMENT; }
113 
114  const GA_AIFStat *getAIFStat() const override
115  { return myAIFStat; }
116  const GA_AIFBlindData *getAIFBlindData() const override
117  { return myAIFBlindData; }
118  const GA_AIFCopyData *getAIFCopyData() const override
119  {
120  return myCopyFlag
121  ? myAIFCopyData
122  : NULL;
123  }
125  {
126  return myAIFCopyData;
127  }
128  const GA_AIFCompare *getAIFCompare() const override
129  {
130  return myAIFCompare;
131  }
132  const GA_AIFMerge *getAIFMerge() const override;
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  const GA_AIFJSON *getAIFJSON() const override { return myAIFJSON; }
175 
176  /// Grow data
177  bool setArraySize(GA_Offset new_size) override;
178 
179  /// Compressing data pages is not applicable to blind data,
180  /// so this does nothing.
182  GA_Offset start_offset = GA_Offset(0),
183  GA_Offset end_offset = GA_INVALID_OFFSET) override {}
184  /// Hardening data pages is not applicable to blind data,
185  /// so this does nothing.
187  GA_Offset start_offset = GA_Offset(0),
188  GA_Offset end_offset = GA_INVALID_OFFSET) override {}
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  bool matchesStorage(const GA_Attribute *that) const override
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  void copyNonStorageMetadata(const GA_Attribute *that) override
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  void replace(const GA_Attribute &src) override;
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  GA_Attribute *doClone(const GA_IndexMap &index_map,
240  const UT_StringHolder &name) const override;
241 
242  /// Re-initialize data for a deleted element
244  GA_Offset offset, GA_Offset nelements) override;
245 private:
246  void setDefault(const void *data, GA_Size size);
247  bool growArraySize(GA_Offset new_size);
248  void growDataSize(GA_Size size=-1, GA_Size align=-1);
249  GA_Size getDataSize() const { return mySize; }
250  GA_Size getAlignedSize() const { return myAlignSize; }
251  GA_Size getAlignment() const { return myAlignment; }
252  bool getCopyFlag() const { return myCopyFlag; }
253  void setCopyFlag(bool f) { myCopyFlag = f; }
254  bool getLittleEndian() const { return myLittleEndian; }
255  void swapEndian() { myLittleEndian = !myLittleEndian; }
256  bool copyData(GA_Offset di,
257  const GA_ATIBlindData &src, GA_Offset si);
258  bool copyData(const GA_Range &di,
259  const GA_ATIBlindData &src, const GA_Range &si);
260  bool isEqual(GA_Offset di,
261  const GA_ATIBlindData &src,
262  GA_Offset si) const;
263  bool isEqual(const GA_Range &di,
264  const GA_ATIBlindData &src,
265  const GA_Range &si) const;
266 
267  void mergeDestroyDestination(const GA_MergeMap &map,
268  GA_Attribute *dattrib) const;
269  GA_Attribute *mergeAddDestination(const GA_MergeMap &map,
270  GA_Attribute *dattrib) const;
271  bool mergeAppendData(const GA_MergeMap &map,
272  const GA_ATIBlindData *sattrib);
273 
274  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &s) const;
275  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &map,
276  GA_Size size,
277  GA_Size alignment,
278  bool endian);
279 
280  static GA_AIFBlindData *myAIFBlindData;
281  static GA_AIFCopyData *myAIFCopyData;
282  static GA_AIFStat *myAIFStat;
283  static GA_AIFJSON *myAIFJSON;
284  static GA_AIFCompare *myAIFCompare;
285  static GA_AIFMerge *myAIFMerge;
286 
287  static const GA_AttributeType *theAttributeType;
288 
289  GA_Size mySize;
290  GA_Size myAlignSize;
291  GA_Size myDefaultSize;
292  GA_Size myAlignment;
293  GA_Offset myElementCapacity;
294  uint8 *myData;
295  uint8 *myDefault;
296  bool myCopyFlag;
297  bool myLittleEndian;
298 
299  /// @cond INTERNAL_DOX
300  friend class ga_BlindDataAccess;
301  friend class ga_BlindCopyData;
302  friend class ga_BlindDataStat;
303  friend class ga_BlindJSON;
304  friend class ga_BlindCompare;
305  friend class ga_BlindMerge;
306  /// @endcond
307 };
308 
309 #endif
const GA_AIFBlindData * getAIFBlindData() const override
Return the attribute's blind data interface or NULL.
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:198
WriteConcurrence getSupportedWriteConcurrence() const override
Supports concurrent writes to separate elements.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
static SYS_FORCE_INLINE const GA_AttributeType & getType()
void hardenAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET) override
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements)=0
static SYS_FORCE_INLINE const GA_ATIBlindData * cast(const GA_Attribute *attrib)
const GA_AIFCompare * getAIFCompare() const override
Return the attribute's comparison interface or NULL.
GLdouble s
Definition: glad.h:3009
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
virtual bool setArraySize(GA_Offset size)=0
#define GA_API
Definition: GA_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
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:751
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:236
SYS_FORCE_INLINE const GA_AttributeType & getType() const
Definition: GA_Attribute.h:206
bool matchesStorage(const GA_Attribute *that) const override
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
Concurrent writes to separate elements supported.
Definition: GA_Attribute.h:369
A range of elements in an index-map.
Definition: GA_Range.h:42
unsigned char uint8
Definition: SYS_Types.h:36
GA_Size GA_Offset
Definition: GA_Types.h:646
GA_AttributeScope
Definition: GA_Types.h:143
GLfloat f
Definition: glcorearb.h:1926
void copyNonStorageMetadata(const GA_Attribute *that) override
GLintptr offset
Definition: glcorearb.h:665
virtual void replace(const GA_Attribute &src)=0
Attribute Interface for merging attribute data between details.
Definition: GA_AIFMerge.h:56
static SYS_FORCE_INLINE GA_ATIBlindData * cast(GA_Attribute *attrib)
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const GA_AIFCopyData * getAIFCopyData() const override
Return the attribute's copy interface or NULL.
Class to fill GA_Stat information about an attribute. This AIF is used to fill GA_Stat type informati...
Definition: GA_AIFStat.h:30
long long int64
Definition: SYS_Types.h:116
const GA_AIFJSON * getAIFJSON() const override
Attribute Interface class to perform comparisons on attributes.
Definition: GA_AIFCompare.h:27
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void copyNonStorageMetadata(const GA_Attribute *that)
Definition: GA_Attribute.h:765
virtual const GA_AIFMerge * getAIFMerge() const
Return the attribute's merge interface or NULL.
GLsizeiptr size
Definition: glcorearb.h:664
A map of string to various well defined value types.
Definition: UT_Options.h:84
endian
Definition: platform.h:532
Attribute Interface for blind data per element.
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
Attribute Interface class to copy attribute data.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
const GA_AIFCopyData * getAIFCopyDataAnyway() const
type
Definition: core.h:1059
virtual void defragment(const GA_Defragment &defrag)=0
Definition: format.h:895
Definition: format.h:2459
const GA_AIFStat * getAIFStat() const override
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
void tryCompressAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET) override
GLenum src
Definition: glcorearb.h:1793