1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 2001 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 2001, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Id: XMLAbstractDoubleFloat.hpp,v 1.20 2004/01/29 11:48:46 cargilld Exp $
|
---|
59 | * $Log: XMLAbstractDoubleFloat.hpp,v $
|
---|
60 | * Revision 1.20 2004/01/29 11:48:46 cargilld
|
---|
61 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
62 | *
|
---|
63 | * Revision 1.19 2004/01/13 19:50:56 peiyongz
|
---|
64 | * remove parseContent()
|
---|
65 | *
|
---|
66 | * Revision 1.17 2003/12/17 00:18:35 cargilld
|
---|
67 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
68 | *
|
---|
69 | * Revision 1.16 2003/12/11 21:38:12 peiyongz
|
---|
70 | * support for Canonical Representation for Datatype
|
---|
71 | *
|
---|
72 | * Revision 1.15 2003/10/15 14:50:01 peiyongz
|
---|
73 | * Bugzilla#22821: locale-sensitive function used to validate 'double' type, patch
|
---|
74 | * from jsweeney@spss.com (Jeff Sweeney)
|
---|
75 | *
|
---|
76 | * Revision 1.14 2003/09/23 18:16:07 peiyongz
|
---|
77 | * Inplementation for Serialization/Deserialization
|
---|
78 | *
|
---|
79 | * Revision 1.13 2003/05/18 14:02:05 knoaman
|
---|
80 | * Memory manager implementation: pass per instance manager.
|
---|
81 | *
|
---|
82 | * Revision 1.12 2003/05/16 06:01:53 knoaman
|
---|
83 | * Partial implementation of the configurable memory manager.
|
---|
84 | *
|
---|
85 | * Revision 1.11 2003/05/15 19:07:46 knoaman
|
---|
86 | * Partial implementation of the configurable memory manager.
|
---|
87 | *
|
---|
88 | * Revision 1.10 2003/05/09 15:13:46 peiyongz
|
---|
89 | * Deprecated toString() in XMLNumber family
|
---|
90 | *
|
---|
91 | * Revision 1.9 2003/03/10 20:55:58 peiyongz
|
---|
92 | * Schema Errata E2-40 double/float
|
---|
93 | *
|
---|
94 | * Revision 1.8 2003/02/02 23:54:43 peiyongz
|
---|
95 | * getFormattedString() added to return original and converted value.
|
---|
96 | *
|
---|
97 | * Revision 1.7 2003/01/30 21:55:22 tng
|
---|
98 | * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory.
|
---|
99 | *
|
---|
100 | * Revision 1.6 2002/12/11 00:20:02 peiyongz
|
---|
101 | * Doing businesss in value space. Converting out-of-bound value into special values.
|
---|
102 | *
|
---|
103 | * Revision 1.5 2002/11/04 15:22:05 tng
|
---|
104 | * C++ Namespace Support.
|
---|
105 | *
|
---|
106 | * Revision 1.4 2002/03/06 19:13:12 peiyongz
|
---|
107 | * Patch: more valid lexcial representation for positive/negative zero
|
---|
108 | *
|
---|
109 | * Revision 1.3 2002/03/01 18:47:37 peiyongz
|
---|
110 | * fix: more valid lexcial representation forms for "neural zero"
|
---|
111 | *
|
---|
112 | * Revision 1.2 2002/02/20 18:17:02 tng
|
---|
113 | * [Bug 5977] Warnings on generating apiDocs.
|
---|
114 | *
|
---|
115 | * Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz
|
---|
116 | * sane_include
|
---|
117 | *
|
---|
118 | * Revision 1.4 2001/11/28 15:39:26 peiyongz
|
---|
119 | * return Type& for operator=
|
---|
120 | *
|
---|
121 | * Revision 1.3 2001/11/22 21:39:00 peiyongz
|
---|
122 | * Allow "0.0" to be a valid lexcial representation of ZERO.
|
---|
123 | *
|
---|
124 | * Revision 1.2 2001/11/22 20:23:00 peiyongz
|
---|
125 | * _declspec(dllimport) and inline warning C4273
|
---|
126 | *
|
---|
127 | * Revision 1.1 2001/11/19 21:33:42 peiyongz
|
---|
128 | * Reorganization: Double/Float
|
---|
129 | *
|
---|
130 | *
|
---|
131 | */
|
---|
132 |
|
---|
133 | #ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP
|
---|
134 | #define XML_ABSTRACT_DOUBLE_FLOAT_HPP
|
---|
135 |
|
---|
136 | #include <xercesc/util/XMLNumber.hpp>
|
---|
137 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
138 |
|
---|
139 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
140 |
|
---|
141 | /***
|
---|
142 | * 3.2.5.1 Lexical representation
|
---|
143 | *
|
---|
144 | * double values have a lexical representation consisting of a mantissa followed,
|
---|
145 | * optionally, by the character "E" or "e", followed by an exponent.
|
---|
146 | *
|
---|
147 | * The exponent ·must· be an integer.
|
---|
148 | * The mantissa must be a decimal number.
|
---|
149 | * The representations for exponent and mantissa must follow the lexical rules
|
---|
150 | * for integer and decimal.
|
---|
151 | *
|
---|
152 | * If the "E" or "e" and the following exponent are omitted,
|
---|
153 | * an exponent value of 0 is assumed.
|
---|
154 | ***/
|
---|
155 |
|
---|
156 | /***
|
---|
157 | * 3.2.4.1 Lexical representation
|
---|
158 | *
|
---|
159 | * float values have a lexical representation consisting of a mantissa followed,
|
---|
160 | * optionally, by the character "E" or "e", followed by an exponent.
|
---|
161 | *
|
---|
162 | * The exponent ·must· be an integer.
|
---|
163 | * The mantissa must be a decimal number.
|
---|
164 | * The representations for exponent and mantissa must follow the lexical rules
|
---|
165 | * for integer and decimal.
|
---|
166 | *
|
---|
167 | * If the "E" or "e" and the following exponent are omitted,
|
---|
168 | * an exponent value of 0 is assumed.
|
---|
169 | ***/
|
---|
170 |
|
---|
171 | class XMLUTIL_EXPORT XMLAbstractDoubleFloat : public XMLNumber
|
---|
172 | {
|
---|
173 | public:
|
---|
174 |
|
---|
175 | enum LiteralType
|
---|
176 | {
|
---|
177 | NegINF,
|
---|
178 | PosINF,
|
---|
179 | NaN,
|
---|
180 | SpecialTypeNum,
|
---|
181 | Normal
|
---|
182 | };
|
---|
183 |
|
---|
184 | virtual ~XMLAbstractDoubleFloat();
|
---|
185 |
|
---|
186 | static XMLCh* getCanonicalRepresentation
|
---|
187 | (
|
---|
188 | const XMLCh* const rawData
|
---|
189 | , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
|
---|
190 | );
|
---|
191 |
|
---|
192 | /**
|
---|
193 | *
|
---|
194 | * Deprecated: please use getRawData
|
---|
195 | *
|
---|
196 | */
|
---|
197 | virtual XMLCh* toString() const;
|
---|
198 |
|
---|
199 | virtual XMLCh* getRawData() const;
|
---|
200 |
|
---|
201 | virtual const XMLCh* getFormattedString() const;
|
---|
202 |
|
---|
203 | virtual int getSign() const;
|
---|
204 |
|
---|
205 | MemoryManager* getMemoryManager() const;
|
---|
206 |
|
---|
207 | /***
|
---|
208 | *
|
---|
209 | * The decimal point delimiter for the schema double/float type is
|
---|
210 | * defined to be a period and is not locale-specific. So, it must
|
---|
211 | * be replaced with the local-specific delimiter before converting
|
---|
212 | * from string to double/float.
|
---|
213 | *
|
---|
214 | ***/
|
---|
215 | void normalizeDecimalPoint(char* const toNormal);
|
---|
216 |
|
---|
217 | /***
|
---|
218 | * Support for Serialization/De-serialization
|
---|
219 | ***/
|
---|
220 | DECL_XSERIALIZABLE(XMLAbstractDoubleFloat)
|
---|
221 |
|
---|
222 | protected:
|
---|
223 |
|
---|
224 | //
|
---|
225 | // To be used by derived class exclusively
|
---|
226 | //
|
---|
227 | XMLAbstractDoubleFloat(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
228 |
|
---|
229 | void init(const XMLCh* const strValue);
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Compares this object to the specified object.
|
---|
233 | * The result is <code>true</code> if and only if the argument is not
|
---|
234 | * <code>null</code> and is an <code>XMLAbstractDoubleFloat</code> object that contains
|
---|
235 | * the same <code>int</code> value as this object.
|
---|
236 | *
|
---|
237 | * @param lValue the object to compare with.
|
---|
238 | * @param rValue the object to compare against.
|
---|
239 | * @return <code>true</code> if the objects are the same;
|
---|
240 | * <code>false</code> otherwise.
|
---|
241 | */
|
---|
242 |
|
---|
243 | static int compareValues(const XMLAbstractDoubleFloat* const lValue
|
---|
244 | , const XMLAbstractDoubleFloat* const rValue
|
---|
245 | , MemoryManager* const manager);
|
---|
246 |
|
---|
247 | //
|
---|
248 | // to be overwritten by derived class
|
---|
249 | //
|
---|
250 | virtual void checkBoundary(const XMLCh* const strValue) = 0;
|
---|
251 |
|
---|
252 | private:
|
---|
253 | //
|
---|
254 | // Unimplemented
|
---|
255 | //
|
---|
256 | // copy ctor
|
---|
257 | // assignment ctor
|
---|
258 | //
|
---|
259 | XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy);
|
---|
260 | XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign);
|
---|
261 |
|
---|
262 | void normalizeZero(XMLCh* const);
|
---|
263 |
|
---|
264 | inline bool isSpecialValue() const;
|
---|
265 |
|
---|
266 | static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue
|
---|
267 | , MemoryManager* const manager);
|
---|
268 |
|
---|
269 | void formatString();
|
---|
270 |
|
---|
271 | protected:
|
---|
272 | double fValue;
|
---|
273 | LiteralType fType;
|
---|
274 | bool fDataConverted;
|
---|
275 |
|
---|
276 | private:
|
---|
277 | int fSign;
|
---|
278 | XMLCh* fRawData;
|
---|
279 |
|
---|
280 | //
|
---|
281 | // If the original string is not lexcially the same as the five
|
---|
282 | // special value notations, and the value is converted to
|
---|
283 | // special value due underlying platform restriction on data
|
---|
284 | // representation, then this string is constructed and
|
---|
285 | // takes the form "original_string (special_value_notation)",
|
---|
286 | // otherwise it is empty.
|
---|
287 | //
|
---|
288 | XMLCh* fFormattedString;
|
---|
289 | MemoryManager* fMemoryManager;
|
---|
290 | };
|
---|
291 |
|
---|
292 | inline bool XMLAbstractDoubleFloat::isSpecialValue() const
|
---|
293 | {
|
---|
294 | return (fType < SpecialTypeNum);
|
---|
295 | }
|
---|
296 |
|
---|
297 | inline MemoryManager* XMLAbstractDoubleFloat::getMemoryManager() const
|
---|
298 | {
|
---|
299 | return fMemoryManager;
|
---|
300 | }
|
---|
301 |
|
---|
302 | XERCES_CPP_NAMESPACE_END
|
---|
303 |
|
---|
304 | #endif
|
---|