HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAConstant.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_DAConstant.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAConstant__
12 #define __GT_DAConstant__
13 
14 #include "GT_API.h"
15 #include "GT_DAInherit.h"
16 
17 #include <UT/UT_StringArray.h> // required by GT_IMPL_INHERIT_ARRAY()
18 #include <UT/UT_ValArray.h>
19 
20 /// @brief Extend a single element from a source array to emulate a larger array
21 ///
22 /// Given a source data array, this class will emulate a larger array by
23 /// extending a single element from the source array over a given size.
24 /// For example: @code
25 /// GT_DataArray &src;
26 /// GT_DAConstant varying;
27 /// varying.init(32, 100);
28 /// @endcode
29 /// Creates an array of 100 entries referencing element 32 from the source
30 /// array.
32 public:
33  /// Default constructor
35  : mySize(0)
36  , myOffset(0)
37  , GT_DAInherit()
38  {
39  }
40  /// Useful constructor
43  : myOffset(offset)
44  , mySize(size)
45  , GT_DAInherit(data)
46  {
47  }
48  /// Copy constructor
50  : myOffset(src.myOffset),
51  mySize(src.mySize),
52  GT_DAInherit(src)
53  {
54  }
55  ~GT_DAConstant() override;
56 
57  const char *className() const override { return "GT_DAConstant"; }
58 
59  GT_Size itemSize(GT_Offset) const override
60  { return GT_DAInherit::itemSize(myOffset); }
61  GT_Size getTotalArrayEntries() const override
62  { return mySize * itemSize(myOffset); }
63 
64  /// Create a constant data array from the existing data array.
65  static const GT_DataArrayHandle createConstant(
66  const GT_DataArrayHandle &h,
68  GT_Size size);
69 
70  /// Initialize with given data
73  {
74  GT_DAInherit::init(data);
75  myOffset = offset;
76  mySize = size;
77  }
78 
79  GT_IMPL_INHERIT_ARRAY(getIndirect, mySize)
80 
81 private:
82  /// Map the requested offset to the offset in my data
83  inline GT_Offset getIndirect(GT_Offset) const
84  { return myOffset; }
85 
86  GT_Offset myOffset;
87  GT_Size mySize;
88 };
89 
90 #endif
GT_Size itemSize(GT_Offset offset) const override
Definition: GT_DAInherit.h:52
const char * className() const override
Definition: GT_DAConstant.h:57
Extend a single element from a source array to emulate a larger array.
Definition: GT_DAConstant.h:31
#define GT_API
Definition: GT_API.h:13
GT_Size getTotalArrayEntries() const override
Definition: GT_DAConstant.h:61
GT_DAConstant(const GT_DAConstant &src)
Copy constructor.
Definition: GT_DAConstant.h:49
GLintptr offset
Definition: glcorearb.h:665
void init(const GT_DataArrayHandle &data, GT_Offset offset, GT_Size size)
Initialize with given data.
Definition: GT_DAConstant.h:71
int64 GT_Offset
Definition: GT_Types.h:129
GT_DAConstant(const GT_DataArrayHandle &data, GT_Offset offset, GT_Size size)
Useful constructor.
Definition: GT_DAConstant.h:41
int64 GT_Size
Definition: GT_Types.h:128
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
Base class for a data array which references another data array.
Definition: GT_DAInherit.h:18
#define GT_IMPL_INHERIT_ARRAY(MAP_INDEX, SIZE)
Definition: GT_DAInherit.h:83
GT_Size itemSize(GT_Offset) const override
Return the number of elements in the array for the given item.
Definition: GT_DAConstant.h:59
void init(const GT_DataArrayHandle &data)
Definition: GT_DAInherit.h:32
GT_DAConstant()
Default constructor.
Definition: GT_DAConstant.h:34
Definition: format.h:895
GLenum src
Definition: glcorearb.h:1793