00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_LANG_LONG_H_
00019 #define _DECAF_LANG_LONG_H_
00020
00021 #include <decaf/lang/Number.h>
00022 #include <decaf/lang/Comparable.h>
00023 #include <decaf/lang/exceptions/NumberFormatException.h>
00024 #include <string>
00025
00026 namespace decaf{
00027 namespace lang{
00028
00029 class DECAF_API Long : public Number,
00030 public Comparable<Long>,
00031 public Comparable<long long> {
00032 private:
00033
00034
00035 long long value;
00036
00037 public:
00038
00040 static const int SIZE;
00041
00043 static const long long MAX_VALUE;
00044
00046 static const long long MIN_VALUE;
00047
00048 public:
00049
00053 Long(long long value);
00054
00065 Long(const std::string& value);
00066
00067 virtual ~Long() {
00068 }
00069
00078 virtual int compareTo(const Long& l) const;
00079
00084 bool equals(const Long& l) const {
00085 return this->value == l.value;
00086 }
00087
00093 virtual bool operator==(const Long& l) const {
00094 return this->value == l.value;
00095 }
00096
00103 virtual bool operator<(const Long& l) const {
00104 return this->value < l.value;
00105 }
00106
00115 virtual int compareTo(const long long& l) const;
00116
00121 bool equals(const long long& l) const {
00122 return this->value == l;
00123 }
00124
00130 virtual bool operator==(const long long& l) const {
00131 return this->value == l;
00132 }
00133
00140 virtual bool operator<(const long long& l) const {
00141 return this->value < l;
00142 }
00143
00147 std::string toString() const;
00148
00153 virtual double doubleValue() const {
00154 return (double) this->value;
00155 }
00156
00161 virtual float floatValue() const {
00162 return (float) this->value;
00163 }
00164
00169 virtual unsigned char byteValue() const {
00170 return (unsigned char) this->value;
00171 }
00172
00177 virtual short shortValue() const {
00178 return (short) this->value;
00179 }
00180
00185 virtual int intValue() const {
00186 return (int) this->value;
00187 }
00188
00193 virtual long long longValue() const {
00194 return this->value;
00195 }
00196
00197 public:
00198
00207 static int bitCount(long long value);
00208
00224 static Long decode(const std::string& value);
00225
00236 static long long highestOneBit(long long value);
00237
00248 static long long lowestOneBit(long long value);
00249
00267 static int numberOfLeadingZeros(long long value);
00268
00279 static int numberOfTrailingZeros(long long value);
00280
00294 static long long parseLong(const std::string& value);
00295
00308 static long long parseLong(const std::string& value, int radix);
00309
00316 static long long reverseBytes(long long value);
00317
00324 static long long reverse(long long value);
00325
00343 static long long rotateLeft(long long value, int distance);
00344
00362 static long long rotateRight(long long value, int distance);
00363
00371 static int signum(long long value);
00372
00378 static std::string toString(long long value);
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 static std::string toString(long long value, int radix);
00404
00424 static std::string toHexString(long long value);
00425
00444 static std::string toOctalString(long long value);
00445
00461 static std::string toBinaryString(long long value);
00462
00468 static Long valueOf(long long value) {
00469 return Long(value);
00470 }
00471
00482 static Long valueOf(const std::string& value);
00483
00496 static Long valueOf(const std::string& value, int radix);
00497
00498 private:
00499
00500 static long long parse(const std::string& value, int offset, int radix, bool negative);
00501
00502 };
00503
00504 }}
00505
00506 #endif