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: XMLBigDecimal.hpp,v 1.19 2004/09/08 13:56:24 peiyongz Exp $
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef XML_BIGDECIMAL_HPP
|
---|
22 | #define XML_BIGDECIMAL_HPP
|
---|
23 |
|
---|
24 | #include <xercesc/util/XMLNumber.hpp>
|
---|
25 | #include <xercesc/util/XMLString.hpp>
|
---|
26 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
27 |
|
---|
28 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
29 |
|
---|
30 | class XMLUTIL_EXPORT XMLBigDecimal : public XMLNumber
|
---|
31 | {
|
---|
32 | public:
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Constructs a newly allocated <code>XMLBigDecimal</code> object that
|
---|
36 | * represents the value represented by the string.
|
---|
37 | *
|
---|
38 | * @param strValue the <code>String</code> to be converted to an
|
---|
39 | * <code>XMLBigDecimal</code>.
|
---|
40 | * @param manager Pointer to the memory manager to be used to
|
---|
41 | * allocate objects.
|
---|
42 | * @exception NumberFormatException if the <code>String</code> does not
|
---|
43 | * contain a parsable XMLBigDecimal.
|
---|
44 | */
|
---|
45 |
|
---|
46 | XMLBigDecimal
|
---|
47 | (
|
---|
48 | const XMLCh* const strValue
|
---|
49 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
50 | );
|
---|
51 |
|
---|
52 | ~XMLBigDecimal();
|
---|
53 |
|
---|
54 | static int compareValues(const XMLBigDecimal* const lValue
|
---|
55 | , const XMLBigDecimal* const rValue
|
---|
56 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
57 |
|
---|
58 | static XMLCh* getCanonicalRepresentation
|
---|
59 | (
|
---|
60 | const XMLCh* const rawData
|
---|
61 | , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
|
---|
62 | );
|
---|
63 |
|
---|
64 | static void parseDecimal
|
---|
65 | (
|
---|
66 | const XMLCh* const toParse
|
---|
67 | , XMLCh* const retBuffer
|
---|
68 | , int& sign
|
---|
69 | , int& totalDigits
|
---|
70 | , int& fractDigits
|
---|
71 | , MemoryManager* const manager
|
---|
72 | );
|
---|
73 |
|
---|
74 | static void parseDecimal
|
---|
75 | (
|
---|
76 | const XMLCh* const toParse
|
---|
77 | , MemoryManager* const manager
|
---|
78 | );
|
---|
79 |
|
---|
80 | /**
|
---|
81 | *
|
---|
82 | * Deprecated: please use getRawData
|
---|
83 | *
|
---|
84 | */
|
---|
85 | virtual XMLCh* toString() const;
|
---|
86 |
|
---|
87 | virtual XMLCh* getRawData() const;
|
---|
88 |
|
---|
89 | virtual const XMLCh* getFormattedString() const;
|
---|
90 |
|
---|
91 | virtual int getSign() const;
|
---|
92 |
|
---|
93 | const XMLCh* getValue() const;
|
---|
94 |
|
---|
95 | unsigned int getScale() const;
|
---|
96 |
|
---|
97 | unsigned int getTotalDigit() const;
|
---|
98 |
|
---|
99 | inline XMLCh* getIntVal() const;
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Compares this object to the specified object.
|
---|
103 | *
|
---|
104 | * @param other the object to compare with.
|
---|
105 | * @return <code>-1</code> value is less than other's
|
---|
106 | * <code>0</code> value equals to other's
|
---|
107 | * <code>+1</code> value is greater than other's
|
---|
108 | */
|
---|
109 | int toCompare(const XMLBigDecimal& other) const;
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * Sets the value to be converted
|
---|
113 | *
|
---|
114 | * @param strValue the value to convert
|
---|
115 | */
|
---|
116 | void setDecimalValue(const XMLCh* const strValue);
|
---|
117 |
|
---|
118 | MemoryManager* getMemoryManager() const;
|
---|
119 |
|
---|
120 | /***
|
---|
121 | * Support for Serialization/De-serialization
|
---|
122 | ***/
|
---|
123 | DECL_XSERIALIZABLE(XMLBigDecimal)
|
---|
124 |
|
---|
125 | XMLBigDecimal(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
126 |
|
---|
127 | private:
|
---|
128 |
|
---|
129 | void cleanUp();
|
---|
130 |
|
---|
131 | // -----------------------------------------------------------------------
|
---|
132 | // Unimplemented contstructors and operators
|
---|
133 | // -----------------------------------------------------------------------
|
---|
134 | XMLBigDecimal(const XMLBigDecimal& other);
|
---|
135 | XMLBigDecimal& operator=(const XMLBigDecimal& other);
|
---|
136 |
|
---|
137 | // -----------------------------------------------------------------------
|
---|
138 | // Private data members
|
---|
139 | //
|
---|
140 | // fSign
|
---|
141 | // sign
|
---|
142 | //
|
---|
143 | // fTotalDigits
|
---|
144 | // the total number of didits
|
---|
145 | //
|
---|
146 | // fScale
|
---|
147 | // the number of digits to the right of the decimal point
|
---|
148 | //
|
---|
149 | // fIntVal
|
---|
150 | // The value of this BigDecimal, w/o
|
---|
151 | // leading whitespace, leading zero
|
---|
152 | // decimal point
|
---|
153 | // trailing zero, trailing whitespace
|
---|
154 | //
|
---|
155 | // fRawData
|
---|
156 | // to preserve the original string used to construct this object,
|
---|
157 | // needed for pattern matching.
|
---|
158 | //
|
---|
159 | // -----------------------------------------------------------------------
|
---|
160 | int fSign;
|
---|
161 | unsigned int fTotalDigits;
|
---|
162 | unsigned int fScale;
|
---|
163 | unsigned int fRawDataLen;
|
---|
164 | XMLCh* fRawData;
|
---|
165 | XMLCh* fIntVal;
|
---|
166 | MemoryManager* fMemoryManager;
|
---|
167 |
|
---|
168 | };
|
---|
169 |
|
---|
170 | inline int XMLBigDecimal::getSign() const
|
---|
171 | {
|
---|
172 | return fSign;
|
---|
173 | }
|
---|
174 |
|
---|
175 | inline const XMLCh* XMLBigDecimal::getValue() const
|
---|
176 | {
|
---|
177 | return fIntVal;
|
---|
178 | }
|
---|
179 |
|
---|
180 | inline unsigned int XMLBigDecimal::getScale() const
|
---|
181 | {
|
---|
182 | return fScale;
|
---|
183 | }
|
---|
184 |
|
---|
185 | inline unsigned int XMLBigDecimal::getTotalDigit() const
|
---|
186 | {
|
---|
187 | return fTotalDigits;
|
---|
188 | }
|
---|
189 |
|
---|
190 | inline XMLCh* XMLBigDecimal::getRawData() const
|
---|
191 | {
|
---|
192 | return fRawData;
|
---|
193 | }
|
---|
194 |
|
---|
195 | inline const XMLCh* XMLBigDecimal::getFormattedString() const
|
---|
196 | {
|
---|
197 | return fRawData;
|
---|
198 | }
|
---|
199 |
|
---|
200 | inline MemoryManager* XMLBigDecimal::getMemoryManager() const
|
---|
201 | {
|
---|
202 | return fMemoryManager;
|
---|
203 | }
|
---|
204 |
|
---|
205 | inline XMLCh* XMLBigDecimal::getIntVal() const
|
---|
206 | {
|
---|
207 | return fIntVal;
|
---|
208 | }
|
---|
209 |
|
---|
210 | //
|
---|
211 | // The caller needs to de-allocate the memory allocated by this function
|
---|
212 | //
|
---|
213 | inline XMLCh* XMLBigDecimal::toString() const
|
---|
214 | {
|
---|
215 | // Return data using global operator new
|
---|
216 | return XMLString::replicate(fRawData);
|
---|
217 | }
|
---|
218 |
|
---|
219 | XERCES_CPP_NAMESPACE_END
|
---|
220 |
|
---|
221 | #endif
|
---|