activemq-cpp-3.6.0
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 primitve Integer value.
36  int value;
37 
38  public:
39 
41  static const int SIZE = 32;
42 
44  static const int MAX_VALUE = (int)0x7FFFFFFF;
45 
47  static const int MIN_VALUE = (int)0x80000000;
48 
49  public:
50 
55  Integer( int value );
56 
67  Integer( const std::string& value );
68 
69  virtual ~Integer() {}
70 
79  virtual int compareTo( const Integer& i ) const;
80 
85  bool equals( const Integer& i ) const {
86  return this->value == i.value;
87  }
88 
94  virtual bool operator==( const Integer& i ) const {
95  return this->value == i.value;
96  }
97 
104  virtual bool operator<( const Integer& i ) const {
105  return this->value < i.value;
106  }
107 
116  virtual int compareTo( const int& i ) const;
117 
122  bool equals( const int& i ) const {
123  return this->value == i;
124  }
125 
131  virtual bool operator==( const int& i ) const {
132  return this->value == i;
133  }
134 
141  virtual bool operator<( const int& i ) const {
142  return this->value < i;
143  }
144 
148  std::string toString() const;
149 
154  virtual double doubleValue() const {
155  return (double)this->value;
156  }
157 
162  virtual float floatValue() const {
163  return (float)this->value;
164  }
165 
170  virtual unsigned char byteValue() const {
171  return (unsigned char)this->value;
172  }
173 
178  virtual short shortValue() const {
179  return (short)this->value;
180  }
181 
186  virtual int intValue() const {
187  return this->value;
188  }
189 
194  virtual long long longValue() const {
195  return (long long)this->value;
196  }
197 
198  public: // Statics
199 
215  static Integer decode( const std::string& value );
216 
223  static int reverseBytes( int value );
224 
231  static int reverse( int value );
232 
256  static int parseInt( const std::string& s, int radix );
257 
269  static int parseInt( const std::string& s );
270 
276  static Integer valueOf( int value ) {
277  return Integer( value );
278  }
279 
290  static Integer valueOf( const std::string& value );
291 
304  static Integer valueOf( const std::string& value, int radix );
305 
314  static int bitCount( int value );
315 
322  static std::string toString( int value );
323 
347  static std::string toString( int value, int radix );
348 
368  static std::string toHexString( int value );
369 
388  static std::string toOctalString( int value );
389 
407  static std::string toBinaryString( int value );
408 
419  static int highestOneBit( int value );
420 
431  static int lowestOneBit( int value );
432 
450  static int numberOfLeadingZeros( int value );
451 
462  static int numberOfTrailingZeros( int value );
463 
481  static int rotateLeft( int value, int distance );
482 
500  static int rotateRight( int value, int distance );
501 
509  static int signum( int value );
510 
511  private:
512 
513  static int parse( const std::string& value, int offset,
514  int radix, bool negative );
515 
516  };
517 
518 }}
519 
520 #endif /*_DECAF_LANG_INTEGER_H_*/