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>
24 #include <decaf/lang/Comparable.h>
25 #include <string>
27 
28 namespace decaf{
29 namespace 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_*/
static Integer valueOf(int value)
Returns a Integer instance representing the specified int value.
Definition: Integer.h:284
static const int MIN_VALUE
The minimum value that the primitive type can hold.
Definition: Integer.h:48
bool equals(const Integer &i) const
Definition: Integer.h:86
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
virtual unsigned char byteValue() const
Answers the byte value which the receiver represents.
Definition: Integer.h:171
virtual float floatValue() const
Answers the float value which the receiver represents.
Definition: Integer.h:163
Definition: Integer.h:31
The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short.
Definition: Number.h:35
virtual double doubleValue() const
Answers the double value which the receiver represents.
Definition: Integer.h:155
virtual int intValue() const
Answers the int value which the receiver represents.
Definition: Integer.h:187
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
virtual bool operator==(const int &i) const
Compares equality between this object and the one passed.
Definition: Integer.h:132
virtual short shortValue() const
Answers the short value which the receiver represents.
Definition: Integer.h:179
An immutable sequence of characters.
Definition: String.h:57
#define DECAF_API
Definition: Config.h:29
static const int MAX_VALUE
The maximum value that the primitive type can hold.
Definition: Integer.h:45
virtual bool operator==(const Integer &i) const
Compares equality between this object and the one passed.
Definition: Integer.h:95
virtual long long longValue() const
Answers the long value which the receiver represents.
Definition: Integer.h:195
This interface imposes a total ordering on the objects of each class that implements it...
Definition: Comparable.h:33
static const int SIZE
The size in bits of the primitive int type.
Definition: Integer.h:42
bool equals(const int &i) const
Definition: Integer.h:123