HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GT_DARange();
68 
69  virtual const char *className() const { 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  virtual GT_Storage getStorage() const
82  { return isBig(myStart) || isBig(myEnd)
85  }
86  virtual GT_Size getTupleSize() const
87  { return 1; }
88  virtual int64 getMemoryUsage() const
89  { return sizeof(*this); }
90  virtual GT_Type getTypeInfo() const
91  { return myType; }
92  virtual GT_Size entries() const
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  virtual fpreal16 getF16(GT_Offset offset, int) const
102  { return myStart + offset*myStep; }
103  virtual fpreal32 getF32(GT_Offset offset, int) const
104  { return myStart + offset*myStep; }
105  virtual fpreal64 getF64(GT_Offset offset, int) const
106  { return myStart + offset*myStep; }
107  virtual uint8 getU8(GT_Offset offset, int) const
108  { return myStart + offset*myStep; }
109  virtual int32 getI32(GT_Offset offset, int) const
110  { return myStart + offset*myStep; }
111  virtual int64 getI64(GT_Offset offset, int) const
112  { return myStart + offset*myStep; }
113  virtual GT_String getS(GT_Offset, int) const { return NULL; }
114  virtual GT_Size getStringIndexCount() const { return -1; }
115  virtual GT_Offset getStringIndex(GT_Offset, int) const { return -1; }
117  UT_IntArray &) const {}
118  /// @}
119 
120 private:
121  bool isBig(GT_Offset v) const
122  {
123  return v < -0x7ffffff || v > 0x7ffffff;
124  }
125  GT_Offset myStart, myEnd;
126  GT_Size myStep;
127  GT_Type myType;
128 };
129 
130 #endif
131 
#define SYSmax(a, b)
Definition: SYS_Math.h:1365
GT_Storage
Definition: GT_Types.h:17
GT_DARange(const GT_DARange &src)
Copy constructor.
Definition: GT_DARange.h:57
void init(GT_Offset start, GT_Offset end, GT_Size step=1)
Initialize with given data.
Definition: GT_DARange.h:72
const GLdouble * v
Definition: glcorearb.h:836
virtual int64 getI64(GT_Offset offset, int) const
Definition: GT_DARange.h:111
GLuint start
Definition: glcorearb.h:474
const char * GT_String
Definition: GT_Types.h:108
int myStep
Definition: GT_CurveEval.h:264
#define GT_API
Definition: GT_API.h:11
GT_Type
Definition: GT_Types.h:31
GT_DARange(GT_Offset stop, GT_Type type=GT_TYPE_NONE)
Initialize [0..stop)
Definition: GT_DARange.h:36
virtual fpreal16 getF16(GT_Offset offset, int) const
Definition: GT_DARange.h:101
virtual GT_Size entries() const
Definition: GT_DARange.h:92
virtual GT_Type getTypeInfo() const
Definition: GT_DARange.h:90
virtual GT_String getS(GT_Offset, int) const
Definition: GT_DARange.h:113
long long int64
Definition: SYS_Types.h:100
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:2007
virtual fpreal64 getF64(GT_Offset offset, int) const
Definition: GT_DARange.h:105
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
virtual const char * className() const
Definition: GT_DARange.h:69
double fpreal64
Definition: SYS_Types.h:185
GLuint GLuint end
Definition: glcorearb.h:474
GLintptr offset
Definition: glcorearb.h:664
virtual GT_Size getStringIndexCount() const
Definition: GT_DARange.h:114
virtual int64 getMemoryUsage() const
Definition: GT_DARange.h:88
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
int int32
Definition: SYS_Types.h:28
A range of values similar to the python range function.
Definition: GT_DARange.h:25
virtual void getIndexedStrings(UT_StringArray &, UT_IntArray &) const
Definition: GT_DARange.h:116
unsigned char uint8
Definition: SYS_Types.h:25
virtual fpreal32 getF32(GT_Offset offset, int) const
Definition: GT_DARange.h:103
virtual GT_Size getTupleSize() const
Definition: GT_DARange.h:86
virtual GT_Storage getStorage() const
Definition: GT_DARange.h:81
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
GT_DARange(GT_Type type=GT_TYPE_NONE)
Default constructor (empty range)
Definition: GT_DARange.h:29
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
virtual GT_Offset getStringIndex(GT_Offset, int) const
Definition: GT_DARange.h:115
virtual uint8 getU8(GT_Offset offset, int) const
Definition: GT_DARange.h:107
float fpreal32
Definition: SYS_Types.h:184
virtual int32 getI32(GT_Offset offset, int) const
Definition: GT_DARange.h:109
GLenum src
Definition: glcorearb.h:1792