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  /// @{
89  /// Methods defined on GT_DataArray
90  GT_Storage getStorage() const override
91  { return GTstorage<T_POD>(); }
92  GT_Size getTupleSize() const override
93  { return myTupleSize; }
94  GT_Type getTypeInfo() const override
95  { return myTypeInfo; }
96  GT_Size entries() const override
97  { return mySize; }
98  int64 getMemoryUsage() const override
99  { return sizeof(T_POD)*myTupleSize; }
100 
101  fpreal16 getF16(GT_Offset, int index) const override
102  {
103  UT_ASSERT_P(index >= 0 && index < myTupleSize);
104  return (fpreal16)myData[index];
105  }
106  fpreal32 getF32(GT_Offset, int index) const override
107  {
108  UT_ASSERT_P(index >= 0 && index < myTupleSize);
109  return (fpreal32)myData[index];
110  }
111  fpreal64 getF64(GT_Offset, int index) const override
112  {
113  UT_ASSERT_P(index >= 0 && index < myTupleSize);
114  return (fpreal64)myData[index];
115  }
116  uint8 getU8(GT_Offset, int index) const override
117  {
118  UT_ASSERT_P(index >= 0 && index < myTupleSize);
119  return (uint8)myData[index];
120  }
121  int32 getI32(GT_Offset, int index) const override
122  {
123  UT_ASSERT_P(index >= 0 && index < myTupleSize);
124  return (int32)myData[index];
125  }
126  int64 getI64(GT_Offset, int index) const override
127  {
128  UT_ASSERT_P(index >= 0 && index < myTupleSize);
129  return (int64)myData[index];
130  }
131  GT_String getS(GT_Offset, int) const override
133  GT_Size getStringIndexCount() const override
134  { return -1; }
135  GT_Offset getStringIndex(GT_Offset, int) const override
136  { return -1; }
138  UT_IntArray &) const override {}
139 
140  GT_DataArrayHandle harden() const override
141  { return GT_DataArrayHandle(SYSconst_cast(this)); }
142  /// @}
143 private:
144  T_POD *myData;
145  GT_Size mySize;
146  int myTupleSize;
147  GT_Type myTypeInfo;
148 };
149 
152 
153 #endif
GT_Storage
Definition: GT_Types.h:18
GLsizeiptr size
Definition: glew.h:1681
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)
GLuint index
Definition: glew.h:1814
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:34
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
~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
GLfloat GLfloat GLfloat v2
Definition: glew.h:1856
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
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
void set(T_POD value)
Set constant value.
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:134
static const UT_StringHolder theEmptyString
int32 getI32(GT_Offset, int index) const override
int64 GT_Offset
Definition: GT_Types.h:114
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
int64 GT_Size
Definition: GT_Types.h:113
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.
GT_Offset getStringIndex(GT_Offset, int) const override
GLfloat v0
Definition: glew.h:1848
GT_Storage getStorage() const override
GT_DAConstantValue< int64 > GT_IntConstant
uint8 getU8(GT_Offset, int index) const override
#define SYSmin(a, b)
Definition: SYS_Math.h:1522
GLsizei const GLfloat * value
Definition: glew.h:1849
GT_Type getTypeInfo() const override
GLfloat GLfloat v1
Definition: glew.h:1852
void set(const T_POD *value, int size)
Set from a tuple.
const char * className() const override