activemq-cpp-3.4.0

src/main/decaf/lang/Character.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_CHARACTER_H_
00019 #define _DECAF_LANG_CHARACTER_H_
00020 
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Number.h>
00023 #include <decaf/lang/Comparable.h>
00024 #include <string>
00025 
00026 namespace decaf{
00027 namespace lang{
00028 
00029     class DECAF_API Character : public Number,
00030                                 public Comparable<Character>,
00031                                 public Comparable<char> {
00032     private:
00033 
00034         // The primitive Char value
00035         char value;
00036 
00037     public:
00038 
00040         static const int MIN_RADIX = 2;
00041 
00043         static const int MAX_RADIX = 36;
00044 
00046         static const char MIN_VALUE = (char)0x7F;
00047 
00049         static const char MAX_VALUE = (char)0x80;
00050 
00052         static const int SIZE = 8;
00053 
00054     public:
00055 
00059         Character( char value );
00060 
00069         virtual int compareTo( const Character& c ) const {
00070             return this->value < c.value ? -1 : (this->value > c.value) ? 1 : 0;
00071         }
00072 
00078         virtual bool operator==( const Character& c ) const {
00079             return this->value == c.value;
00080         }
00081 
00088         virtual bool operator<( const Character& c ) const {
00089             return this->value < c.value;
00090         }
00091 
00100         virtual int compareTo( const char& c ) const {
00101             return this->value < c ? -1 : (this->value > c) ? 1 : 0;
00102         }
00103 
00109         virtual bool operator==( const char& c ) const {
00110             return this->value == c;
00111         }
00112 
00119         virtual bool operator<( const char& c ) const {
00120             return this->value < c;
00121         }
00122 
00126         bool equals( const Character& c ) const {
00127             return this->value == c.value;
00128         }
00129 
00133         bool equals( const char& c ) const {
00134             return this->value == c;
00135         }
00136 
00140         std::string toString() const;
00141 
00146         virtual double doubleValue() const {
00147             return (double)this->value;
00148         }
00149 
00154         virtual float floatValue() const {
00155             return (float)this->value;
00156         }
00157 
00162         virtual unsigned char byteValue() const {
00163             return (unsigned char)this->value;
00164         }
00165 
00170         virtual short shortValue() const {
00171             return (short)this->value;
00172         }
00173 
00178         virtual int intValue() const {
00179             return (int)this->value;
00180         }
00181 
00186         virtual long long longValue() const {
00187             return (long long)this->value;
00188         }
00189 
00190     public:    // statics
00191 
00197         static Character valueOf( char value ) {
00198             return Character( value );
00199         }
00200 
00205         static bool isWhitespace( char c ){
00206             switch ( c )
00207             {
00208                 case '\n':
00209                 case '\t':
00210                 case '\r':
00211                 case '\f':
00212                 case ' ':
00213                     return true;
00214             }
00215 
00216             return false;
00217         }
00218 
00223         static bool isDigit( char c ){
00224             return c >= '0' && c <= '9';
00225         }
00226 
00231         static bool isLowerCase( char c ){
00232             return c >= 'a' && c <= 'z';
00233         }
00234 
00239         static bool isUpperCase( char c ){
00240             return c >= 'A' && c <= 'Z';
00241         }
00242 
00247         static bool isLetter( char c ){
00248             return isUpperCase(c) || isLowerCase(c);
00249         }
00250 
00255         static bool isLetterOrDigit( char c ){
00256             return isLetter(c) || isDigit(c);
00257         }
00258 
00265         static bool isISOControl( char c ) {
00266             return ( c >= 0 && c <= 0x1f ) ||
00267                    ( (unsigned char)c >= 0x7f && (unsigned char)c <= 0x9f );
00268         }
00269 
00292         static int digit( char c, int radix );
00293 
00294     };
00295 
00296 }}
00297 
00298 #endif /*_DECAF_LANG_CHARACTER_H_*/