HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAValues.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_DAValues.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAValue__
12 #define __GT_DAValue__
13 
14 #include "GT_API.h"
15 #include "GT_DataArray.h"
16 #include <UT/UT_Assert.h>
17 
18 /// @brief An array of const values.
19 ///
20 /// The data in the array is @b not owned by the array, but needs to exist
21 /// while the array is in use.
22 template <typename T>
23 class GT_DAValues : public GT_DataArray {
24 public:
25  GT_DAValues(const T *values, GT_Size array_size,
26  int tuple_size, GT_Type type=GT_TYPE_NONE)
27  : myData(values)
28  , mySize(array_size)
29  , myTupleSize(tuple_size)
30  , myType(type)
31  {
32  }
33  ~GT_DAValues() override {}
34 
35  const T *getData() const { return myData; }
36 
37  const char *className() const override { return "GT_DAValues"; }
38  bool getPointerAliasing(const void *data) const override
39  { return myData == data; }
40 
41  /// @{
42  /// Methods defined on GT_DataArray
43  GT_Storage getStorage() const override
44  { return GTstorage<T>(); }
45  GT_Size getTupleSize() const override
46  { return myTupleSize; }
47  int64 getMemoryUsage() const override
48  { return sizeof(*this); }
49  GT_Size entries() const override
50  { return mySize; }
51  GT_Type getTypeInfo() const override
52  { return myType; }
53 
54  uint8 getU8(GT_Offset offset, int index=0) const override
55  {
56  offset = offset * myTupleSize + index;
57  UT_ASSERT_P(offset>=0 && offset<mySize*myTupleSize);
58  return myData[offset];
59  }
60  int32 getI32(GT_Offset offset, int index=0) const override
61  {
62  offset = offset * myTupleSize + index;
63  UT_ASSERT_P(offset>=0 && offset<mySize*myTupleSize);
64  return myData[offset];
65  }
66  int64 getI64(GT_Offset offset, int index=0) const override
67  {
68  offset = offset * myTupleSize + index;
69  UT_ASSERT_P(offset>=0 && offset<mySize*myTupleSize);
70  return myData[offset];
71  }
72  fpreal16 getF16(GT_Offset offset, int index=0) const override
73  {
74  offset = offset * myTupleSize + index;
75  UT_ASSERT_P(offset>=0 && offset<mySize*myTupleSize);
76  return myData[offset];
77  }
78  fpreal32 getF32(GT_Offset offset, int index=0) const override
79  {
80  offset = offset * myTupleSize + index;
81  UT_ASSERT_P(offset>=0 && offset<mySize*myTupleSize);
82  return myData[offset];
83  }
84  fpreal64 getF64(GT_Offset offset, int index=0) const override
85  {
86  offset = offset * myTupleSize + index;
87  UT_ASSERT_P(offset>=0 && offset<mySize*myTupleSize);
88  return myData[offset];
89  }
90  GT_String getS(GT_Offset, int) const override
92  GT_Size getStringIndexCount() const override
93  { return -1; }
94  GT_Offset getStringIndex(GT_Offset, int) const override
95  { return -1; }
97  UT_IntArray &) const override {}
98  GT_Size getDictIndexCount() const override
99  { return -1; }
100  GT_Offset getDictIndex(GT_Offset, int) const override
101  { return -1; }
103  UT_IntArray &) const override {}
104  /// @}
105 
106  template<typename U>
107  const U *getT(GT_Offset offset, SYS_MAYBE_UNUSED U *buf, int size) const
108  {
109  const T *data = myData + offset*myTupleSize;
110  UT_ASSERT_P(offset < mySize && size <= myTupleSize);
111  if constexpr (SYSisSame<T, U>())
112  {
113  return data;
114  }
115  else
116  {
117  for (int i = 0; i < size; i++)
118  buf[i] = data[i];
119  return buf;
120  }
121  }
122 
123  const uint8 *get(GT_Offset offset,
124  uint8 *buf, int size) const override
125  {
126  return getT(offset, buf, size);
127  }
128 
129  const int8 *get(GT_Offset offset,
130  int8 *buf, int size) const override
131  {
132  return getT(offset, buf, size);
133  }
134 
135  const int16 *get(GT_Offset offset,
136  int16 *buf, int size) const override
137  {
138  return getT(offset, buf, size);
139  }
140 
141  const int32 *get(GT_Offset offset,
142  int32 *buf, int size) const override
143  {
144  return getT(offset, buf, size);
145  }
146  const int64 *get(GT_Offset offset,
147  int64 *buf, int size) const override
148  {
149  return getT(offset, buf, size);
150  }
152  fpreal16 *buf, int size) const override
153  {
154  return getT(offset, buf, size);
155  }
157  fpreal32 *buf, int size) const override
158  {
159  return getT(offset, buf, size);
160  }
162  fpreal64 *buf, int size) const override
163  {
164  return getT(offset, buf, size);
165  }
166 private:
167  const T *myData;
168  GT_Size myTupleSize;
169  GT_Size mySize;
170  GT_Type myType;
171 };
172 
178 
179 #endif
GT_Storage
Definition: GT_Types.h:19
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
int int32
Definition: SYS_Types.h:39
fpreal32 getF32(GT_Offset offset, int index=0) const override
Definition: GT_DAValues.h:78
bool getPointerAliasing(const void *data) const override
Return "true" if there's pointer aliasing.
Definition: GT_DAValues.h:38
GT_Offset getDictIndex(GT_Offset, int) const override
Definition: GT_DAValues.h:100
GLboolean * data
Definition: glcorearb.h:131
GT_DAValues< int64 > GT_I64Values
Definition: GT_DAValues.h:174
#define SYS_MAYBE_UNUSED
Definition: SYS_Compiler.h:71
GT_Size entries() const override
Definition: GT_DAValues.h:49
GT_Type
Definition: GT_Types.h:36
int64 getI64(GT_Offset offset, int index=0) const override
Definition: GT_DAValues.h:66
GT_Size getStringIndexCount() const override
Definition: GT_DAValues.h:92
float fpreal32
Definition: SYS_Types.h:200
GT_DAValues< fpreal16 > GT_F16Values
Definition: GT_DAValues.h:175
GT_DAValues(const T *values, GT_Size array_size, int tuple_size, GT_Type type=GT_TYPE_NONE)
Definition: GT_DAValues.h:25
GT_DAValues< fpreal64 > GT_F64Values
Definition: GT_DAValues.h:177
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
const T * getData() const
Definition: GT_DAValues.h:35
const char * className() const override
Definition: GT_DAValues.h:37
GLintptr offset
Definition: glcorearb.h:665
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
const U * getT(GT_Offset offset, SYS_MAYBE_UNUSED U *buf, int size) const
Definition: GT_DAValues.h:107
GT_Offset getStringIndex(GT_Offset, int) const override
Definition: GT_DAValues.h:94
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
static const UT_StringHolder theEmptyString
GT_DAValues< int32 > GT_I32Values
Definition: GT_DAValues.h:173
GT_DAValues< fpreal32 > GT_F32Values
Definition: GT_DAValues.h:176
GT_Type getTypeInfo() const override
Definition: GT_DAValues.h:51
int64 GT_Offset
Definition: GT_Types.h:129
long long int64
Definition: SYS_Types.h:116
GT_Storage getStorage() const override
Definition: GT_DAValues.h:43
signed char int8
Definition: SYS_Types.h:35
fpreal16 getF16(GT_Offset offset, int index=0) const override
Definition: GT_DAValues.h:72
fpreal64 getF64(GT_Offset offset, int index=0) const override
Definition: GT_DAValues.h:84
uint8 getU8(GT_Offset offset, int index=0) const override
Definition: GT_DAValues.h:54
int64 GT_Size
Definition: GT_Types.h:128
GLsizeiptr size
Definition: glcorearb.h:664
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
short int16
Definition: SYS_Types.h:37
GLuint index
Definition: glcorearb.h:786
~GT_DAValues() override
Definition: GT_DAValues.h:33
int64 getMemoryUsage() const override
Definition: GT_DAValues.h:47
GT_Size getDictIndexCount() const override
Definition: GT_DAValues.h:98
GT_String getS(GT_Offset, int) const override
Definition: GT_DAValues.h:90
void getIndexedStrings(UT_StringArray &, UT_IntArray &) const override
Definition: GT_DAValues.h:96
void getIndexedDicts(UT_Array< UT_OptionsHolder > &, UT_IntArray &) const override
Definition: GT_DAValues.h:102
An array of const values.
Definition: GT_DAValues.h:23
int32 getI32(GT_Offset offset, int index=0) const override
Definition: GT_DAValues.h:60
type
Definition: core.h:1059
GT_Size getTupleSize() const override
Definition: GT_DAValues.h:45
Definition: format.h:895