|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: XMLBigDecimal.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 #ifndef XML_BIGDECIMAL_HPP |
|
39 #define XML_BIGDECIMAL_HPP |
|
40 |
|
41 #include <xercesc/util/XMLNumber.hpp> |
|
42 #include <xercesc/util/XMLString.hpp> |
|
43 #include <xercesc/util/PlatformUtils.hpp> |
|
44 |
|
45 XERCES_CPP_NAMESPACE_BEGIN |
|
46 |
|
47 class XMLUTIL_EXPORT XMLBigDecimal : public XMLNumber |
|
48 { |
|
49 public: |
|
50 |
|
51 /** |
|
52 * Constructs a newly allocated <code>XMLBigDecimal</code> object that |
|
53 * represents the value represented by the string. |
|
54 * |
|
55 * @param strValue the <code>String</code> to be converted to an |
|
56 * <code>XMLBigDecimal</code>. |
|
57 * @param manager Pointer to the memory manager to be used to |
|
58 * allocate objects. |
|
59 * @exception NumberFormatException if the <code>String</code> does not |
|
60 * contain a parsable XMLBigDecimal. |
|
61 */ |
|
62 |
|
63 XMLBigDecimal |
|
64 ( |
|
65 const XMLCh* const strValue |
|
66 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
67 ); |
|
68 |
|
69 ~XMLBigDecimal(); |
|
70 |
|
71 static int compareValues(const XMLBigDecimal* const lValue |
|
72 , const XMLBigDecimal* const rValue |
|
73 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
74 |
|
75 static XMLCh* getCanonicalRepresentation |
|
76 ( |
|
77 const XMLCh* const rawData |
|
78 , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager |
|
79 ); |
|
80 |
|
81 static void parseDecimal |
|
82 ( |
|
83 const XMLCh* const toParse |
|
84 , XMLCh* const retBuffer |
|
85 , int& sign |
|
86 , int& totalDigits |
|
87 , int& fractDigits |
|
88 , MemoryManager* const manager |
|
89 ); |
|
90 |
|
91 static void parseDecimal |
|
92 ( |
|
93 const XMLCh* const toParse |
|
94 , MemoryManager* const manager |
|
95 ); |
|
96 |
|
97 /** |
|
98 * |
|
99 * Deprecated: please use getRawData |
|
100 * |
|
101 */ |
|
102 virtual XMLCh* toString() const; |
|
103 |
|
104 virtual XMLCh* getRawData() const; |
|
105 |
|
106 virtual const XMLCh* getFormattedString() const; |
|
107 |
|
108 virtual int getSign() const; |
|
109 |
|
110 const XMLCh* getValue() const; |
|
111 |
|
112 unsigned int getScale() const; |
|
113 |
|
114 unsigned int getTotalDigit() const; |
|
115 |
|
116 inline XMLCh* getIntVal() const; |
|
117 |
|
118 /** |
|
119 * Compares this object to the specified object. |
|
120 * |
|
121 * @param other the object to compare with. |
|
122 * @return <code>-1</code> value is less than other's |
|
123 * <code>0</code> value equals to other's |
|
124 * <code>+1</code> value is greater than other's |
|
125 */ |
|
126 int toCompare(const XMLBigDecimal& other) const; |
|
127 |
|
128 /* |
|
129 * Sets the value to be converted |
|
130 * |
|
131 * @param strValue the value to convert |
|
132 */ |
|
133 void setDecimalValue(const XMLCh* const strValue); |
|
134 |
|
135 MemoryManager* getMemoryManager() const; |
|
136 |
|
137 /*** |
|
138 * Support for Serialization/De-serialization |
|
139 ***/ |
|
140 DECL_XSERIALIZABLE(XMLBigDecimal) |
|
141 |
|
142 XMLBigDecimal(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
143 |
|
144 private: |
|
145 |
|
146 void cleanUp(); |
|
147 |
|
148 // ----------------------------------------------------------------------- |
|
149 // Unimplemented contstructors and operators |
|
150 // ----------------------------------------------------------------------- |
|
151 XMLBigDecimal(const XMLBigDecimal& other); |
|
152 XMLBigDecimal& operator=(const XMLBigDecimal& other); |
|
153 |
|
154 // ----------------------------------------------------------------------- |
|
155 // Private data members |
|
156 // |
|
157 // fSign |
|
158 // sign |
|
159 // |
|
160 // fTotalDigits |
|
161 // the total number of didits |
|
162 // |
|
163 // fScale |
|
164 // the number of digits to the right of the decimal point |
|
165 // |
|
166 // fIntVal |
|
167 // The value of this BigDecimal, w/o |
|
168 // leading whitespace, leading zero |
|
169 // decimal point |
|
170 // trailing zero, trailing whitespace |
|
171 // |
|
172 // fRawData |
|
173 // to preserve the original string used to construct this object, |
|
174 // needed for pattern matching. |
|
175 // |
|
176 // ----------------------------------------------------------------------- |
|
177 int fSign; |
|
178 unsigned int fTotalDigits; |
|
179 unsigned int fScale; |
|
180 unsigned int fRawDataLen; |
|
181 XMLCh* fRawData; |
|
182 XMLCh* fIntVal; |
|
183 MemoryManager* fMemoryManager; |
|
184 |
|
185 }; |
|
186 |
|
187 inline int XMLBigDecimal::getSign() const |
|
188 { |
|
189 return fSign; |
|
190 } |
|
191 |
|
192 inline const XMLCh* XMLBigDecimal::getValue() const |
|
193 { |
|
194 return fIntVal; |
|
195 } |
|
196 |
|
197 inline unsigned int XMLBigDecimal::getScale() const |
|
198 { |
|
199 return fScale; |
|
200 } |
|
201 |
|
202 inline unsigned int XMLBigDecimal::getTotalDigit() const |
|
203 { |
|
204 return fTotalDigits; |
|
205 } |
|
206 |
|
207 inline XMLCh* XMLBigDecimal::getRawData() const |
|
208 { |
|
209 return fRawData; |
|
210 } |
|
211 |
|
212 inline const XMLCh* XMLBigDecimal::getFormattedString() const |
|
213 { |
|
214 return fRawData; |
|
215 } |
|
216 |
|
217 inline MemoryManager* XMLBigDecimal::getMemoryManager() const |
|
218 { |
|
219 return fMemoryManager; |
|
220 } |
|
221 |
|
222 inline XMLCh* XMLBigDecimal::getIntVal() const |
|
223 { |
|
224 return fIntVal; |
|
225 } |
|
226 |
|
227 // |
|
228 // The caller needs to de-allocate the memory allocated by this function |
|
229 // |
|
230 inline XMLCh* XMLBigDecimal::toString() const |
|
231 { |
|
232 // Return data using global operator new |
|
233 return XMLString::replicate(fRawData); |
|
234 } |
|
235 |
|
236 XERCES_CPP_NAMESPACE_END |
|
237 |
|
238 #endif |