activemq-cpp-3.4.0

src/main/decaf/lang/Byte.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_BYTE_H_
00019 #define _DECAF_LANG_BYTE_H_
00020 
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Number.h>
00023 #include <decaf/lang/Comparable.h>
00024 #include <decaf/lang/exceptions/NumberFormatException.h>
00025 #include <string>
00026 
00027 namespace decaf{
00028 namespace lang{
00029 
00030     class DECAF_API Byte : public Number,
00031                            public Comparable<Byte>,
00032                            public Comparable<unsigned char> {
00033     private:
00034 
00035         unsigned char value;
00036 
00037     public:
00038 
00040         static const unsigned char MIN_VALUE = 0x7F;
00041 
00043         static const unsigned char MAX_VALUE = 0x80;
00044 
00046         static const int SIZE = 8;
00047 
00048     public:
00049 
00053         Byte( unsigned char value );
00054 
00063         Byte( const std::string& value );
00064 
00065         virtual ~Byte() {}
00066 
00075         virtual int compareTo( const Byte& c ) const {
00076             return this->value < c.value ? -1 : (this->value > c.value) ? 1 : 0;
00077         }
00078 
00084         virtual bool operator==( const Byte& c ) const {
00085             return this->value == c.value;
00086         }
00087 
00094         virtual bool operator<( const Byte& c ) const {
00095             return this->value < c.value;
00096         }
00097 
00106         virtual int compareTo( const unsigned char& c ) const {
00107             return this->value < c ? -1 : (this->value > c) ? 1 : 0;
00108         }
00109 
00115         virtual bool operator==( const unsigned char& c ) const {
00116             return this->value == c;
00117         }
00118 
00125         virtual bool operator<( const unsigned char& c ) const {
00126             return this->value < c;
00127         }
00128 
00132         bool equals( const Byte& c ) const {
00133             return this->value == c.value;
00134         }
00135 
00139         bool equals( const unsigned char& c ) const {
00140             return this->value == c;
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 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 (long long)this->value;
00194         }
00195 
00196     public:    // statics
00197 
00201         static std::string toString( unsigned char value );
00202 
00218         static Byte decode( const std::string& value );
00219 
00245         static unsigned char parseByte( const std::string& s, int radix );
00246 
00258         static unsigned char parseByte( const std::string& s );
00259 
00265         static Byte valueOf( unsigned char value ) {
00266             return Byte( value );
00267         }
00268 
00279         static Byte valueOf( const std::string& value );
00280 
00294         static Byte valueOf( const std::string& value, int radix );
00295 
00296     };
00297 
00298 }}
00299 
00300 #endif /*_DECAF_LANG_BYTE_H_*/