activemq-cpp-3.3.0

src/main/decaf/lang/Integer.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef _DECAF_LANG_INTEGER_H_
00019 #define _DECAF_LANG_INTEGER_H_
00020 
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Number.h>
00023 #include <decaf/lang/Comparable.h>
00024 #include <string>
00025 #include <decaf/lang/exceptions/NumberFormatException.h>
00026 
00027 namespace decaf{
00028 namespace lang{
00029 
00030     class DECAF_API Integer : public Number,
00031                               public Comparable<Integer>,
00032                               public Comparable<int> {
00033     private:
00034 
00035         // The primitve Integer value.
00036         int value;
00037 
00038     public:
00039 
00041         static const int SIZE = 32;
00042 
00044         static const int MAX_VALUE = (int)0x7FFFFFFF;
00045 
00047         static const int MIN_VALUE = (int)0x80000000;
00048 
00049     public:
00050 
00055         Integer( int value );
00056 
00067         Integer( const std::string& value );
00068 
00069         virtual ~Integer() {}
00070 
00079         virtual int compareTo( const Integer& i ) const;
00080 
00085         bool equals( const Integer& i ) const {
00086             return this->value == i.value;
00087         }
00088 
00094         virtual bool operator==( const Integer& i ) const {
00095             return this->value == i.value;
00096         }
00097 
00104         virtual bool operator<( const Integer& i ) const {
00105             return this->value < i.value;
00106         }
00107 
00116         virtual int compareTo( const int& i ) const;
00117 
00122         bool equals( const int& i ) const {
00123             return this->value == i;
00124         }
00125 
00131         virtual bool operator==( const int& i ) const {
00132             return this->value == i;
00133         }
00134 
00141         virtual bool operator<( const int& i ) const {
00142             return this->value < i;
00143         }
00144 
00148         std::string toString() const;
00149 
00154         virtual double doubleValue() const {
00155             return (double)this->value;
00156         }
00157 
00162         virtual float floatValue() const {
00163             return (float)this->value;
00164         }
00165 
00170         virtual unsigned char byteValue() const {
00171             return (unsigned char)this->value;
00172         }
00173 
00178         virtual short shortValue() const {
00179             return (short)this->value;
00180         }
00181 
00186         virtual int intValue() const {
00187             return this->value;
00188         }
00189 
00194         virtual long long longValue() const {
00195             return (long long)this->value;
00196         }
00197 
00198     public:  // Statics
00199 
00215         static Integer decode( const std::string& value );
00216 
00223         static int reverseBytes( int value );
00224 
00231         static int reverse( int value );
00232 
00256         static int parseInt( const std::string& s, int radix );
00257 
00269         static int parseInt( const std::string& s );
00270 
00276         static Integer valueOf( int value ) {
00277             return Integer( value );
00278         }
00279 
00290         static Integer valueOf( const std::string& value );
00291 
00304         static Integer valueOf( const std::string& value, int radix );
00305 
00314         static int bitCount( int value );
00315 
00322         static std::string toString( int value );
00323 
00347         static std::string toString( int value, int radix );
00348 
00368         static std::string toHexString( int value );
00369 
00388         static std::string toOctalString( int value );
00389 
00407         static std::string toBinaryString( int value );
00408 
00419         static int highestOneBit( int value );
00420 
00431         static int lowestOneBit( int value );
00432 
00450         static int numberOfLeadingZeros( int value );
00451 
00462         static int numberOfTrailingZeros( int value );
00463 
00481         static int rotateLeft( int value, int distance );
00482 
00500         static int rotateRight( int value, int distance );
00501 
00509         static int signum( int value );
00510 
00511     private:
00512 
00513         static int parse( const std::string& value, int offset,
00514                           int radix, bool negative );
00515 
00516     };
00517 
00518 }}
00519 
00520 #endif /*_DECAF_LANG_INTEGER_H_*/