source: NonGTP/Xerces/xerces/include/xercesc/util/XMLAbstractDoubleFloat.hpp @ 358

Revision 358, 9.3 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Id: XMLAbstractDoubleFloat.hpp,v 1.24 2004/09/09 20:09:30 peiyongz Exp $
19 * $Log: XMLAbstractDoubleFloat.hpp,v $
20 * Revision 1.24  2004/09/09 20:09:30  peiyongz
21 * getDataOverflowed()
22 *
23 * Revision 1.23  2004/09/08 13:56:23  peiyongz
24 * Apache License Version 2.0
25 *
26 * Revision 1.22  2004/09/02 19:08:09  cargilld
27 * Fix API Doc warning message
28 *
29 * Revision 1.21  2004/08/11 16:50:47  peiyongz
30 * getValue()/isDataConverted()
31 *
32 * Revision 1.20  2004/01/29 11:48:46  cargilld
33 * Code cleanup changes to get rid of various compiler diagnostic messages.
34 *
35 * Revision 1.19  2004/01/13 19:50:56  peiyongz
36 * remove parseContent()
37 *
38 * Revision 1.17  2003/12/17 00:18:35  cargilld
39 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
40 *
41 * Revision 1.16  2003/12/11 21:38:12  peiyongz
42 * support for Canonical Representation for Datatype
43 *
44 * Revision 1.15  2003/10/15 14:50:01  peiyongz
45 * Bugzilla#22821: locale-sensitive function used to validate 'double' type, patch
46 * from jsweeney@spss.com (Jeff Sweeney)
47 *
48 * Revision 1.14  2003/09/23 18:16:07  peiyongz
49 * Inplementation for Serialization/Deserialization
50 *
51 * Revision 1.13  2003/05/18 14:02:05  knoaman
52 * Memory manager implementation: pass per instance manager.
53 *
54 * Revision 1.12  2003/05/16 06:01:53  knoaman
55 * Partial implementation of the configurable memory manager.
56 *
57 * Revision 1.11  2003/05/15 19:07:46  knoaman
58 * Partial implementation of the configurable memory manager.
59 *
60 * Revision 1.10  2003/05/09 15:13:46  peiyongz
61 * Deprecated toString() in XMLNumber family
62 *
63 * Revision 1.9  2003/03/10 20:55:58  peiyongz
64 * Schema Errata E2-40 double/float
65 *
66 * Revision 1.8  2003/02/02 23:54:43  peiyongz
67 * getFormattedString() added to return original and converted value.
68 *
69 * Revision 1.7  2003/01/30 21:55:22  tng
70 * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory.
71 *
72 * Revision 1.6  2002/12/11 00:20:02  peiyongz
73 * Doing businesss in value space. Converting out-of-bound value into special values.
74 *
75 * Revision 1.5  2002/11/04 15:22:05  tng
76 * C++ Namespace Support.
77 *
78 * Revision 1.4  2002/03/06 19:13:12  peiyongz
79 * Patch: more valid lexcial representation for positive/negative zero
80 *
81 * Revision 1.3  2002/03/01 18:47:37  peiyongz
82 * fix: more valid lexcial representation forms for "neural zero"
83 *
84 * Revision 1.2  2002/02/20 18:17:02  tng
85 * [Bug 5977] Warnings on generating apiDocs.
86 *
87 * Revision 1.1.1.1  2002/02/01 22:22:14  peiyongz
88 * sane_include
89 *
90 * Revision 1.4  2001/11/28 15:39:26  peiyongz
91 * return Type& for operator=
92 *
93 * Revision 1.3  2001/11/22 21:39:00  peiyongz
94 * Allow "0.0" to be a valid lexcial representation of ZERO.
95 *
96 * Revision 1.2  2001/11/22 20:23:00  peiyongz
97 * _declspec(dllimport) and inline warning C4273
98 *
99 * Revision 1.1  2001/11/19 21:33:42  peiyongz
100 * Reorganization: Double/Float
101 *
102 *
103 */
104
105#ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP
106#define XML_ABSTRACT_DOUBLE_FLOAT_HPP
107
108#include <xercesc/util/XMLNumber.hpp>
109#include <xercesc/util/PlatformUtils.hpp>
110
111XERCES_CPP_NAMESPACE_BEGIN
112
113/***
114 * 3.2.5.1 Lexical representation
115 *
116 *   double values have a lexical representation consisting of a mantissa followed,
117 *   optionally, by the character "E" or "e", followed by an exponent.
118 *
119 *   The exponent ·must· be an integer.
120 *   The mantissa must be a decimal number.
121 *   The representations for exponent and mantissa must follow the lexical rules
122 *   for integer and decimal.
123 *
124 *   If the "E" or "e" and the following exponent are omitted,
125 *   an exponent value of 0 is assumed.
126***/
127
128/***
129 * 3.2.4.1 Lexical representation
130 *
131 *   float values have a lexical representation consisting of a mantissa followed,
132 *   optionally, by the character "E" or "e", followed by an exponent.
133 *
134 *   The exponent ·must· be an integer.
135 *   The mantissa must be a decimal number.
136 *   The representations for exponent and mantissa must follow the lexical rules
137 *   for integer and decimal.
138 *
139 *   If the "E" or "e" and the following exponent are omitted,
140 *   an exponent value of 0 is assumed.
141***/
142
143class XMLUTIL_EXPORT XMLAbstractDoubleFloat : public XMLNumber
144{
145public:
146
147    enum LiteralType
148    {
149        NegINF,
150        PosINF,
151        NaN,
152        SpecialTypeNum,
153        Normal
154    };
155
156    virtual ~XMLAbstractDoubleFloat();
157
158    static XMLCh* getCanonicalRepresentation
159                        (
160                          const XMLCh*         const rawData
161                        ,       MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
162                        );
163
164    /**
165     *
166     *  Deprecated: please use getRawData
167     *
168     */
169    virtual XMLCh*        toString() const;
170   
171    virtual XMLCh*        getRawData() const;
172
173    virtual const XMLCh*  getFormattedString() const;
174
175    virtual int           getSign() const;
176
177    MemoryManager*        getMemoryManager() const;
178
179    inline  bool          isDataConverted()  const;
180
181    inline  bool          isDataOverflowed()  const;
182
183    inline  double        getValue() const;
184
185    /***
186     *
187     * The decimal point delimiter for the schema double/float type is
188     * defined to be a period and is not locale-specific. So, it must
189     * be replaced with the local-specific delimiter before converting
190     * from string to double/float.
191     *
192     ***/
193    void                  normalizeDecimalPoint(char* const toNormal);
194
195    /***
196     * Support for Serialization/De-serialization
197     ***/
198    DECL_XSERIALIZABLE(XMLAbstractDoubleFloat)
199
200protected:
201
202    //
203    // To be used by derived class exclusively
204    //
205    XMLAbstractDoubleFloat(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
206
207    void                  init(const XMLCh* const strValue);
208
209    /**
210         * Compares this object to the specified object.
211         * The result is <code>true</code> if and only if the argument is not
212         * <code>null</code> and is an <code>XMLAbstractDoubleFloat</code> object that contains
213         * the same <code>int</code> value as this object.
214         *
215         * @param   lValue the object to compare with.
216         * @param   rValue the object to compare against.
217     * @param manager The MemoryManager to use to allocate objects
218         * @return  <code>true</code> if the objects are the same;
219         *          <code>false</code> otherwise.
220         */
221
222    static int            compareValues(const XMLAbstractDoubleFloat* const lValue
223                                      , const XMLAbstractDoubleFloat* const rValue
224                                      , MemoryManager* const manager);
225
226    //
227    // to be overwritten by derived class
228    //
229    virtual void          checkBoundary(const XMLCh* const strValue) = 0;
230
231private:
232    //
233    // Unimplemented
234    //
235    // copy ctor
236    // assignment ctor
237    //
238    XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy);
239    XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign);
240
241        void                  normalizeZero(XMLCh* const);
242
243    inline bool           isSpecialValue() const;
244
245    static int            compareSpecial(const XMLAbstractDoubleFloat* const specialValue                                       
246                                       , MemoryManager* const manager);
247
248    void                  formatString();
249
250protected:
251    double                  fValue;
252    LiteralType             fType;
253    bool                    fDataConverted;
254    bool                    fDataOverflowed;
255
256private:
257    int                     fSign;
258    XMLCh*                  fRawData;
259
260    //
261    // If the original string is not lexcially the same as the five
262    // special value notations, and the value is converted to
263    // special value due underlying platform restriction on data
264    // representation, then this string is constructed and
265    // takes the form "original_string (special_value_notation)",
266    // otherwise it is empty.
267    //
268    XMLCh*                  fFormattedString;
269    MemoryManager*          fMemoryManager;
270
271};
272
273inline bool XMLAbstractDoubleFloat::isSpecialValue() const
274{
275    return (fType < SpecialTypeNum);
276}
277
278inline MemoryManager* XMLAbstractDoubleFloat::getMemoryManager() const
279{
280    return fMemoryManager;
281}
282
283inline bool XMLAbstractDoubleFloat::isDataConverted() const
284{
285    return fDataConverted;
286}
287
288inline bool XMLAbstractDoubleFloat::isDataOverflowed() const
289{
290    return fDataOverflowed;
291}
292
293inline double XMLAbstractDoubleFloat::getValue() const
294{
295    return fValue;
296}
297
298XERCES_CPP_NAMESPACE_END
299
300#endif
Note: See TracBrowser for help on using the repository browser.