activemq-cpp-3.9.5
Integer.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_LANG_INTEGER_H_
19#define _DECAF_LANG_INTEGER_H_
20
21#include <decaf/util/Config.h>
22#include <decaf/lang/Number.h>
23#include <decaf/lang/String.h>
25#include <string>
27
28namespace decaf{
29namespace lang{
30
31 class DECAF_API Integer : public Number,
32 public Comparable<Integer>,
33 public Comparable<int> {
34 private:
35
36 // The primitive Integer value.
37 int value;
38
39 public:
40
42 static const int SIZE;
43
45 static const int MAX_VALUE;
46
48 static const int MIN_VALUE;
49
50 public:
51
56 Integer(int value);
57
68 Integer(const std::string& value);
69
70 virtual ~Integer();
71
80 virtual int compareTo(const Integer& i) const;
81
86 bool equals(const Integer& i) const {
87 return this->value == i.value;
88 }
89
95 virtual bool operator==(const Integer& i) const {
96 return this->value == i.value;
97 }
98
105 virtual bool operator<(const Integer& i) const {
106 return this->value < i.value;
107 }
108
117 virtual int compareTo(const int& i) const;
118
123 bool equals(const int& i) const {
124 return this->value == i;
125 }
126
132 virtual bool operator==(const int& i) const {
133 return this->value == i;
134 }
135
142 virtual bool operator<(const int& i) const {
143 return this->value < i;
144 }
145
149 std::string toString() const;
150
155 virtual double doubleValue() const {
156 return (double) this->value;
157 }
158
163 virtual float floatValue() const {
164 return (float) this->value;
165 }
166
171 virtual unsigned char byteValue() const {
172 return (unsigned char) this->value;
173 }
174
179 virtual short shortValue() const {
180 return (short) this->value;
181 }
182
187 virtual int intValue() const {
188 return this->value;
189 }
190
195 virtual long long longValue() const {
196 return (long long) this->value;
197 }
198
199 public:
200 // Statics
201
217 static Integer decode(const String& value);
218
225 static int reverseBytes(int value);
226
233 static int reverse(int value);
234
258 static int parseInt(const String& s, int radix);
259
274 static int parseInt(const String& s);
275
284 static Integer valueOf(int value) {
285 return Integer(value);
286 }
287
298 static Integer valueOf(const String& value);
299
312 static Integer valueOf(const String& value, int radix);
313
322 static int bitCount(int value);
323
330 static std::string toString(int value);
331
355 static std::string toString(int value, int radix);
356
376 static std::string toHexString(int value);
377
396 static std::string toOctalString(int value);
397
415 static std::string toBinaryString(int value);
416
427 static int highestOneBit(int value);
428
439 static int lowestOneBit(int value);
440
458 static int numberOfLeadingZeros(int value);
459
470 static int numberOfTrailingZeros(int value);
471
489 static int rotateLeft(int value, int distance);
490
508 static int rotateRight(int value, int distance);
509
517 static int signum(int value);
518
519 private:
520
521 static int parse(const String& value, int offset, int radix, bool negative);
522
523 };
524
525}}
526
527#endif /*_DECAF_LANG_INTEGER_H_*/
This interface imposes a total ordering on the objects of each class that implements it.
Definition Comparable.h:33
virtual unsigned char byteValue() const
Answers the byte value which the receiver represents.
Definition Integer.h:171
static int signum(int value)
Returns the signum function of the specified int value.
static int parseInt(const String &s)
Parses the string argument as a signed decimal int.
static std::string toBinaryString(int value)
Returns a string representation of the integer argument as an unsigned integer in base 2.
virtual int compareTo(const int &i) const
Compares this Integer instance with another.
virtual int intValue() const
Answers the int value which the receiver represents.
Definition Integer.h:187
Integer(const std::string &value)
Constructs a new Integer and attempts to convert the given string to an int value,...
static int rotateLeft(int value, int distance)
Returns the value obtained by rotating the two's complement binary representation of the specified in...
static int bitCount(int value)
Returns the number of one-bits in the two's complement binary representation of the specified int val...
static std::string toString(int value)
Converts the int to a String representation.
virtual int compareTo(const Integer &i) const
Compares this Integer instance with another.
static int parseInt(const String &s, int radix)
Parses the string argument as a signed int in the radix specified by the second argument.
virtual bool operator==(const Integer &i) const
Compares equality between this object and the one passed.
Definition Integer.h:95
static std::string toOctalString(int value)
Returns a string representation of the integer argument as an unsigned integer in base 8.
static Integer valueOf(const String &value)
Returns a Integer object holding the value given by the specified std::string.
virtual bool operator<(const Integer &i) const
Compares this object to another and returns true if this object is considered to be less than the one...
Definition Integer.h:105
static int numberOfTrailingZeros(int value)
Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complem...
virtual bool operator==(const int &i) const
Compares equality between this object and the one passed.
Definition Integer.h:132
static std::string toHexString(int value)
Returns a string representation of the integer argument as an unsigned integer in base 16.
static Integer valueOf(const String &value, int radix)
Returns a Integer object holding the value extracted from the specified std::string when parsed with ...
static int lowestOneBit(int value)
Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost")...
virtual long long longValue() const
Answers the long value which the receiver represents.
Definition Integer.h:195
static Integer valueOf(int value)
Returns a Integer instance representing the specified int value.
Definition Integer.h:284
virtual double doubleValue() const
Answers the double value which the receiver represents.
Definition Integer.h:155
virtual float floatValue() const
Answers the float value which the receiver represents.
Definition Integer.h:163
bool equals(const Integer &i) const
Definition Integer.h:86
static const int MAX_VALUE
The maximum value that the primitive type can hold.
Definition Integer.h:45
static int highestOneBit(int value)
Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost")...
static int numberOfLeadingZeros(int value)
Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complem...
bool equals(const int &i) const
Definition Integer.h:123
static Integer decode(const String &value)
Decodes a String into a Integer.
virtual bool operator<(const int &i) const
Compares this object to another and returns true if this object is considered to be less than the one...
Definition Integer.h:142
static std::string toString(int value, int radix)
Returns a string representation of the first argument in the radix specified by the second argument.
static int rotateRight(int value, int distance)
Returns the value obtained by rotating the two's complement binary representation of the specified in...
static const int MIN_VALUE
The minimum value that the primitive type can hold.
Definition Integer.h:48
virtual short shortValue() const
Answers the short value which the receiver represents.
Definition Integer.h:179
static int reverseBytes(int value)
Returns the value obtained by reversing the order of the bytes in the two's complement representation...
static int reverse(int value)
Returns the value obtained by reversing the order of the bits in the two's complement binary represen...
static const int SIZE
The size in bits of the primitive int type.
Definition Integer.h:42
std::string toString() const
The abstract class Number is the superclass of classes Byte, Double, Float, Integer,...
Definition Number.h:35
An immutable sequence of characters.
Definition String.h:57
#define DECAF_API
Definition Config.h:29
Definition ThreadingTypes.h:31
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25