00001 /* 00002 * Copyright 2001,2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /* 00018 * $Id: XMLAbstractDoubleFloat.hpp,v 1.24 2004/09/09 20:09:30 peiyongz Exp $ 00019 * $Log: XMLAbstractDoubleFloat.hpp,v $ 00020 * Revision 1.24 2004/09/09 20:09:30 peiyongz 00021 * getDataOverflowed() 00022 * 00023 * Revision 1.23 2004/09/08 13:56:23 peiyongz 00024 * Apache License Version 2.0 00025 * 00026 * Revision 1.22 2004/09/02 19:08:09 cargilld 00027 * Fix API Doc warning message 00028 * 00029 * Revision 1.21 2004/08/11 16:50:47 peiyongz 00030 * getValue()/isDataConverted() 00031 * 00032 * Revision 1.20 2004/01/29 11:48:46 cargilld 00033 * Code cleanup changes to get rid of various compiler diagnostic messages. 00034 * 00035 * Revision 1.19 2004/01/13 19:50:56 peiyongz 00036 * remove parseContent() 00037 * 00038 * Revision 1.17 2003/12/17 00:18:35 cargilld 00039 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. 00040 * 00041 * Revision 1.16 2003/12/11 21:38:12 peiyongz 00042 * support for Canonical Representation for Datatype 00043 * 00044 * Revision 1.15 2003/10/15 14:50:01 peiyongz 00045 * Bugzilla#22821: locale-sensitive function used to validate 'double' type, patch 00046 * from jsweeney@spss.com (Jeff Sweeney) 00047 * 00048 * Revision 1.14 2003/09/23 18:16:07 peiyongz 00049 * Inplementation for Serialization/Deserialization 00050 * 00051 * Revision 1.13 2003/05/18 14:02:05 knoaman 00052 * Memory manager implementation: pass per instance manager. 00053 * 00054 * Revision 1.12 2003/05/16 06:01:53 knoaman 00055 * Partial implementation of the configurable memory manager. 00056 * 00057 * Revision 1.11 2003/05/15 19:07:46 knoaman 00058 * Partial implementation of the configurable memory manager. 00059 * 00060 * Revision 1.10 2003/05/09 15:13:46 peiyongz 00061 * Deprecated toString() in XMLNumber family 00062 * 00063 * Revision 1.9 2003/03/10 20:55:58 peiyongz 00064 * Schema Errata E2-40 double/float 00065 * 00066 * Revision 1.8 2003/02/02 23:54:43 peiyongz 00067 * getFormattedString() added to return original and converted value. 00068 * 00069 * Revision 1.7 2003/01/30 21:55:22 tng 00070 * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory. 00071 * 00072 * Revision 1.6 2002/12/11 00:20:02 peiyongz 00073 * Doing businesss in value space. Converting out-of-bound value into special values. 00074 * 00075 * Revision 1.5 2002/11/04 15:22:05 tng 00076 * C++ Namespace Support. 00077 * 00078 * Revision 1.4 2002/03/06 19:13:12 peiyongz 00079 * Patch: more valid lexcial representation for positive/negative zero 00080 * 00081 * Revision 1.3 2002/03/01 18:47:37 peiyongz 00082 * fix: more valid lexcial representation forms for "neural zero" 00083 * 00084 * Revision 1.2 2002/02/20 18:17:02 tng 00085 * [Bug 5977] Warnings on generating apiDocs. 00086 * 00087 * Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz 00088 * sane_include 00089 * 00090 * Revision 1.4 2001/11/28 15:39:26 peiyongz 00091 * return Type& for operator= 00092 * 00093 * Revision 1.3 2001/11/22 21:39:00 peiyongz 00094 * Allow "0.0" to be a valid lexcial representation of ZERO. 00095 * 00096 * Revision 1.2 2001/11/22 20:23:00 peiyongz 00097 * _declspec(dllimport) and inline warning C4273 00098 * 00099 * Revision 1.1 2001/11/19 21:33:42 peiyongz 00100 * Reorganization: Double/Float 00101 * 00102 * 00103 */ 00104 00105 #ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP 00106 #define XML_ABSTRACT_DOUBLE_FLOAT_HPP 00107 00108 #include <xercesc/util/XMLNumber.hpp> 00109 #include <xercesc/util/PlatformUtils.hpp> 00110 00111 XERCES_CPP_NAMESPACE_BEGIN 00112 00113 /*** 00114 * 3.2.5.1 Lexical representation 00115 * 00116 * double values have a lexical representation consisting of a mantissa followed, 00117 * optionally, by the character "E" or "e", followed by an exponent. 00118 * 00119 * The exponent ·must· be an integer. 00120 * The mantissa must be a decimal number. 00121 * The representations for exponent and mantissa must follow the lexical rules 00122 * for integer and decimal. 00123 * 00124 * If the "E" or "e" and the following exponent are omitted, 00125 * an exponent value of 0 is assumed. 00126 ***/ 00127 00128 /*** 00129 * 3.2.4.1 Lexical representation 00130 * 00131 * float values have a lexical representation consisting of a mantissa followed, 00132 * optionally, by the character "E" or "e", followed by an exponent. 00133 * 00134 * The exponent ·must· be an integer. 00135 * The mantissa must be a decimal number. 00136 * The representations for exponent and mantissa must follow the lexical rules 00137 * for integer and decimal. 00138 * 00139 * If the "E" or "e" and the following exponent are omitted, 00140 * an exponent value of 0 is assumed. 00141 ***/ 00142 00143 class XMLAbstractDoubleFloat : public XMLNumber 00144 { 00145 public: 00146 00147 enum LiteralType 00148 { 00149 NegINF, 00150 PosINF, 00151 NaN, 00152 SpecialTypeNum, 00153 Normal 00154 }; 00155 00156 virtual ~XMLAbstractDoubleFloat(); 00157 00158 static XMLCh* getCanonicalRepresentation 00159 ( 00160 const XMLCh* const rawData 00161 , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager 00162 ); 00163 00169 virtual XMLCh* toString() const; 00170 00171 virtual XMLCh* getRawData() const; 00172 00173 virtual const XMLCh* getFormattedString() const; 00174 00175 virtual int getSign() const; 00176 00177 MemoryManager* getMemoryManager() const; 00178 00179 inline bool isDataConverted() const; 00180 00181 inline bool isDataOverflowed() const; 00182 00183 inline double getValue() const; 00184 00185 /*** 00186 * 00187 * The decimal point delimiter for the schema double/float type is 00188 * defined to be a period and is not locale-specific. So, it must 00189 * be replaced with the local-specific delimiter before converting 00190 * from string to double/float. 00191 * 00192 ***/ 00193 void normalizeDecimalPoint(char* const toNormal); 00194 00195 /*** 00196 * Support for Serialization/De-serialization 00197 ***/ 00198 DECL_XSERIALIZABLE(XMLAbstractDoubleFloat) 00199 00200 protected: 00201 00202 // 00203 // To be used by derived class exclusively 00204 // 00205 XMLAbstractDoubleFloat(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 00206 00207 void init(const XMLCh* const strValue); 00208 00222 static int compareValues(const XMLAbstractDoubleFloat* const lValue 00223 , const XMLAbstractDoubleFloat* const rValue 00224 , MemoryManager* const manager); 00225 00226 // 00227 // to be overwritten by derived class 00228 // 00229 virtual void checkBoundary(const XMLCh* const strValue) = 0; 00230 00231 private: 00232 // 00233 // Unimplemented 00234 // 00235 // copy ctor 00236 // assignment ctor 00237 // 00238 XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy); 00239 XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign); 00240 00241 void normalizeZero(XMLCh* const); 00242 00243 inline bool isSpecialValue() const; 00244 00245 static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue 00246 , MemoryManager* const manager); 00247 00248 void formatString(); 00249 00250 protected: 00251 double fValue; 00252 LiteralType fType; 00253 bool fDataConverted; 00254 bool fDataOverflowed; 00255 00256 private: 00257 int fSign; 00258 XMLCh* fRawData; 00259 00260 // 00261 // If the original string is not lexcially the same as the five 00262 // special value notations, and the value is converted to 00263 // special value due underlying platform restriction on data 00264 // representation, then this string is constructed and 00265 // takes the form "original_string (special_value_notation)", 00266 // otherwise it is empty. 00267 // 00268 XMLCh* fFormattedString; 00269 MemoryManager* fMemoryManager; 00270 00271 }; 00272 00273 inline bool XMLAbstractDoubleFloat::isSpecialValue() const 00274 { 00275 return (fType < SpecialTypeNum); 00276 } 00277 00278 inline MemoryManager* XMLAbstractDoubleFloat::getMemoryManager() const 00279 { 00280 return fMemoryManager; 00281 } 00282 00283 inline bool XMLAbstractDoubleFloat::isDataConverted() const 00284 { 00285 return fDataConverted; 00286 } 00287 00288 inline bool XMLAbstractDoubleFloat::isDataOverflowed() const 00289 { 00290 return fDataOverflowed; 00291 } 00292 00293 inline double XMLAbstractDoubleFloat::getValue() const 00294 { 00295 return fValue; 00296 } 00297 00298 XERCES_CPP_NAMESPACE_END 00299 00300 #endif