00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_LANG_INTEGER_H_
00019 #define _DECAF_LANG_INTEGER_H_
00020
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Number.h>
00023 #include <decaf/lang/Comparable.h>
00024 #include <string>
00025 #include <decaf/lang/exceptions/NumberFormatException.h>
00026
00027 namespace decaf{
00028 namespace lang{
00029
00030 class DECAF_API Integer : public Number,
00031 public Comparable<Integer>,
00032 public Comparable<int> {
00033 private:
00034
00035
00036 int value;
00037
00038 public:
00039
00041 static const int SIZE;
00042
00044 static const int MAX_VALUE;
00045
00047 static const int MIN_VALUE;
00048
00049 public:
00050
00055 Integer(int value);
00056
00067 Integer(const std::string& value);
00068
00069 virtual ~Integer() {
00070 }
00071
00080 virtual int compareTo(const Integer& i) const;
00081
00086 bool equals(const Integer& i) const {
00087 return this->value == i.value;
00088 }
00089
00095 virtual bool operator==(const Integer& i) const {
00096 return this->value == i.value;
00097 }
00098
00105 virtual bool operator<(const Integer& i) const {
00106 return this->value < i.value;
00107 }
00108
00117 virtual int compareTo(const int& i) const;
00118
00123 bool equals(const int& i) const {
00124 return this->value == i;
00125 }
00126
00132 virtual bool operator==(const int& i) const {
00133 return this->value == i;
00134 }
00135
00142 virtual bool operator<(const int& i) const {
00143 return this->value < i;
00144 }
00145
00149 std::string toString() const;
00150
00155 virtual double doubleValue() const {
00156 return (double) this->value;
00157 }
00158
00163 virtual float floatValue() const {
00164 return (float) this->value;
00165 }
00166
00171 virtual unsigned char byteValue() const {
00172 return (unsigned char) this->value;
00173 }
00174
00179 virtual short shortValue() const {
00180 return (short) this->value;
00181 }
00182
00187 virtual int intValue() const {
00188 return this->value;
00189 }
00190
00195 virtual long long longValue() const {
00196 return (long long) this->value;
00197 }
00198
00199 public:
00200
00201
00217 static Integer decode(const std::string& value);
00218
00225 static int reverseBytes(int value);
00226
00233 static int reverse(int value);
00234
00258 static int parseInt(const std::string& s, int radix);
00259
00271 static int parseInt(const std::string& s);
00272
00278 static Integer valueOf(int value) {
00279 return Integer(value);
00280 }
00281
00292 static Integer valueOf(const std::string& value);
00293
00306 static Integer valueOf(const std::string& value, int radix);
00307
00316 static int bitCount(int value);
00317
00324 static std::string toString(int value);
00325
00349 static std::string toString(int value, int radix);
00350
00370 static std::string toHexString(int value);
00371
00390 static std::string toOctalString(int value);
00391
00409 static std::string toBinaryString(int value);
00410
00421 static int highestOneBit(int value);
00422
00433 static int lowestOneBit(int value);
00434
00452 static int numberOfLeadingZeros(int value);
00453
00464 static int numberOfTrailingZeros(int value);
00465
00483 static int rotateLeft(int value, int distance);
00484
00502 static int rotateRight(int value, int distance);
00503
00511 static int signum(int value);
00512
00513 private:
00514
00515 static int parse(const std::string& value, int offset, int radix, bool negative);
00516
00517 };
00518
00519 }}
00520
00521 #endif