1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: XMLAbstractDoubleFloat.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP |
---|
23 | #define XML_ABSTRACT_DOUBLE_FLOAT_HPP |
---|
24 | |
---|
25 | #include <xercesc/util/XMLNumber.hpp> |
---|
26 | #include <xercesc/util/PlatformUtils.hpp> |
---|
27 | |
---|
28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
29 | |
---|
30 | /*** |
---|
31 | * 3.2.5.1 Lexical representation |
---|
32 | * |
---|
33 | * double values have a lexical representation consisting of a mantissa followed, |
---|
34 | * optionally, by the character "E" or "e", followed by an exponent. |
---|
35 | * |
---|
36 | * The exponent �must� be an integer. |
---|
37 | * The mantissa must be a decimal number. |
---|
38 | * The representations for exponent and mantissa must follow the lexical rules |
---|
39 | * for integer and decimal. |
---|
40 | * |
---|
41 | * If the "E" or "e" and the following exponent are omitted, |
---|
42 | * an exponent value of 0 is assumed. |
---|
43 | ***/ |
---|
44 | |
---|
45 | /*** |
---|
46 | * 3.2.4.1 Lexical representation |
---|
47 | * |
---|
48 | * float values have a lexical representation consisting of a mantissa followed, |
---|
49 | * optionally, by the character "E" or "e", followed by an exponent. |
---|
50 | * |
---|
51 | * The exponent �must� be an integer. |
---|
52 | * The mantissa must be a decimal number. |
---|
53 | * The representations for exponent and mantissa must follow the lexical rules |
---|
54 | * for integer and decimal. |
---|
55 | * |
---|
56 | * If the "E" or "e" and the following exponent are omitted, |
---|
57 | * an exponent value of 0 is assumed. |
---|
58 | ***/ |
---|
59 | |
---|
60 | class XMLUTIL_EXPORT XMLAbstractDoubleFloat : public XMLNumber |
---|
61 | { |
---|
62 | public: |
---|
63 | |
---|
64 | enum LiteralType |
---|
65 | { |
---|
66 | NegINF, |
---|
67 | PosINF, |
---|
68 | NaN, |
---|
69 | SpecialTypeNum, |
---|
70 | Normal |
---|
71 | }; |
---|
72 | |
---|
73 | virtual ~XMLAbstractDoubleFloat(); |
---|
74 | |
---|
75 | static XMLCh* getCanonicalRepresentation |
---|
76 | ( |
---|
77 | const XMLCh* const rawData |
---|
78 | , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager |
---|
79 | ); |
---|
80 | |
---|
81 | /** |
---|
82 | * |
---|
83 | * Deprecated: please use getRawData |
---|
84 | * |
---|
85 | */ |
---|
86 | virtual XMLCh* toString() const; |
---|
87 | |
---|
88 | virtual XMLCh* getRawData() const; |
---|
89 | |
---|
90 | virtual const XMLCh* getFormattedString() const; |
---|
91 | |
---|
92 | virtual int getSign() const; |
---|
93 | |
---|
94 | MemoryManager* getMemoryManager() const; |
---|
95 | |
---|
96 | inline bool isDataConverted() const; |
---|
97 | |
---|
98 | inline bool isDataOverflowed() const; |
---|
99 | |
---|
100 | inline double getValue() const; |
---|
101 | |
---|
102 | inline LiteralType getType() const; |
---|
103 | |
---|
104 | /*** |
---|
105 | * |
---|
106 | * The decimal point delimiter for the schema double/float type is |
---|
107 | * defined to be a period and is not locale-specific. So, it must |
---|
108 | * be replaced with the local-specific delimiter before converting |
---|
109 | * from string to double/float. |
---|
110 | * |
---|
111 | ***/ |
---|
112 | static void normalizeDecimalPoint(char* const toNormal); |
---|
113 | |
---|
114 | /*** |
---|
115 | * Support for Serialization/De-serialization |
---|
116 | ***/ |
---|
117 | DECL_XSERIALIZABLE(XMLAbstractDoubleFloat) |
---|
118 | |
---|
119 | protected: |
---|
120 | |
---|
121 | // |
---|
122 | // To be used by derived class exclusively |
---|
123 | // |
---|
124 | XMLAbstractDoubleFloat(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
125 | |
---|
126 | void init(const XMLCh* const strValue); |
---|
127 | |
---|
128 | /** |
---|
129 | * Compares this object to the specified object. |
---|
130 | * The result is <code>true</code> if and only if the argument is not |
---|
131 | * <code>null</code> and is an <code>XMLAbstractDoubleFloat</code> object that contains |
---|
132 | * the same <code>int</code> value as this object. |
---|
133 | * |
---|
134 | * @param lValue the object to compare with. |
---|
135 | * @param rValue the object to compare against. |
---|
136 | * @param manager The MemoryManager to use to allocate objects |
---|
137 | * @return <code>true</code> if the objects are the same; |
---|
138 | * <code>false</code> otherwise. |
---|
139 | */ |
---|
140 | |
---|
141 | static int compareValues(const XMLAbstractDoubleFloat* const lValue |
---|
142 | , const XMLAbstractDoubleFloat* const rValue |
---|
143 | , MemoryManager* const manager); |
---|
144 | |
---|
145 | // |
---|
146 | // to be overridden by derived class |
---|
147 | // |
---|
148 | virtual void checkBoundary(char* const strValue) = 0; |
---|
149 | |
---|
150 | void |
---|
151 | convert(char* const strValue); |
---|
152 | |
---|
153 | private: |
---|
154 | // |
---|
155 | // Unimplemented |
---|
156 | // |
---|
157 | // copy ctor |
---|
158 | // assignment ctor |
---|
159 | // |
---|
160 | XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy); |
---|
161 | XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign); |
---|
162 | |
---|
163 | void normalizeZero(XMLCh* const); |
---|
164 | |
---|
165 | inline bool isSpecialValue() const; |
---|
166 | |
---|
167 | static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue |
---|
168 | , MemoryManager* const manager); |
---|
169 | |
---|
170 | void formatString(); |
---|
171 | |
---|
172 | protected: |
---|
173 | double fValue; |
---|
174 | LiteralType fType; |
---|
175 | bool fDataConverted; |
---|
176 | bool fDataOverflowed; |
---|
177 | |
---|
178 | private: |
---|
179 | int fSign; |
---|
180 | XMLCh* fRawData; |
---|
181 | |
---|
182 | // |
---|
183 | // If the original string is not lexcially the same as the five |
---|
184 | // special value notations, and the value is converted to |
---|
185 | // special value due underlying platform restriction on data |
---|
186 | // representation, then this string is constructed and |
---|
187 | // takes the form "original_string (special_value_notation)", |
---|
188 | // otherwise it is empty. |
---|
189 | // |
---|
190 | XMLCh* fFormattedString; |
---|
191 | MemoryManager* fMemoryManager; |
---|
192 | |
---|
193 | }; |
---|
194 | |
---|
195 | inline bool XMLAbstractDoubleFloat::isSpecialValue() const |
---|
196 | { |
---|
197 | return (fType < SpecialTypeNum); |
---|
198 | } |
---|
199 | |
---|
200 | inline MemoryManager* XMLAbstractDoubleFloat::getMemoryManager() const |
---|
201 | { |
---|
202 | return fMemoryManager; |
---|
203 | } |
---|
204 | |
---|
205 | inline bool XMLAbstractDoubleFloat::isDataConverted() const |
---|
206 | { |
---|
207 | return fDataConverted; |
---|
208 | } |
---|
209 | |
---|
210 | inline bool XMLAbstractDoubleFloat::isDataOverflowed() const |
---|
211 | { |
---|
212 | return fDataOverflowed; |
---|
213 | } |
---|
214 | |
---|
215 | inline double XMLAbstractDoubleFloat::getValue() const |
---|
216 | { |
---|
217 | return fValue; |
---|
218 | } |
---|
219 | |
---|
220 | inline XMLAbstractDoubleFloat::LiteralType XMLAbstractDoubleFloat::getType() const |
---|
221 | { |
---|
222 | return fType; |
---|
223 | } |
---|
224 | |
---|
225 | XERCES_CPP_NAMESPACE_END |
---|
226 | |
---|
227 | #endif |
---|