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 #undef IMPL_GET
98  GT_Size getStringIndexCount() const override
99  { return myData->getStringIndexCount(); }
101  UT_IntArray &indices) const override
102  { return myData->getIndexedStrings(strings, indices); }
103 
104  // TODO: Add support for indexed strings
105 
108  GT_Offset start, GT_Size length) const override;
109 
110  /// @{
111  /// Array accessors
112  bool getSA(UT_StringArray &a, GT_Offset off) const override;
113  bool getFA16(UT_ValArray<fpreal16> &a, GT_Offset off) const override
114  { return arrayImport(a, off); }
115  bool getFA32(UT_ValArray<fpreal32> &a, GT_Offset off) const override
116  { return arrayImport(a, off); }
117  bool getFA64(UT_ValArray<fpreal64> &a, GT_Offset off) const override
118  { return arrayImport(a, off); }
119  bool getUA8(UT_ValArray<uint8> &a, GT_Offset off) const override
120  { return arrayImport(a, off); }
121  bool getIA8(UT_ValArray<int8> &a, GT_Offset off) const override
122  { return arrayImport(a, off); }
123  bool getIA16(UT_ValArray<int16> &a, GT_Offset off) const override
124  { return arrayImport(a, off); }
125  bool getIA32(UT_ValArray<int32> &a, GT_Offset off) const override
126  { return arrayImport(a, off); }
127  bool getIA64(UT_ValArray<int64> &a, GT_Offset off) const override
128  { return arrayImport(a, off); }
129  void doImportArray(GT_Offset off, UT_ValArray<fpreal16> &a) const override
130  { arrayImport(a, off); }
131  void doImportArray(GT_Offset off, UT_ValArray<fpreal32> &a) const override
132  { arrayImport(a, off); }
133  void doImportArray(GT_Offset off, UT_ValArray<fpreal64> &a) const override
134  { arrayImport(a, off); }
135  void doImportArray(GT_Offset off, UT_ValArray<uint8> &a) const override
136  { arrayImport(a, off); }
137  void doImportArray(GT_Offset off, UT_ValArray<int8> &a) const override
138  { arrayImport(a, off); }
139  void doImportArray(GT_Offset off, UT_ValArray<int16> &a) const override
140  { arrayImport(a, off); }
141  void doImportArray(GT_Offset off, UT_ValArray<int32> &a) const override
142  { arrayImport(a, off); }
143  void doImportArray(GT_Offset off, UT_ValArray<int64> &a) const override
144  { arrayImport(a, off); }
145  /// @}
146 
147 protected:
148  /// Extract an array of a given type. Implemented for fpreal16/32/64
149  /// int16/32/64.
150  ///
151  /// The size of the array returned by arrayImport() will be
152  /// itemSize()*getTupleSize() scalar values.
153  template <typename T> bool
154  arrayImport(UT_ValArray<T> &a, GT_Offset offset) const;
155 
157 };
158 
159 #endif
GT_Size itemSize(GT_Offset offset) const override
Return the number of elements in the array for the given item.
int int32
Definition: SYS_Types.h:39
void doImportArray(GT_Offset off, UT_ValArray< uint8 > &a) const override
virtual void fillStringArray(UT_StringArray &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:198
GT_DataArrayHandle myData
Definition: GT_DAInherit.h:172
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:11
int64 exint
Definition: SYS_Types.h:125
bool isValid() const override
float fpreal32
Definition: SYS_Types.h:200
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
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)
bool hasArrayEntries() const override
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
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:124
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 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
int64 GT_Size
Definition: GT_Types.h:123
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
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
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
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
bool getIA8(UT_ValArray< int8 > &a, GT_Offset off) const override
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:153
GLintptr offset
Definition: glcorearb.h:665
void doImportArray(GT_Offset off, UT_ValArray< fpreal32 > &a) const override
GT_Size sumCounts() const
Return the sum of all the counts.
Definition: format.h:895
const GT_DataArrayHandle & values() const