activemq-cpp-3.8.2
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/Comparable.h>
24 #include <string>
26 
27 namespace decaf{
28 namespace lang{
29 
30  class DECAF_API Integer : public Number,
31  public Comparable<Integer>,
32  public Comparable<int> {
33  private:
34 
35  // The primitive Integer value.
36  int value;
37 
38  public:
39 
41  static const int SIZE;
42 
44  static const int MAX_VALUE;
45 
47  static const int MIN_VALUE;
48 
49  public:
50 
55  Integer(int value);
56 
67  Integer(const std::string& value);
68 
69  virtual ~Integer() {
70  }
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 std::string& value);
218 
225  static int reverseBytes(int value);
226 
233  static int reverse(int value);
234 
258  static int parseInt(const std::string& s, int radix);
259 
271  static int parseInt(const std::string& s);
272 
278  static Integer valueOf(int value) {
279  return Integer(value);
280  }
281 
292  static Integer valueOf(const std::string& value);
293 
306  static Integer valueOf(const std::string& value, int radix);
307 
316  static int bitCount(int value);
317 
324  static std::string toString(int value);
325 
349  static std::string toString(int value, int radix);
350 
370  static std::string toHexString(int value);
371 
390  static std::string toOctalString(int value);
391 
409  static std::string toBinaryString(int value);
410 
421  static int highestOneBit(int value);
422 
433  static int lowestOneBit(int value);
434 
452  static int numberOfLeadingZeros(int value);
453 
464  static int numberOfTrailingZeros(int value);
465 
483  static int rotateLeft(int value, int distance);
484 
502  static int rotateRight(int value, int distance);
503 
511  static int signum(int value);
512 
513  private:
514 
515  static int parse(const std::string& value, int offset, int radix, bool negative);
516 
517  };
518 
519 }}
520 
521 #endif /*_DECAF_LANG_INTEGER_H_*/
virtual int intValue() const
Answers the int value which the receiver represents.
Definition: Integer.h:187
static Integer valueOf(int value)
Returns a Integer instance representing the specified int value.
Definition: Integer.h:278
bool equals(const int &i) const
Definition: Integer.h:123
static const int MIN_VALUE
The minimum value that the primitive type can hold.
Definition: Integer.h:47
virtual bool operator==(const int &i) const
Compares equality between this object and the one passed.
Definition: Integer.h:132
virtual long long longValue() const
Answers the long value which the receiver represents.
Definition: Integer.h:195
virtual unsigned char byteValue() const
Answers the byte value which the receiver represents.
Definition: Integer.h:171
bool equals(const Integer &i) const
Definition: Integer.h:86
virtual bool operator==(const Integer &i) const
Compares equality between this object and the one passed.
Definition: Integer.h:95
Definition: Integer.h:30
The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short.
Definition: Number.h:35
virtual ~Integer()
Definition: Integer.h:69
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 float floatValue() const
Answers the float value which the receiver represents.
Definition: Integer.h:163
virtual double doubleValue() const
Answers the double value which the receiver represents.
Definition: Integer.h:155
#define DECAF_API
Definition: Config.h:29
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 short shortValue() const
Answers the short value which the receiver represents.
Definition: Integer.h:179
static const int MAX_VALUE
The maximum value that the primitive type can hold.
Definition: Integer.h:44
This interface imposes a total ordering on the objects of each class that implements it...
Definition: Comparable.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25
static const int SIZE
The size in bits of the primitive int type.
Definition: Integer.h:41