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 /* 00019 * $Id: XMLAbstractDoubleFloat.hpp 568078 2007-08-21 11:43:25Z amassari $ 00020 */ 00021 00022 #ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP 00023 #define XML_ABSTRACT_DOUBLE_FLOAT_HPP 00024 00025 #include <xercesc/util/XMLNumber.hpp> 00026 #include <xercesc/util/PlatformUtils.hpp> 00027 00028 XERCES_CPP_NAMESPACE_BEGIN 00029 00030 /*** 00031 * 3.2.5.1 Lexical representation 00032 * 00033 * double values have a lexical representation consisting of a mantissa followed, 00034 * optionally, by the character "E" or "e", followed by an exponent. 00035 * 00036 * The exponent �must� be an integer. 00037 * The mantissa must be a decimal number. 00038 * The representations for exponent and mantissa must follow the lexical rules 00039 * for integer and decimal. 00040 * 00041 * If the "E" or "e" and the following exponent are omitted, 00042 * an exponent value of 0 is assumed. 00043 ***/ 00044 00045 /*** 00046 * 3.2.4.1 Lexical representation 00047 * 00048 * float values have a lexical representation consisting of a mantissa followed, 00049 * optionally, by the character "E" or "e", followed by an exponent. 00050 * 00051 * The exponent �must� be an integer. 00052 * The mantissa must be a decimal number. 00053 * The representations for exponent and mantissa must follow the lexical rules 00054 * for integer and decimal. 00055 * 00056 * If the "E" or "e" and the following exponent are omitted, 00057 * an exponent value of 0 is assumed. 00058 ***/ 00059 00060 class XMLUTIL_EXPORT XMLAbstractDoubleFloat : public XMLNumber 00061 { 00062 public: 00063 00064 enum LiteralType 00065 { 00066 NegINF, 00067 PosINF, 00068 NaN, 00069 SpecialTypeNum, 00070 Normal 00071 }; 00072 00073 virtual ~XMLAbstractDoubleFloat(); 00074 00075 static XMLCh* getCanonicalRepresentation 00076 ( 00077 const XMLCh* const rawData 00078 , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager 00079 ); 00080 00086 virtual XMLCh* toString() const; 00087 00088 virtual XMLCh* getRawData() const; 00089 00090 virtual const XMLCh* getFormattedString() const; 00091 00092 virtual int getSign() const; 00093 00094 MemoryManager* getMemoryManager() const; 00095 00096 inline bool isDataConverted() const; 00097 00098 inline bool isDataOverflowed() const; 00099 00100 inline double getValue() const; 00101 00102 inline LiteralType getType() const; 00103 00104 /*** 00105 * 00106 * The decimal point delimiter for the schema double/float type is 00107 * defined to be a period and is not locale-specific. So, it must 00108 * be replaced with the local-specific delimiter before converting 00109 * from string to double/float. 00110 * 00111 ***/ 00112 static void normalizeDecimalPoint(char* const toNormal); 00113 00114 /*** 00115 * Support for Serialization/De-serialization 00116 ***/ 00117 DECL_XSERIALIZABLE(XMLAbstractDoubleFloat) 00118 00119 protected: 00120 00121 // 00122 // To be used by derived class exclusively 00123 // 00124 XMLAbstractDoubleFloat(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 00125 00126 void init(const XMLCh* const strValue); 00127 00141 static int compareValues(const XMLAbstractDoubleFloat* const lValue 00142 , const XMLAbstractDoubleFloat* const rValue 00143 , MemoryManager* const manager); 00144 00145 // 00146 // to be overridden by derived class 00147 // 00148 virtual void checkBoundary(char* const strValue) = 0; 00149 00150 void 00151 convert(char* const strValue); 00152 00153 private: 00154 // 00155 // Unimplemented 00156 // 00157 // copy ctor 00158 // assignment ctor 00159 // 00160 XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy); 00161 XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign); 00162 00163 void normalizeZero(XMLCh* const); 00164 00165 inline bool isSpecialValue() const; 00166 00167 static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue 00168 , MemoryManager* const manager); 00169 00170 void formatString(); 00171 00172 protected: 00173 double fValue; 00174 LiteralType fType; 00175 bool fDataConverted; 00176 bool fDataOverflowed; 00177 00178 private: 00179 int fSign; 00180 XMLCh* fRawData; 00181 00182 // 00183 // If the original string is not lexcially the same as the five 00184 // special value notations, and the value is converted to 00185 // special value due underlying platform restriction on data 00186 // representation, then this string is constructed and 00187 // takes the form "original_string (special_value_notation)", 00188 // otherwise it is empty. 00189 // 00190 XMLCh* fFormattedString; 00191 MemoryManager* fMemoryManager; 00192 00193 }; 00194 00195 inline bool XMLAbstractDoubleFloat::isSpecialValue() const 00196 { 00197 return (fType < SpecialTypeNum); 00198 } 00199 00200 inline MemoryManager* XMLAbstractDoubleFloat::getMemoryManager() const 00201 { 00202 return fMemoryManager; 00203 } 00204 00205 inline bool XMLAbstractDoubleFloat::isDataConverted() const 00206 { 00207 return fDataConverted; 00208 } 00209 00210 inline bool XMLAbstractDoubleFloat::isDataOverflowed() const 00211 { 00212 return fDataOverflowed; 00213 } 00214 00215 inline double XMLAbstractDoubleFloat::getValue() const 00216 { 00217 return fValue; 00218 } 00219 00220 inline XMLAbstractDoubleFloat::LiteralType XMLAbstractDoubleFloat::getType() const 00221 { 00222 return fType; 00223 } 00224 00225 XERCES_CPP_NAMESPACE_END 00226 00227 #endif
1.5.4