IntegerClass.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel IntegerClass.hpp */
40 /* */
41 /* Primitive Integer Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxInteger
45 #define Included_RexxInteger
46 
47 #include "NumberStringClass.hpp"
48 
49 void integer_create (void);
50 #define INTEGERCACHELOW -10
51 #define INTEGERCACHESIZE 100
52 #define MAX_INTEGER_LENGTH 10
53 
54 class RexxIntegerClass;
55 
56 class RexxInteger : public RexxObject {
57  public:
58  inline RexxInteger(RESTORETYPE restoreType) { ; };
59  inline RexxInteger(wholenumber_t intValue) { this->value = intValue; };
60  inline void *operator new(size_t size, void *ptr) {return ptr;};
61  void *operator new(size_t);
62  void live(size_t);
63  void liveGeneral(int reason);
64  void flatten(RexxEnvelope*);
65  virtual HashCode getHashValue();
67 
68  bool numberValue(wholenumber_t &result, size_t precision);
69  bool numberValue(wholenumber_t &result);
70  bool unsignedNumberValue(stringsize_t &result, size_t precision);
71  bool unsignedNumberValue(stringsize_t &result);
72  bool doubleValue(double &result);
73 
75  RexxInteger *integerValue(size_t);
82  bool truthValue(int);
83  virtual bool logicalValue(logical_t &);
84  bool isInstanceOf(RexxClass *);
87 
88  bool isEqual(RexxObject *);
89  wholenumber_t strictComp(RexxObject *, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL);
90  wholenumber_t comp(RexxObject *other, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL);
91 
104  RexxObject *hashCode();
105 
114  RexxObject *notOp();
119 
120  RexxObject *abs();
121  RexxObject *sign();
122  RexxObject *Max(RexxObject **, size_t, size_t);
123  RexxObject *Min(RexxObject **, size_t, size_t);
125  RexxObject *floor();
126  RexxObject *ceiling();
127  RexxObject *round();
138  void setString(RexxString *string);
140  /* numberstring operator forwarders */
141  koper (integer_operator_not)
142 
143  inline wholenumber_t getValue() {return this->value;}
144  inline wholenumber_t wholeNumber() {return this->value;}
145  inline stringsize_t stringSize() {return (stringsize_t)this->value;}
146  inline wholenumber_t incrementValue() {return ++this->value;}
147  inline wholenumber_t decrementValue() {return --this->value;}
148  inline RexxString *getStringrep() {return this->stringrep;}
149 
150  static void createInstance();
153 
157 
169 
170 protected:
171 
172  RexxString *stringrep; /* integer string representation */
173  wholenumber_t value; /* actual integer value */
174 
175  static wholenumber_t validMaxWhole[]; // table of maximum values per digits setting
176 };
177 
178 class RexxIntegerClass : public RexxClass {
179  public:
180  RexxIntegerClass(RESTORETYPE restoreType) { ; };
181  void *operator new(size_t size, void *ptr) {return ptr;};
182  void *operator new (size_t);
183  void *operator new(size_t size, size_t size1, const char *className, RexxBehaviour *classBehave, RexxBehaviour *instance) { return new (size, className, classBehave, instance) RexxClass; }
184  inline void operator delete(void *, void *ptr) { }
185  inline void operator delete (void *) { }
186  inline void operator delete(void *, size_t, const char *, RexxBehaviour *, RexxBehaviour *) { }
187 
189  inline RexxInteger *newCache(wholenumber_t value) {if (value >= INTEGERCACHELOW && value < INTEGERCACHESIZE)
190  return this->integercache[value - INTEGERCACHELOW];
191  else
192  return new RexxInteger (value); };
193  void live(size_t);
194  void liveGeneral(int reason);
195  /* array of fast aloocation integers 0-99 */
197 };
198 
199 
200 inline RexxInteger *new_integer(wholenumber_t v) { return TheIntegerClass->newCache(v); }
201 #endif
#define INTEGERCACHELOW
#define INTEGERCACHESIZE
void integer_create(void)
RexxInteger * new_integer(wholenumber_t v)
RESTORETYPE
Definition: ObjectClass.hpp:82
RexxObject *(RexxObject::* PCPPM)()
size_t HashCode
Definition: ObjectClass.hpp:79
#define OREF_NULL
Definition: RexxCore.h:61
#define TheIntegerClass
Definition: RexxCore.h:158
void liveGeneral(int reason)
RexxInteger * newCache(wholenumber_t value)
RexxIntegerClass(RESTORETYPE restoreType)
void live(size_t)
RexxInteger * integercache[INTEGERCACHESIZE - INTEGERCACHELOW]
bool numberValue(wholenumber_t &result, size_t precision)
RexxInteger * isLessOrEqual(RexxObject *)
void setString(RexxString *string)
static RexxInteger * integerFour
RexxObject * xorOp(RexxObject *)
static void createInstance()
static RexxInteger * integerSix
RexxInteger * equal(RexxObject *)
wholenumber_t strictComp(RexxObject *, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
RexxInteger * isLessThan(RexxObject *)
RexxInteger * strictGreaterOrEqual(RexxObject *)
RexxString * concat(RexxString *)
static RexxInteger * falseObject
static RexxInteger * integerThree
RexxInteger * isGreaterThan(RexxObject *)
static RexxInteger * integerSeven
RexxInteger * notEqual(RexxObject *)
void flatten(RexxEnvelope *)
static wholenumber_t validMaxWhole[]
RexxObject * power(RexxObject *)
RexxObject * getRealValue(RexxActivation *)
RexxObject * plus(RexxInteger *)
RexxString * getStringrep()
wholenumber_t incrementValue()
RexxString * stringrep
RexxObject * remainder(RexxInteger *)
RexxObject * minus(RexxInteger *)
RexxObject * notOp()
static RexxInteger * integerZero
RexxObject * ceiling()
RexxObject * Max(RexxObject **, size_t, size_t)
bool isEqual(RexxObject *)
static RexxInteger * integerTwo
RexxObject * round()
RexxObject * d2x(RexxObject *)
RexxInteger * strictGreaterThan(RexxObject *)
RexxObject * operatorNot(RexxObject *)
RexxInteger(RESTORETYPE restoreType)
RexxNumberString * numberString()
RexxInteger * strictLessOrEqual(RexxObject *)
RexxInteger * strictLessThan(RexxObject *)
static RexxInteger * integerNine
RexxObject * trunc(RexxObject *)
RexxObject * Min(RexxObject **, size_t, size_t)
RexxInteger * isGreaterOrEqual(RexxObject *)
static RexxInteger * nullPointer
RexxString * concatBlank(RexxString *)
wholenumber_t value
RexxObject * d2c(RexxObject *)
void liveGeneral(int reason)
virtual HashCode getHashValue()
RexxClass * classObject()
bool isInstanceOf(RexxClass *)
static RexxInteger * trueObject
void live(size_t)
RexxInteger * integerValue(size_t)
RexxObject * getValue(RexxActivation *)
RexxString * stringValue()
void copyIntoTail(RexxCompoundTail *)
RexxObject * andOp(RexxObject *)
wholenumber_t wholeNumber()
static RexxInteger * integerEight
RexxObject * multiply(RexxInteger *)
wholenumber_t decrementValue()
virtual wholenumber_t compareTo(RexxObject *)
RexxInteger * hasMethod(RexxString *)
RexxInteger * strictNotEqual(RexxObject *)
RexxObject * orOp(RexxObject *)
static RexxIntegerClass * classInstance
RexxObject * unknown(RexxString *, RexxArray *, RexxDirectory *)
RexxMethod * instanceMethod(RexxString *)
RexxString * makeString()
RexxObject * hashCode()
wholenumber_t comp(RexxObject *other, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
RexxObject * sign()
RexxObject * abs()
static RexxInteger * integerMinusOne
RexxObject * format(RexxObject *, RexxObject *, RexxObject *, RexxObject *)
static RexxInteger * integerOne
stringsize_t stringSize()
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
koper(integer_operator_not) inline wholenumber_t getValue()
RexxInteger * strictEqual(RexxObject *)
RexxObject * integerDivide(RexxInteger *)
bool truthValue(int)
static RexxInteger * integerFive
bool doubleValue(double &result)
RexxArray * makeArray()
RexxObject * floor()
RexxSupplier * instanceMethods(RexxClass *)
RexxInteger(wholenumber_t intValue)
bool unsignedNumberValue(stringsize_t &result, size_t precision)
RexxObject * divide(RexxInteger *)
virtual bool logicalValue(logical_t &)
RexxString * primitiveMakeString()
static PCPPM operatorMethods[]
size_t logical_t
Definition: rexx.h:231
ssize_t wholenumber_t
Definition: rexx.h:230
size_t stringsize_t
Definition: rexx.h:228