HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeArray.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_ATTRIBUTE_ARRAY_H__
10 #define __PDG_ATTRIBUTE_ARRAY_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeData.h"
15 #include "PDG_AttributeTypes.h"
16 
17 #include <UT/UT_StringMap.h>
18 #include <UT/UT_ValArray.h>
19 
20 /**
21  * Base template for array attribute types
22  */
24  typename DataType,
27 {
28 public:
29  static constexpr PDG_AttributeType TypeEnum = AttribType;
30 
32  using Data = DataType;
33  using Array = ArrayType;
36 
39  {
40  }
41 
44  , myData(data)
45  {
46  }
47 
48  ~PDG_AttributeArray() override {}
49 
50  inline bool hasData() const
51  {
52  return (myData.size() > 0);
53  }
54 
55  inline int size() const
56  {
57  return myData.size();
58  }
59 
60  inline bool valid(int component) const
61  {
62  return (component >= 0) && (component < myData.size());
63  }
64 
65  inline bool value(DataType& data, int component) const
66  {
67  int real_index = component;
68 
69  if (real_index < 0)
70  real_index += size();
71 
72  if (!valid(real_index))
73  return false;
74 
75  data = myData[real_index];
76  return true;
77  }
78 
79  inline const DataType& value(int component) const
80  {
81  return myData[component];
82  }
83 
84  inline DataType& value(int component)
85  {
86  return myData[component];
87  }
88 
89  inline void setValue(const ArrayType& data)
90  {
91  myData = data;
92  }
93 
94  inline void setValue(const ArrayType&& data)
95  {
96  myData = data;
97  }
98 
99  inline void setValue(const DataType& value, int component)
100  {
101  expand(value, component);
102  }
103 
104  inline void setValues(const ArrayType& data)
105  {
106  myData.setSizeIfNeeded(data.size());
107  for (exint i = 0; i < data.size(); i++)
108  myData[i] = data[i];
109  }
110 
111  inline const DataType& appendValue(const DataType& value)
112  {
113  myData.append(value);
114  return myData.last();
115  }
116 
117  inline const ArrayType& values() const
118  {
119  return myData;
120  }
121 
122  inline ArrayType& values()
123  {
124  return myData;
125  }
126 
127  inline void clear()
128  {
129  myData.clear();
130  }
131 
132  inline void truncate(int length)
133  {
134  myData.truncate(length);
135  }
136 
137  inline bool concat(const Self* other)
138  {
139  myData.concat(other->myData);
140  return true;
141  }
142 
143  inline bool adjustSize(int offset)
144  {
145  myData.setSize(myData.size() + offset);
146  return true;
147  }
148 
149  inline bool setSize(int size)
150  {
151  myData.setSize(size);
152  return true;
153  }
154 
156  UT_WorkBuffer& errors) const override
157  {
158  hash_value = SYShashRange(myData.begin(), myData.end());
159  return true;
160  }
161 
162  inline void swap(Self* other)
163  {
164  myData.swap(other->myData);
165  }
166 
167  inline void copy(const Self* other)
168  {
169  myData = other->myData;
170  }
171 
172  bool compare(
173  const PDG_AttributeData* other) const override
174  {
175  return ((const Self*)(other))->myData == myData;
176  }
177 
179  int stride) override
180  {
181  return PDG_AttributeData::merge(myData, merge_op, stride);
182  }
183 
184 protected:
185  void expand(const DataType& value, int component)
186  {
187  if (component < 0)
188  {
189  myData.append(value);
190  }
191  else
192  {
193  myData.setSizeIfNeeded(component+1);
194  myData[component] = value;
195  }
196  }
197 
199  const DataType& default_value,
200  int component)
201  {
202  if (component < 0)
203  {
204  myData.append(default_value);
205  }
206  else if (component >= myData.size())
207  {
208  myData.setSizeIfNeeded(component+1);
209  myData[component] = default_value;
210  }
211  }
212 
213 protected:
215 };
216 
217 #endif
DataType & value(int component)
GLboolean * data
Definition: glcorearb.h:131
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void setValues(const ArrayType &data)
int64 exint
Definition: SYS_Types.h:125
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
void setValue(const DataType &value, int component)
void truncate(int length)
const DataType & value(int component) const
void copy(const Self *other)
const ArrayType & values() const
bool concat(const Self *other)
GLintptr offset
Definition: glcorearb.h:665
const DataType & appendValue(const DataType &value)
void setValue(const ArrayType &&data)
void setValue(const ArrayType &data)
virtual PDG_AttributeMergeError merge(PDG_AttributeMergeOp merge_op, int stride)=0
Applies a merge op to the data in this attribute.
PDG_AttributeArray(const ArrayType &data)
bool hash(SYS_HashType &hash_value, UT_WorkBuffer &errors) const override
Return a hash value derived from the attribute data.
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
#define PDG_API_TMPL
Definition: PDG_API.h:24
bool valid(int component) const
void expand(const DataType &value, int component)
PDG_AttributeType
Enumeration of possible attribute types.
~PDG_AttributeArray() override
PDG_AttributeMergeOp
Enumeration of different ways that attributes can be combined.
uint8_t ArrayType
Definition: NanoVDB.h:5566
bool adjustSize(int offset)
GLsizeiptr size
Definition: glcorearb.h:664
void expandIfNeeded(const DataType &default_value, int component)
bool setSize(int size)
bool value(DataType &data, int component) const
void swap(Self *other)
PDG_AttributeMergeError
Enumerations of errors that can occur when merging attributes.
Definition: core.h:1131
PDG_AttributeMergeError merge(PDG_AttributeMergeOp merge_op, int stride) override
Applies a merge op to the data in this attribute.
size_t hash_value(const CH_ChannelRef &ref)
bool compare(const PDG_AttributeData *other) const override
Compares this data object with another data object.
Definition: format.h:895