- Main Page
- Related Pages
- Classes
- Files

# XMLAbstractDoubleFloat.hpp

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