HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual const char *className() const { 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  virtual GT_Storage getStorage() const { return GTstorage<T_POD>(); }
91  virtual GT_Size getTupleSize() const { return myTupleSize; }
92  virtual GT_Type getTypeInfo() const { return myTypeInfo; }
93  virtual GT_Size entries() const { return mySize; }
94  virtual int64 getMemoryUsage() const
95  { return sizeof(T_POD)*myTupleSize; }
96 
97  virtual fpreal16 getF16(GT_Offset, int index) const
98  {
99  UT_ASSERT_P(index >= 0 && index < myTupleSize);
100  return (fpreal16)myData[index];
101  }
102  virtual fpreal32 getF32(GT_Offset, int index) const
103  {
104  UT_ASSERT_P(index >= 0 && index < myTupleSize);
105  return (fpreal32)myData[index];
106  }
107  virtual fpreal64 getF64(GT_Offset, int index) const
108  {
109  UT_ASSERT_P(index >= 0 && index < myTupleSize);
110  return (fpreal64)myData[index];
111  }
112  virtual uint8 getU8(GT_Offset, int index) const
113  {
114  UT_ASSERT_P(index >= 0 && index < myTupleSize);
115  return (uint8)myData[index];
116  }
117  virtual int32 getI32(GT_Offset, int index) const
118  {
119  UT_ASSERT_P(index >= 0 && index < myTupleSize);
120  return (int32)myData[index];
121  }
122  virtual int64 getI64(GT_Offset, int index) const
123  {
124  UT_ASSERT_P(index >= 0 && index < myTupleSize);
125  return (int64)myData[index];
126  }
127  virtual GT_String getS(GT_Offset, int) const { return NULL; }
128  virtual GT_Size getStringIndexCount() const { return -1; }
129  virtual GT_Offset getStringIndex(GT_Offset, int) const { return -1; }
131  UT_IntArray &) const {}
132 
133  virtual GT_DataArrayHandle harden() const
134  { return GT_DataArrayHandle(SYSconst_cast(this)); }
135  /// @}
136 private:
137  T_POD *myData;
138  GT_Size mySize;
139  int myTupleSize;
140  GT_Type myTypeInfo;
141 };
142 
145 
146 #endif
GT_Storage
Definition: GT_Types.h:17
virtual GT_DataArrayHandle harden() const
GT_DAConstantValue(GT_Size array_size, const T_POD *value, int tuple_size, GT_Type typeinfo=GT_TYPE_NONE)
virtual const char * className() const
virtual GT_Size getTupleSize() const
virtual fpreal16 getF16(GT_Offset, int index) const
const char * GT_String
Definition: GT_Types.h:108
virtual GT_Type getTypeInfo() const
GT_DAConstantValue(GT_Size array_size, T_POD value=0, int tuple_size=1, GT_Type typeinfo=GT_TYPE_NONE)
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:120
virtual fpreal64 getF64(GT_Offset, int index) const
GT_Type
Definition: GT_Types.h:31
static bool isConstantValue(GT_Size a_size, const T_POD *data, int t_size)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
virtual int64 getI64(GT_Offset, int index) const
png_uint_32 i
Definition: png.h:2877
virtual uint8 getU8(GT_Offset, int index) const
GLsizeiptr size
Definition: glcorearb.h:663
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
virtual GT_Storage getStorage() const
long long int64
Definition: SYS_Types.h:100
virtual GT_Offset getStringIndex(GT_Offset, int) const
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
virtual int64 getMemoryUsage() const
virtual GT_Size getStringIndexCount() const
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:30
virtual void getIndexedStrings(UT_StringArray &, UT_IntArray &) const
void set(T_POD value)
Set constant value.
double fpreal64
Definition: SYS_Types.h:185
virtual GT_Size entries() const
A data array for a constant value.
GLboolean * data
Definition: glcorearb.h:130
int int32
Definition: SYS_Types.h:28
GLfloat v0
Definition: glcorearb.h:815
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GT_DAConstantValue< fpreal64 > GT_RealConstant
unsigned char uint8
Definition: SYS_Types.h:25
void assign(T_POD v0, T_POD v1, T_POD v2)
Assign a 3-tuple.
GLuint index
Definition: glcorearb.h:785
virtual fpreal32 getF32(GT_Offset, int index) const
GLfloat GLfloat v1
Definition: glcorearb.h:816
virtual GT_String getS(GT_Offset, int) const
GT_DAConstantValue< int64 > GT_IntConstant
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
virtual int32 getI32(GT_Offset, int index) const
#define SYSmin(a, b)
Definition: SYS_Math.h:1366
float fpreal32
Definition: SYS_Types.h:184
void set(const T_POD *value, int size)
Set from a tuple.