HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DARange.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_DARange.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DARange__
12 #define __GT_DARange__
13 
14 #include "GT_API.h"
15 #include "GT_DataArray.h"
16 #include <SYS/SYS_Math.h>
17 
18 /// @brief A range of values similar to the python range function
19 ///
20 /// This is a light-weight way of creating a range of integers. The class uses
21 /// the same semantics as the Python range() function.
22 /// - GT_DARange(4) @n Create a sequence of integers [0,1,2,3]
23 /// - GT_DARange(3,6) @n Create the sequence [3,4,5]
24 /// - GT_DARange(4,0,-1) @n Create the sequence [4,3,2,1]
26 {
27 public:
28  /// Default constructor (empty range)
30  : GT_DataArray()
31  , myType(type)
32  {
33  init(0, 0, 1);
34  }
35  /// Initialize [0..stop)
37  : GT_DataArray()
38  , myType(type)
39  {
40  init(0, stop, 1);
41  }
42  /// Initialize [start..stop)
44  : GT_DataArray()
45  , myType(type)
46  {
47  init(start, stop, 1);
48  }
49  /// Initialize [start..stop, by step)
51  : GT_DataArray()
52  , myType(type)
53  {
54  init(start, stop, step);
55  }
56  /// Copy constructor
58  : myStart(src.myStart)
59  , myEnd(src.myEnd)
60  , myStep(src.myStep)
61  , myType(src.myType)
62  , GT_DataArray()
63  {
64  }
65 
66  // Destructor
67  ~GT_DARange() override;
68 
69  const char *className() const override { return "GT_DARange"; }
70 
71  /// Initialize with given data
73  {
74  myStart = start;
75  myEnd = end;
76  myStep = (step == 0) ? 1 : step;
77  }
78 
79  /// @{
80  /// Methods defined on GT_DataArray
81  GT_Storage getStorage() const override
82  { return isBig(myStart) || isBig(myEnd)
85  }
86  GT_Size getTupleSize() const override
87  { return 1; }
88  int64 getMemoryUsage() const override
89  { return sizeof(*this); }
90  GT_Type getTypeInfo() const override
91  { return myType; }
92  GT_Size entries() const override
93  {
94  GT_Size n;
95  if (myStep > 0)
96  n = (myEnd - myStart) + (myStep-1);
97  else
98  n = (myEnd - myStart) + (myStep+1);
99  return SYSmax(n/myStep, 0);
100  }
101  fpreal16 getF16(GT_Offset offset, int) const override
102  { return myStart + offset*myStep; }
103  fpreal32 getF32(GT_Offset offset, int) const override
104  { return myStart + offset*myStep; }
105  fpreal64 getF64(GT_Offset offset, int) const override
106  { return myStart + offset*myStep; }
107  uint8 getU8(GT_Offset offset, int) const override
108  { return myStart + offset*myStep; }
109  int32 getI32(GT_Offset offset, int) const override
110  { return myStart + offset*myStep; }
111  int64 getI64(GT_Offset offset, int) const override
112  { return myStart + offset*myStep; }
113  GT_String getS(GT_Offset, int) const override
115  GT_Size getStringIndexCount() const override
116  { return -1; }
117  GT_Offset getStringIndex(GT_Offset, int) const override
118  { return -1; }
120  UT_IntArray &) const override {}
121  GT_Size getDictIndexCount() const override
122  { return -1; }
123  GT_Offset getDictIndex(GT_Offset, int) const override
124  { return -1; }
126  UT_IntArray &) const override {}
127  /// @}
128 
129 private:
130  bool isBig(GT_Offset v) const
131  {
132  return v < -0x7ffffff || v > 0x7ffffff;
133  }
134  GT_Offset myStart, myEnd;
135  GT_Size myStep;
136  GT_Type myType;
137 };
138 
139 #endif
140 
#define SYSmax(a, b)
Definition: SYS_Math.h:1570
GT_Storage
Definition: GT_Types.h:19
GT_DARange(const GT_DARange &src)
Copy constructor.
Definition: GT_DARange.h:57
GT_Offset getDictIndex(GT_Offset, int) const override
Definition: GT_DARange.h:123
int int32
Definition: SYS_Types.h:39
GT_Type getTypeInfo() const override
Definition: GT_DARange.h:90
void init(GT_Offset start, GT_Offset end, GT_Size step=1)
Initialize with given data.
Definition: GT_DARange.h:72
void getIndexedDicts(UT_Array< UT_OptionsHolder > &, UT_IntArray &) const override
Definition: GT_DARange.h:125
const GLdouble * v
Definition: glcorearb.h:837
GLuint start
Definition: glcorearb.h:475
int myStep
Definition: GT_CurveEval.h:264
#define GT_API
Definition: GT_API.h:13
GT_Type
Definition: GT_Types.h:36
GT_DARange(GT_Offset stop, GT_Type type=GT_TYPE_NONE)
Initialize [0..stop)
Definition: GT_DARange.h:36
float fpreal32
Definition: SYS_Types.h:200
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
const char * className() const override
Definition: GT_DARange.h:69
GT_DARange(GT_Offset start, GT_Offset stop, GT_Type type=GT_TYPE_NONE)
Initialize [start..stop)
Definition: GT_DARange.h:43
GLdouble n
Definition: glcorearb.h:2008
GLintptr offset
Definition: glcorearb.h:665
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
void getIndexedStrings(UT_StringArray &, UT_IntArray &) const override
Definition: GT_DARange.h:119
GT_Size entries() const override
Definition: GT_DARange.h:92
static const UT_StringHolder theEmptyString
GLuint GLuint end
Definition: glcorearb.h:475
int32 getI32(GT_Offset offset, int) const override
Definition: GT_DARange.h:109
int64 GT_Offset
Definition: GT_Types.h:129
long long int64
Definition: SYS_Types.h:116
GT_DARange(GT_Offset start, GT_Offset stop, GT_Offset step, GT_Type type=GT_TYPE_NONE)
Initialize [start..stop, by step)
Definition: GT_DARange.h:50
A range of values similar to the python range function.
Definition: GT_DARange.h:25
GT_Storage getStorage() const override
Definition: GT_DARange.h:81
int64 GT_Size
Definition: GT_Types.h:128
fpreal32 getF32(GT_Offset offset, int) const override
Definition: GT_DARange.h:103
int64 getI64(GT_Offset offset, int) const override
Definition: GT_DARange.h:111
GT_Offset getStringIndex(GT_Offset, int) const override
Definition: GT_DARange.h:117
GT_String getS(GT_Offset, int) const override
Definition: GT_DARange.h:113
GT_Size getTupleSize() const override
Definition: GT_DARange.h:86
fpreal64 getF64(GT_Offset offset, int) const override
Definition: GT_DARange.h:105
GT_DARange(GT_Type type=GT_TYPE_NONE)
Default constructor (empty range)
Definition: GT_DARange.h:29
GT_Size getStringIndexCount() const override
Definition: GT_DARange.h:115
uint8 getU8(GT_Offset offset, int) const override
Definition: GT_DARange.h:107
GT_Size getDictIndexCount() const override
Definition: GT_DARange.h:121
type
Definition: core.h:1059
int64 getMemoryUsage() const override
Definition: GT_DARange.h:88
fpreal16 getF16(GT_Offset offset, int) const override
Definition: GT_DARange.h:101
GLenum src
Definition: glcorearb.h:1793