activemq-cpp-3.3.0

src/main/decaf/lang/Long.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_LONG_H_
00019 #define _DECAF_LANG_LONG_H_
00020 
00021 #include <decaf/lang/Number.h>
00022 #include <decaf/lang/Comparable.h>
00023 #include <decaf/lang/exceptions/NumberFormatException.h>
00024 #include <string>
00025 
00026 namespace decaf{
00027 namespace lang{
00028 
00029     class DECAF_API Long : public Number,
00030                            public Comparable<Long>,
00031                            public Comparable<long long> {
00032     private:
00033 
00034         // The primitive long long value
00035         long long value;
00036 
00037     public:
00038 
00040         static const int SIZE = 64;
00041 
00043         static const long long MAX_VALUE = (long long)0x7FFFFFFFFFFFFFFFLL;
00044 
00046         static const long long MIN_VALUE = (long long)0x8000000000000000LL;
00047 
00048     public:
00049 
00053         Long( long long value );
00054 
00065         Long( const std::string& value );
00066 
00067         virtual ~Long() {}
00068 
00077         virtual int compareTo( const Long& l ) const;
00078 
00083         bool equals( const Long& l ) const {
00084             return this->value == l.value;
00085         }
00086 
00092         virtual bool operator==( const Long& l ) const {
00093             return this->value == l.value;
00094         }
00095 
00102         virtual bool operator<( const Long& l ) const {
00103             return this->value < l.value;
00104         }
00105 
00114         virtual int compareTo( const long long& l ) const;
00115 
00120         bool equals( const long long& l ) const {
00121             return this->value == l;
00122         }
00123 
00129         virtual bool operator==( const long long& l ) const {
00130             return this->value == l;
00131         }
00132 
00139         virtual bool operator<( const long long& l ) const {
00140             return this->value < l;
00141         }
00142 
00146         std::string toString() const;
00147 
00152         virtual double doubleValue() const {
00153             return (double)this->value;
00154         }
00155 
00160         virtual float floatValue() const {
00161             return (float)this->value;
00162         }
00163 
00168         virtual unsigned char byteValue() const {
00169             return (unsigned char)this->value;
00170         }
00171 
00176         virtual short shortValue() const {
00177             return (short)this->value;
00178         }
00179 
00184         virtual int intValue() const {
00185             return (int)this->value;
00186         }
00187 
00192         virtual long long longValue() const {
00193             return this->value;
00194         }
00195 
00196     public:
00197 
00206         static int bitCount( long long value );
00207 
00223         static Long decode( const std::string& value );
00224 
00235         static long long highestOneBit( long long value );
00236 
00247         static long long lowestOneBit( long long value );
00248 
00266         static int numberOfLeadingZeros( long long value );
00267 
00278         static int numberOfTrailingZeros( long long value );
00279 
00293         static long long parseLong( const std::string& value );
00294 
00307         static long long parseLong( const std::string& value, int radix );
00308 
00315         static long long reverseBytes( long long value );
00316 
00323         static long long reverse( long long value );
00324 
00342         static long long rotateLeft( long long value, int distance );
00343 
00361         static long long rotateRight( long long value, int distance );
00362 
00370         static int signum( long long value );
00371 
00377         static std::string toString( long long value );
00378 
00379         /*
00380          * Returns a string representation of the first argument in the radix
00381          * specified by the second argument.
00382          *
00383          * If the radix is smaller than Character.MIN_RADIX or larger than
00384          * Character.MAX_RADIX, then the radix 10 is used instead.
00385          *
00386          * If the first argument is negative, the first element of the result is
00387          * the ASCII minus character '-'. If the first argument is not
00388          * negative, no sign character appears in the result.
00389          *
00390          * The remaining characters of the result represent the magnitude of the
00391          * first argument. If the magnitude is zero, it is represented by a single
00392          *  zero character '0'; otherwise, the first character of the
00393          * representation of the magnitude will not be the zero character. The
00394          * following ASCII characters are used as digits:
00395          *
00396          *    0123456789abcdefghijklmnopqrstuvwxyz
00397          *
00398          * @param value - the long long to convert to a string
00399          * @param radix - the radix to format the string in
00400          * @returns an long long formatted to the string value of the radix given.
00401          */
00402         static std::string toString( long long value, int radix );
00403 
00423         static std::string toHexString( long long value );
00424 
00443         static std::string toOctalString( long long value );
00444 
00460         static std::string toBinaryString( long long value );
00461 
00467         static Long valueOf( long long value ) {
00468             return Long( value );
00469         }
00470 
00481         static Long valueOf( const std::string& value );
00482 
00495         static Long valueOf( const std::string& value, int radix );
00496 
00497     private:
00498 
00499         static long long parse( const std::string& value, int offset,
00500                                 int radix, bool negative );
00501 
00502     };
00503 
00504 }}
00505 
00506 #endif /*_DECAF_LANG_LONG_H_*/