Xerces-C++ 3.2.4

XMLAbstractDoubleFloat.hpp
Go to the documentation of this file.
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$
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XML_ABSTRACT_DOUBLE_FLOAT_HPP)
23#define XERCESC_INCLUDE_GUARD_XML_ABSTRACT_DOUBLE_FLOAT_HPP
24
25
26#include <xercesc/util/XMLNumber.hpp>
27#include <xercesc/util/PlatformUtils.hpp>
28
29 XERCES_CPP_NAMESPACE_BEGIN
30
31/***
32 * 3.2.5.1 Lexical representation
33 *
34 * double values have a lexical representation consisting of a mantissa followed,
35 * optionally, by the character "E" or "e", followed by an exponent.
36 *
37 * The exponent must be an integer.
38 * The mantissa must be a decimal number.
39 * The representations for exponent and mantissa must follow the lexical rules
40 * for integer and decimal.
41 *
42 * If the "E" or "e" and the following exponent are omitted,
43 * an exponent value of 0 is assumed.
44***/
45
46/***
47 * 3.2.4.1 Lexical representation
48 *
49 * float values have a lexical representation consisting of a mantissa followed,
50 * optionally, by the character "E" or "e", followed by an exponent.
51 *
52 * The exponent must be an integer.
53 * The mantissa must be a decimal number.
54 * The representations for exponent and mantissa must follow the lexical rules
55 * for integer and decimal.
56 *
57 * If the "E" or "e" and the following exponent are omitted,
58 * an exponent value of 0 is assumed.
59***/
60
61 class XMLUTIL_EXPORT XMLAbstractDoubleFloat : public XMLNumber
62{
63 public:
64
65 enum LiteralType
66 {
67 NegINF,
68 PosINF,
69 NaN,
70 SpecialTypeNum,
71 Normal
72 };
73
74 virtual ~XMLAbstractDoubleFloat();
75
76 static XMLCh* getCanonicalRepresentation
77 (
78 const XMLCh* const rawData
79 , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
80 );
81
82 virtual XMLCh* getRawData() const;
83
84 virtual const XMLCh* getFormattedString() const;
85
86 virtual int getSign() const;
87
88 MemoryManager* getMemoryManager() const;
89
90 inline bool isDataConverted() const;
91
92 inline bool isDataOverflowed() const;
93
94 inline double getValue() const;
95
96 inline LiteralType getType() const;
97
98 /***
99 *
100 * The decimal point delimiter for the schema double/float type is
101 * defined to be a period and is not locale-specific. So, it must
102 * be replaced with the local-specific delimiter before converting
103 * from string to double/float.
104 *
105 ***/
106 static void normalizeDecimalPoint(char* const toNormal);
107
108 /***
109 * Support for Serialization/De-serialization
110 ***/
111 DECL_XSERIALIZABLE(XMLAbstractDoubleFloat)
112
113 protected:
114
115 //
116 // To be used by derived class exclusively
117 //
118 XMLAbstractDoubleFloat(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
119
120 void init(const XMLCh* const strValue);
121
135 static int compareValues(const XMLAbstractDoubleFloat* const lValue
136 , const XMLAbstractDoubleFloat* const rValue
137 , MemoryManager* const manager);
138
139 //
140 // to be overridden by derived class
141 //
142 virtual void checkBoundary(char* const strValue) = 0;
143
144 void
145 convert(char* const strValue);
146
147 private:
148 //
149 // Unimplemented
150 //
151 // copy ctor
152 // assignment ctor
153 //
154 XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy);
155 XMLAbstractDoubleFloat& operator=(const XMLAbstractDoubleFloat& toAssign);
156
157 void normalizeZero(XMLCh* const);
158
159 inline bool isSpecialValue() const;
160
161 static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue
162 , MemoryManager* const manager);
163
164 void formatString();
165
166 protected:
167 double fValue;
168 LiteralType fType;
169 bool fDataConverted;
170 bool fDataOverflowed;
171
172 private:
173 int fSign;
174 XMLCh* fRawData;
175
176 //
177 // If the original string is not lexcially the same as the five
178 // special value notations, and the value is converted to
179 // special value due underlying platform restriction on data
180 // representation, then this string is constructed and
181 // takes the form "original_string (special_value_notation)",
182 // otherwise it is empty.
183 //
184 XMLCh* fFormattedString;
185 MemoryManager* fMemoryManager;
186
187};
188
189 inline bool XMLAbstractDoubleFloat::isSpecialValue() const
190{
191 return (fType < SpecialTypeNum);
192}
193
194 inline MemoryManager* XMLAbstractDoubleFloat::getMemoryManager() const
195{
196 return fMemoryManager;
197}
198
199 inline bool XMLAbstractDoubleFloat::isDataConverted() const
200{
201 return fDataConverted;
202}
203
204 inline bool XMLAbstractDoubleFloat::isDataOverflowed() const
205{
206 return fDataOverflowed;
207}
208
209 inline double XMLAbstractDoubleFloat::getValue() const
210{
211 return fValue;
212}
213
214 inline XMLAbstractDoubleFloat::LiteralType XMLAbstractDoubleFloat::getType() const
215{
216 return fType;
217}
218
219 XERCES_CPP_NAMESPACE_END
220
221#endif
PlatformUtils.hpp
XMLNumber.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:40
XMLAbstractDoubleFloat
Definition: XMLAbstractDoubleFloat.hpp:62
XMLAbstractDoubleFloat::getValue
double getValue() const
Definition: XMLAbstractDoubleFloat.hpp:209
XMLAbstractDoubleFloat::convert
void convert(char *const strValue)
XMLAbstractDoubleFloat::checkBoundary
virtual void checkBoundary(char *const strValue)=0
XMLAbstractDoubleFloat::XMLAbstractDoubleFloat
XMLAbstractDoubleFloat(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLAbstractDoubleFloat::LiteralType
LiteralType
Definition: XMLAbstractDoubleFloat.hpp:66
XMLAbstractDoubleFloat::SpecialTypeNum
@ SpecialTypeNum
Definition: XMLAbstractDoubleFloat.hpp:70
XMLAbstractDoubleFloat::NegINF
@ NegINF
Definition: XMLAbstractDoubleFloat.hpp:67
XMLAbstractDoubleFloat::NaN
@ NaN
Definition: XMLAbstractDoubleFloat.hpp:69
XMLAbstractDoubleFloat::PosINF
@ PosINF
Definition: XMLAbstractDoubleFloat.hpp:68
XMLAbstractDoubleFloat::getCanonicalRepresentation
static XMLCh * getCanonicalRepresentation(const XMLCh *const rawData, MemoryManager *const memMgr=XMLPlatformUtils::fgMemoryManager)
XMLAbstractDoubleFloat::fDataOverflowed
bool fDataOverflowed
Definition: XMLAbstractDoubleFloat.hpp:170
XMLAbstractDoubleFloat::fType
LiteralType fType
Definition: XMLAbstractDoubleFloat.hpp:168
XMLAbstractDoubleFloat::fValue
double fValue
Definition: XMLAbstractDoubleFloat.hpp:167
XMLAbstractDoubleFloat::getRawData
virtual XMLCh * getRawData() const
Return string representation of the decimal value.
XMLAbstractDoubleFloat::isDataOverflowed
bool isDataOverflowed() const
Definition: XMLAbstractDoubleFloat.hpp:204
XMLAbstractDoubleFloat::getFormattedString
virtual const XMLCh * getFormattedString() const
Return the original and converted value of the original data.
XMLAbstractDoubleFloat::fDataConverted
bool fDataConverted
Definition: XMLAbstractDoubleFloat.hpp:169
XMLAbstractDoubleFloat::getType
LiteralType getType() const
Definition: XMLAbstractDoubleFloat.hpp:214
XMLAbstractDoubleFloat::normalizeDecimalPoint
static void normalizeDecimalPoint(char *const toNormal)
XMLAbstractDoubleFloat::getMemoryManager
MemoryManager * getMemoryManager() const
Definition: XMLAbstractDoubleFloat.hpp:194
XMLAbstractDoubleFloat::isDataConverted
bool isDataConverted() const
Definition: XMLAbstractDoubleFloat.hpp:199
XMLAbstractDoubleFloat::getSign
virtual int getSign() const
Returns the sign of this number.
XMLAbstractDoubleFloat::compareValues
static int compareValues(const XMLAbstractDoubleFloat *const lValue, const XMLAbstractDoubleFloat *const rValue, MemoryManager *const manager)
Compares this object to the specified object.
XMLAbstractDoubleFloat::init
void init(const XMLCh *const strValue)
XMLAbstractDoubleFloat::~XMLAbstractDoubleFloat
virtual ~XMLAbstractDoubleFloat()
XMLNumber
Definition: XMLNumber.hpp:31
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121