HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAVaryingArray.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: GT_DAVaryingArray.h (GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAVaryingArray__
12 #define __GT_DAVaryingArray__
13 
14 #include "GT_API.h"
15 #include "GT_CountArray.h"
16 #include "GT_DAInherit.h"
17 
18 /// A array of arrays as values. Each item is an array of 0 or more items.
20 {
21 public:
23  : GT_DAInherit()
24  , myCounts()
25  {
26  }
27 
28  /// The values passed in are a run of values for all the entries of all the
29  /// arrays. The counts array is the number of elements in each array.
30  /// For example: @code
31  /// int values := { 0, 1, 2, 0, 1, 2, 3, 4, 5 };
32  /// counts := { 3, 0, 5}
33  /// @endcode
34  /// Will define an data array of three entries. Each entry will be an
35  /// array of integers: @code
36  /// this[0] = { 0, 1, 2 }
37  /// this[1] = {}
38  /// this[2] = { 0, 1, 2, 3, 4, 5 }
39  /// @endcode
41  const GT_CountArray &counts)
42  : GT_DAInherit(values)
43  , myCounts(counts)
44  {
45  // Currently, we can't have nested array attributes
46  UT_ASSERT(!values || !values->hasArrayEntries());
47  UT_ASSERT((!values && counts.sumCounts() == 0)
48  || (values && values->entries() == counts.sumCounts()));
49  }
50 
51  ~GT_DAVaryingArray() override;
52 
53  const char *className() const override { return "GT_DAVaryingArray"; }
54  bool isValid() const override
55  {
56  return myData
57  && myData->isValid()
58  && !myData->hasArrayEntries()
59  && myData->entries() == myCounts.sumCounts();
60  }
61 
62  const GT_DataArrayHandle &values() const { return myData; }
63  const GT_CountArray &counts() const { return myCounts; }
64  /// Return the number of elements in the array for the given item
65  GT_Size itemSize(GT_Offset offset) const override
66  {
67  return myCounts.getCount(offset);
68  }
69 
70  exint getMemoryUsage() const override
71  {
72  return myData->getMemoryUsage() + myCounts.getMemoryUsage();
73  }
74  bool hasArrayEntries() const override { return true; }
75  GT_Size entries() const override { return myCounts.entries(); }
76  GT_Size getTotalArrayEntries() const override
77  {
78  return myCounts.sumCounts();
79  }
80  bool isSameIndirection(const GT_DataArray &base) const override
81  {
82  auto *other = dynamic_cast<const GT_DAVaryingArray *>(&base);
83  return other
84  && other->myCounts.isEqual(myCounts)
85  && myData->isSameIndirection(*other->myData);
86  }
87 #define IMPL_GET(TYPE, METHOD) \
88  TYPE METHOD(GT_Offset off, int idx) const override { \
89  auto offcount = myCounts.getOffsetCount(off); \
90  if (offcount.second == 0) return 0; /* empty array */ \
91  return myData->METHOD(offcount.first, idx); \
92  } \
93  /* end macro */
94  IMPL_GET(fpreal16, getF16);
95  IMPL_GET(fpreal32, getF32);
96  IMPL_GET(fpreal64, getF64);
97  IMPL_GET(uint8, getU8);
98  IMPL_GET(int16, getI16);
99  IMPL_GET(int32, getI32);
100  IMPL_GET(int64, getI64);
101  IMPL_GET(GT_String, getS);
102  IMPL_GET(GT_Offset, getStringIndex);
103  IMPL_GET(GT_Dict, getDict);
104  IMPL_GET(GT_Offset, getDictIndex);
105 #undef IMPL_GET
106  GT_Size getStringIndexCount() const override
107  { return myData->getStringIndexCount(); }
109  UT_IntArray &indices) const override
110  { return myData->getIndexedStrings(strings, indices); }
111 
112  // TODO: Add support for indexed strings
113 
116  GT_Offset start, GT_Size length) const override;
117 
118  GT_Size getDictIndexCount() const override
119  { return myData->getDictIndexCount(); }
121  UT_IntArray &indices) const override
122  { return myData->getIndexedDicts(dicts, indices); }
123 
126  GT_Offset start, GT_Size length) const override;
127 
128  /// @{
129  /// Array accessors
130  bool getSA(UT_StringArray &a, GT_Offset off) const override;
131  bool getDictA(UT_Array<UT_OptionsHolder> &a, GT_Offset offset) const override;
132  bool getFA16(UT_ValArray<fpreal16> &a, GT_Offset off) const override
133  { return arrayImport(a, off); }
134  bool getFA32(UT_ValArray<fpreal32> &a, GT_Offset off) const override
135  { return arrayImport(a, off); }
136  bool getFA64(UT_ValArray<fpreal64> &a, GT_Offset off) const override
137  { return arrayImport(a, off); }
138  bool getUA8(UT_ValArray<uint8> &a, GT_Offset off) const override
139  { return arrayImport(a, off); }
140  bool getIA8(UT_ValArray<int8> &a, GT_Offset off) const override
141  { return arrayImport(a, off); }
142  bool getIA16(UT_ValArray<int16> &a, GT_Offset off) const override
143  { return arrayImport(a, off); }
144  bool getIA32(UT_ValArray<int32> &a, GT_Offset off) const override
145  { return arrayImport(a, off); }
146  bool getIA64(UT_ValArray<int64> &a, GT_Offset off) const override
147  { return arrayImport(a, off); }
148  void doImportArray(GT_Offset off, UT_ValArray<fpreal16> &a) const override
149  { arrayImport(a, off); }
150  void doImportArray(GT_Offset off, UT_ValArray<fpreal32> &a) const override
151  { arrayImport(a, off); }
152  void doImportArray(GT_Offset off, UT_ValArray<fpreal64> &a) const override
153  { arrayImport(a, off); }
154  void doImportArray(GT_Offset off, UT_ValArray<uint8> &a) const override
155  { arrayImport(a, off); }
156  void doImportArray(GT_Offset off, UT_ValArray<int8> &a) const override
157  { arrayImport(a, off); }
158  void doImportArray(GT_Offset off, UT_ValArray<int16> &a) const override
159  { arrayImport(a, off); }
160  void doImportArray(GT_Offset off, UT_ValArray<int32> &a) const override
161  { arrayImport(a, off); }
162  void doImportArray(GT_Offset off, UT_ValArray<int64> &a) const override
163  { arrayImport(a, off); }
164  /// @}
165 
166 protected:
167  /// Extract an array of a given type. Implemented for fpreal16/32/64
168  /// int16/32/64.
169  ///
170  /// The size of the array returned by arrayImport() will be
171  /// itemSize()*getTupleSize() scalar values.
172  template <typename T> bool
173  arrayImport(UT_ValArray<T> &a, GT_Offset offset) const;
174 
176 };
177 
178 #endif
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
GT_Size itemSize(GT_Offset offset) const override
Return the number of elements in the array for the given item.
bool isEqual(const GT_CountArray &other) const
Test equality.
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
int int32
Definition: SYS_Types.h:39
void doImportArray(GT_Offset off, UT_ValArray< uint8 > &a) const override
GT_Size getDictIndexCount() const override
virtual void fillStringArray(UT_StringArray &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:210
GT_DataArrayHandle myData
Definition: GT_DAInherit.h:200
GT_Size entries() const override
Number of entries in the array.
GLuint start
Definition: glcorearb.h:475
void getIndexedStrings(UT_StringArray &strings, UT_IntArray &indices) const override
#define GT_API
Definition: GT_API.h:13
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
bool isValid() const override
float fpreal32
Definition: SYS_Types.h:200
bool getIA16(UT_ValArray< int16 > &a, GT_Offset off) const override
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
void doImportArray(GT_Offset off, UT_ValArray< int64 > &a) const override
GT_DAVaryingArray(const GT_DataArrayHandle &values, const GT_CountArray &counts)
GLintptr offset
Definition: glcorearb.h:665
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:41
bool hasArrayEntries() const override
void doImportArray(GT_Offset off, UT_ValArray< fpreal16 > &a) const override
void doImportArray(GT_Offset off, UT_ValArray< int8 > &a) const override
GT_Size getTotalArrayEntries() const override
int64 GT_Offset
Definition: GT_Types.h:129
bool getFA64(UT_ValArray< fpreal64 > &a, GT_Offset off) const override
bool getFA16(UT_ValArray< fpreal16 > &a, GT_Offset off) const override
long long int64
Definition: SYS_Types.h:116
GT_Size getStringIndexCount() const override
virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
Definition: GT_DataArray.h:119
void doImportArray(GT_Offset off, UT_ValArray< int32 > &a) const override
bool isSameIndirection(const GT_DataArray &base) const override
bool getIA64(UT_ValArray< int64 > &a, GT_Offset off) const override
const char * className() const override
exint getMemoryUsage() const override
GLsizei const GLchar *const * strings
Definition: glcorearb.h:1933
#define IMPL_GET(TYPE, METHOD)
bool getFA32(UT_ValArray< fpreal32 > &a, GT_Offset off) const override
void getIndexedDicts(UT_Array< UT_OptionsHolder > &dicts, UT_IntArray &indices) const override
int64 GT_Size
Definition: GT_Types.h:128
bool getIA32(UT_ValArray< int32 > &a, GT_Offset off) const override
void doImportArray(GT_Offset off, UT_ValArray< int16 > &a) const override
Base class for a data array which references another data array.
Definition: GT_DAInherit.h:18
bool getUA8(UT_ValArray< uint8 > &a, GT_Offset off) const override
void doImportArray(GT_Offset off, UT_ValArray< fpreal64 > &a) const override
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
short int16
Definition: SYS_Types.h:37
const GT_CountArray & counts() const
A array of arrays as values. Each item is an array of 0 or more items.
GT_CountArray myCounts
bool getIA8(UT_ValArray< int8 > &a, GT_Offset off) const override
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
virtual void fillDictionaryArray(UT_Array< UT_OptionsHolder > &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:247
void doImportArray(GT_Offset off, UT_ValArray< fpreal32 > &a) const override
GT_Size sumCounts() const
Return the sum of all the counts.
virtual bool getDictA(UT_Array< UT_OptionsHolder > &a, GT_Offset offset) const
Definition: GT_DataArray.h:124
Definition: format.h:1821
const GT_DataArrayHandle & values() const