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