HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAConstantValue.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_DAConstantValue.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAConstantValue__
12 #define __GT_DAConstantValue__
13 
14 #include "GT_API.h"
15 #include <UT/UT_Assert.h>
16 #include <SYS/SYS_Math.h>
17 #include "GT_DataArray.h"
18 
19 /// @brief A data array for a constant value
20 template <typename T_POD>
22 {
23 public:
24  GT_DAConstantValue(GT_Size array_size, T_POD value=0,
25  int tuple_size=1, GT_Type typeinfo=GT_TYPE_NONE)
26  : mySize(array_size)
27  , myTupleSize(tuple_size)
28  , myTypeInfo(typeinfo)
29  {
30  myData = new T_POD[tuple_size];
31  set(value);
32  }
33  GT_DAConstantValue(GT_Size array_size, const T_POD *value,
34  int tuple_size, GT_Type typeinfo=GT_TYPE_NONE)
35  : mySize(array_size)
36  , myTupleSize(tuple_size)
37  , myTypeInfo(typeinfo)
38  {
39  myData = new T_POD[tuple_size];
40  set(value, tuple_size);
41  }
43  {
44  delete [] myData;
45  }
46 
47  const char *className() const override { return "GT_DAConstantValue"; }
48 
49  static bool isConstantValue(GT_Size a_size, const T_POD *data, int t_size)
50  {
51  // Check to see if an array of tuples is a constant value
52  for (GT_Offset i = 1; i < a_size; ++i)
53  {
54  for (int j = 0; j < t_size; ++j)
55  {
56  if (data[j] != data[i*t_size + j])
57  return false;
58  }
59  }
60  return true;
61  }
62 
63  /// Set constant value
64  void set(T_POD value)
65  {
66  int i;
67  for (i = 0; i < myTupleSize; i++)
68  myData[i] = value;
69  }
70  /// Set from a tuple
71  void set(const T_POD *value, int size)
72  {
73  int i;
74  size = SYSmin(size, myTupleSize);
75  for (i = 0; i < size; i++)
76  myData[i] = value[i];
77  }
78  /// Assign a 3-tuple
79  void assign(T_POD v0, T_POD v1, T_POD v2)
80  {
81  myData[0] = v0;
82  if (myTupleSize > 0)
83  myData[1] = v1;
84  if (myTupleSize > 1)
85  myData[2] = v2;
86  }
87 
88  /// Provide virtual access to the backing data
89  const void *getBackingData() const override
90  {
91  return mySize == 1 ? myData : nullptr;
92  }
93 
94  /// @{
95  /// Methods defined on GT_DataArray
96  GT_Storage getStorage() const override
97  { return GTstorage<T_POD>(); }
98  GT_Size getTupleSize() const override
99  { return myTupleSize; }
100  GT_Type getTypeInfo() const override
101  { return myTypeInfo; }
102  GT_Size entries() const override
103  { return mySize; }
104  int64 getMemoryUsage() const override
105  { return sizeof(T_POD)*myTupleSize; }
106 
107  fpreal16 getF16(GT_Offset, int index) const override
108  {
109  UT_ASSERT_P(index >= 0 && index < myTupleSize);
110  return (fpreal16)myData[index];
111  }
112  fpreal32 getF32(GT_Offset, int index) const override
113  {
114  UT_ASSERT_P(index >= 0 && index < myTupleSize);
115  return (fpreal32)myData[index];
116  }
117  fpreal64 getF64(GT_Offset, int index) const override
118  {
119  UT_ASSERT_P(index >= 0 && index < myTupleSize);
120  return (fpreal64)myData[index];
121  }
122  uint8 getU8(GT_Offset, int index) const override
123  {
124  UT_ASSERT_P(index >= 0 && index < myTupleSize);
125  return (uint8)myData[index];
126  }
127  int32 getI32(GT_Offset, int index) const override
128  {
129  UT_ASSERT_P(index >= 0 && index < myTupleSize);
130  return (int32)myData[index];
131  }
132  int64 getI64(GT_Offset, int index) const override
133  {
134  UT_ASSERT_P(index >= 0 && index < myTupleSize);
135  return (int64)myData[index];
136  }
137  GT_String getS(GT_Offset, int) const override
139  GT_Size getStringIndexCount() const override
140  { return -1; }
141  GT_Offset getStringIndex(GT_Offset, int) const override
142  { return -1; }
144  UT_IntArray &) const override {}
145  GT_Size getDictIndexCount() const override
146  { return -1; }
147  GT_Offset getDictIndex(GT_Offset, int) const override
148  { return -1; }
150  UT_IntArray &) const override {}
151 
152  GT_DataArrayHandle harden() const override
153  { return GT_DataArrayHandle(SYSconst_cast(this)); }
154  /// @}
155 private:
156  T_POD *myData;
157  GT_Size mySize;
158  int myTupleSize;
159  GT_Type myTypeInfo;
160 };
161 
164 
165 #endif
GT_Storage
Definition: GT_Types.h:19
int int32
Definition: SYS_Types.h:39
GT_DAConstantValue(GT_Size array_size, const T_POD *value, int tuple_size, GT_Type typeinfo=GT_TYPE_NONE)
const void * getBackingData() const override
Provide virtual access to the backing data.
GT_DAConstantValue(GT_Size array_size, T_POD value=0, int tuple_size=1, GT_Type typeinfo=GT_TYPE_NONE)
GT_Size getTupleSize() const override
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:136
GT_Type
Definition: GT_Types.h:36
int64 getI64(GT_Offset, int index) const override
static bool isConstantValue(GT_Size a_size, const T_POD *data, int t_size)
fpreal32 getF32(GT_Offset, int index) const override
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
~GT_DAConstantValue() override
fpreal16 getF16(GT_Offset, int index) const override
float fpreal32
Definition: SYS_Types.h:200
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
GT_Size getStringIndexCount() const override
void getIndexedStrings(UT_StringArray &, UT_IntArray &) const override
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
void set(T_POD value)
Set constant value.
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
static const UT_StringHolder theEmptyString
void getIndexedDicts(UT_Array< UT_OptionsHolder > &, UT_IntArray &) const override
int32 getI32(GT_Offset, int index) const override
int64 GT_Offset
Definition: GT_Types.h:129
long long int64
Definition: SYS_Types.h:116
A data array for a constant value.
fpreal64 getF64(GT_Offset, int index) const override
GT_Size entries() const override
GT_String getS(GT_Offset, int) const override
int64 getMemoryUsage() const override
GT_Size getDictIndexCount() const override
GT_Offset getDictIndex(GT_Offset, int) const override
GLfloat v0
Definition: glcorearb.h:816
GLint j
Definition: glad.h:2733
int64 GT_Size
Definition: GT_Types.h:128
GLsizeiptr size
Definition: glcorearb.h:664
GT_DAConstantValue< fpreal64 > GT_RealConstant
GT_DataArrayHandle harden() const override
void assign(T_POD v0, T_POD v1, T_POD v2)
Assign a 3-tuple.
GLuint index
Definition: glcorearb.h:786
GLfloat GLfloat v1
Definition: glcorearb.h:817
GT_Offset getStringIndex(GT_Offset, int) const override
GT_Storage getStorage() const override
GT_DAConstantValue< int64 > GT_IntConstant
Definition: core.h:1131
uint8 getU8(GT_Offset, int index) const override
#define SYSmin(a, b)
Definition: SYS_Math.h:1571
GT_Type getTypeInfo() const override
void set(const T_POD *value, int size)
Set from a tuple.
Definition: format.h:895
const char * className() const override