C++ main module for gpm Package  1.0
CORE_Integer.h
Go to the documentation of this file.
1 #ifndef CORE_INTEGER_H
2 #define CORE_INTEGER_H
3 
4 #include "CORE_Object.h"
5 
6 #include "CORE_Pointers.h"
7 
8 
23 class CORE_Integer : public CORE_Object {
24  // ATTRIBUTES
25  private:
26 
27  long int mInteger;
28 
29  // ASSOCIATIONS
30 
31  protected:
32 
33  // CONSTRUCTORS
37 
38 
39 
40  // DESTRUCTORS
43  ~CORE_Integer();
44 
45 
46  public:
47 
48  // NEW
49 
52  static inline SP::CORE_Integer New() {
53  SP::CORE_Integer p(new CORE_Integer(0),CORE_Integer::Delete());
54  return p;
55 
56  };
59  static inline SP::CORE_Integer New(tRelativeInteger i) {
60  SP::CORE_Integer p(new CORE_Integer(i),CORE_Integer::Delete());
61  return p;
62  }
63 
64  // SET Accessors
65 
68  inline void setInteger(const tRelativeInteger& i) {
69  mInteger=i;
70  };
73  inline void setInteger(const tString& i) {
74  setInteger(parseInt(i));
75  };
76 
77  // GET Accessors
80  static tBoolean isInteger(const tString& str);
81 
85  tRelativeInteger getInteger() const {return mInteger;};
86 
90  int intValue() const {return (int)mInteger;};
94  int shortValue() const {return (short)mInteger;};
95 
96  // Methods
97 
100  static int xtoi(const char * buffer,unsigned int* i);
101 #if defined(WIN32) || defined(WIN64)
102  static long int atoll(char * buffer);
103  static long long strtoll( const char *str, char **endptr, int base );
104 
105 #define fixit(_from, _to) __extension__ ( \
106  { \
107  union \
108  { \
109  const _to _copy; _to __p; \
110  } _quesie; \
111  _quesie._copy = _from; \
112  _quesie.__p; \
113  })
114 #endif
115 
117  static char *itoa(int val,char *buf, int base);
120  static char *ltoa(long int val,char *buf, int base);
123  static char *lltoa(long long int val,char *buf, int base);
126  static char *utoa(unsigned int val,char *buf, int base);
129  static char *ultoa(unsigned long int val,char *buf, int base);
132  static char *ulltoa(unsigned long long int val,char *buf, int base);
133 
134 
135 
136 
137  // transform methods
138 
142  tString toString() const {return toString(mInteger);};
143 
147  static tString toString(int i);
148 
152  static tString toString(long i);
156  static tString toString(long long i);
157 
161  static tString toString(unsigned int i);
162 
166  static tString toString(unsigned long i);
170  static tString toString(unsigned long long i);
171 
172 
173 
177  static tString toString(const tRelativeInteger& i,const int& nDigits);
178 
179 
183  static tString toHexString(const tRelativeInteger& i,const int& nDigits);
184 
188  static tString toHexString(const tRelativeInteger& i);
189 
194 
197  static long int parseInt(tString str);
200  static unsigned long long parseHex(const tString& str);
203  static unsigned long int parseUnsignedInt(tString str);
204 
208  inline static tBoolean parseBoolean(const tString& str) {
209  return (tBoolean) parseInt(str);
210  };
211 
218  static tInteger turnIntoPBase(tString str,tInteger p);
219 
222  inline void increment() {
223  mInteger++;
224  };
227  inline void decrement() {
228  mInteger--;
229  };
230 
231 };
232 
233 
234 #endif // end of ifndef
static tString toHexString(const tRelativeInteger &i, const int &nDigits)
return the hexadecimal string corresponding to the int integer
Definition: CORE_Integer.cpp:97
void increment()
increment the value
Definition: CORE_Integer.h:222
int shortValue() const
get the integer
Definition: CORE_Integer.h:94
static tString toBinString(tRelativeInteger i)
return the binary string corresponding to the int integer
Definition: CORE_Integer.cpp:110
static long int parseInt(tString str)
return the integer associated to the string
Definition: CORE_Integer.cpp:120
~CORE_Integer()
destriuctors
Definition: CORE_Integer.cpp:13
CORE_Integer(const tRelativeInteger &i)
create an integer initialize to i
Definition: CORE_Integer.cpp:8
#define tRelativeInteger
Definition: types.h:33
#define tBoolean
Definition: types.h:35
static char * ulltoa(unsigned long long int val, char *buf, int base)
C function which return the val val into string.
Definition: CORE_Integer.cpp:168
static SP::CORE_Integer New()
build an integer object
Definition: CORE_Integer.h:52
this class describes an integer
Definition: CORE_Integer.h:23
DEFINE_SPTR(CORE_Integer)
static char * ultoa(unsigned long int val, char *buf, int base)
C function which return the val val into string.
Definition: CORE_Integer.cpp:212
void setInteger(const tString &i)
set the integer to i
Definition: CORE_Integer.h:73
void setInteger(const tRelativeInteger &i)
set the integer to i
Definition: CORE_Integer.h:68
static unsigned long long parseHex(const tString &str)
return the integer associated to the hex string
Definition: CORE_Integer.cpp:130
void decrement()
decrement the value
Definition: CORE_Integer.h:227
static SP::CORE_Integer New(tRelativeInteger i)
build an integer object
Definition: CORE_Integer.h:59
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:142
static char * itoa(int val, char *buf, int base)
C function which return the val val into string.
Definition: CORE_Integer.cpp:233
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
static unsigned long int parseUnsignedInt(tString str)
return the integer associated to the string
Definition: CORE_Integer.cpp:155
static tInteger turnIntoPBase(tString str, tInteger p)
return the integer associated to str in base P
Definition: CORE_Integer.cpp:249
static char * utoa(unsigned int val, char *buf, int base)
C function which return the val val into string.
Definition: CORE_Integer.cpp:237
static char * ltoa(long int val, char *buf, int base)
C function which return the val val into string.
Definition: CORE_Integer.cpp:202
int intValue() const
get the integer
Definition: CORE_Integer.h:90
static int xtoi(const char *buffer, unsigned int *i)
C function which return the int value corresponding to buffer.
Definition: CORE_Integer.cpp:264
#define tInteger
Definition: types.h:32
static tBoolean parseBoolean(const tString &str)
return the integer associated to a boolean
Definition: CORE_Integer.h:208
static tBoolean isInteger(const tString &str)
return true if the str is an integer
Definition: CORE_Integer.cpp:240
static char * lltoa(long long int val, char *buf, int base)
C function which return the val val into string.
Definition: CORE_Integer.cpp:189
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
tRelativeInteger getInteger() const
get the integer
Definition: CORE_Integer.h:85