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 
81 #define IMPL_GET(TYPE, METHOD) \
82  TYPE METHOD(GT_Offset off, int idx) const override { \
83  auto offcount = myCounts.getOffsetCount(off); \
84  if (offcount.second == 0) return 0; /* empty array */ \
85  return myData->METHOD(offcount.first, idx); \
86  } \
87  /* end macro */
88  IMPL_GET(fpreal16, getF16);
89  IMPL_GET(fpreal32, getF32);
90  IMPL_GET(fpreal64, getF64);
91  IMPL_GET(uint8, getU8);
92  IMPL_GET(int16, getI16);
93  IMPL_GET(int32, getI32);
94  IMPL_GET(int64, getI64);
95  IMPL_GET(GT_String, getS);
96  IMPL_GET(GT_Offset, getStringIndex);
97  IMPL_GET(GT_Dict, getDict);
98  IMPL_GET(GT_Offset, getDictIndex);
99 #undef IMPL_GET
100  GT_Size getStringIndexCount() const override
101  { return myData->getStringIndexCount(); }
103  UT_IntArray &indices) const override
104  { return myData->getIndexedStrings(strings, indices); }
105 
106  // TODO: Add support for indexed strings
107 
110  GT_Offset start, GT_Size length) const override;
111 
112  GT_Size getDictIndexCount() const override
113  { return myData->getDictIndexCount(); }
115  UT_IntArray &indices) const override
116  { return myData->getIndexedDicts(dicts, indices); }
117 
120  GT_Offset start, GT_Size length) const override;
121 
122  /// @{
123  /// Array accessors
124  bool getSA(UT_StringArray &a, GT_Offset off) const override;
125  bool getDictA(UT_Array<UT_OptionsHolder> &a, GT_Offset offset) const override;
126  bool getFA16(UT_ValArray<fpreal16> &a, GT_Offset off) const override
127  { return arrayImport(a, off); }
128  bool getFA32(UT_ValArray<fpreal32> &a, GT_Offset off) const override
129  { return arrayImport(a, off); }
130  bool getFA64(UT_ValArray<fpreal64> &a, GT_Offset off) const override
131  { return arrayImport(a, off); }
132  bool getUA8(UT_ValArray<uint8> &a, GT_Offset off) const override
133  { return arrayImport(a, off); }
134  bool getIA8(UT_ValArray<int8> &a, GT_Offset off) const override
135  { return arrayImport(a, off); }
136  bool getIA16(UT_ValArray<int16> &a, GT_Offset off) const override
137  { return arrayImport(a, off); }
138  bool getIA32(UT_ValArray<int32> &a, GT_Offset off) const override
139  { return arrayImport(a, off); }
140  bool getIA64(UT_ValArray<int64> &a, GT_Offset off) const override
141  { return arrayImport(a, off); }
142  void doImportArray(GT_Offset off, UT_ValArray<fpreal16> &a) const override
143  { arrayImport(a, off); }
144  void doImportArray(GT_Offset off, UT_ValArray<fpreal32> &a) const override
145  { arrayImport(a, off); }
146  void doImportArray(GT_Offset off, UT_ValArray<fpreal64> &a) const override
147  { arrayImport(a, off); }
148  void doImportArray(GT_Offset off, UT_ValArray<uint8> &a) const override
149  { arrayImport(a, off); }
150  void doImportArray(GT_Offset off, UT_ValArray<int8> &a) const override
151  { arrayImport(a, off); }
152  void doImportArray(GT_Offset off, UT_ValArray<int16> &a) const override
153  { arrayImport(a, off); }
154  void doImportArray(GT_Offset off, UT_ValArray<int32> &a) const override
155  { arrayImport(a, off); }
156  void doImportArray(GT_Offset off, UT_ValArray<int64> &a) const override
157  { arrayImport(a, off); }
158  /// @}
159 
160 protected:
161  /// Extract an array of a given type. Implemented for fpreal16/32/64
162  /// int16/32/64.
163  ///
164  /// The size of the array returned by arrayImport() will be
165  /// itemSize()*getTupleSize() scalar values.
166  template <typename T> bool
167  arrayImport(UT_ValArray<T> &a, GT_Offset offset) const;
168 
170 };
171 
172 #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.
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:203
GT_DataArrayHandle myData
Definition: GT_DAInherit.h:179
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
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:118
void doImportArray(GT_Offset off, UT_ValArray< int32 > &a) 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:156
virtual void fillDictionaryArray(UT_Array< UT_OptionsHolder > &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:234
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:123
Definition: format.h:895
const GT_DataArrayHandle & values() const