Xerces-C++ 3.2.5

XMLBigInteger.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_BIGINTEGER_HPP)
23#define XERCESC_INCLUDE_GUARD_XML_BIGINTEGER_HPP
24
25#include <xercesc/util/XMemory.hpp>
26#include <xercesc/util/XMLString.hpp>
27
28 XERCES_CPP_NAMESPACE_BEGIN
29
30 class XMLUTIL_EXPORT XMLBigInteger : public XMemory
31{
32 public:
33
47 XMLBigInteger
48 (
49 const XMLCh* const strValue
50 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
51 );
52 ~XMLBigInteger();
53
54 XMLBigInteger(const XMLBigInteger& toCopy);
55
56 static XMLCh* getCanonicalRepresentation
57 (
58 const XMLCh* const rawData
59 , MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
60 , bool isNonPositiveInteger = false
61 );
62
63 static void parseBigInteger(const XMLCh* const toConvert
64 , XMLCh* const retBuffer
65 , int& signValue
66 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
67
68 static int compareValues(const XMLBigInteger* const lValue
69 ,const XMLBigInteger* const rValue
70 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
71
72
73 static int compareValues(const XMLCh* const lString
74 , const int& lSign
75 , const XMLCh* const rString
76 , const int& rSign
77 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
78
79 void multiply(const unsigned int byteToShift);
80
81 void divide(const unsigned int byteToShift);
82
83 unsigned int getTotalDigit() const;
84
90 inline XMLCh* getRawData() const;
91
102 bool operator==(const XMLBigInteger& toCompare) const;
103
108 int getSign() const;
109
110 int intValue() const;
111
112 private:
113 // -----------------------------------------------------------------------
114 // Unimplemented constructors and operators
115 // -----------------------------------------------------------------------
116 XMLBigInteger& operator=(const XMLBigInteger&);
117
118
119 void setSign(int);
120
121 /*
122 * The number is internally stored in "minimal" sign-fMagnitude format
123 * (i.e., no BigIntegers have a leading zero byte in their magnitudes).
124 * Zero is represented with a signum of 0 (and a zero-length fMagnitude).
125 * Thus, there is exactly one representation for each value.
126 */
127 // -----------------------------------------------------------------------
128 // Private data members
129 //
130 // fSign
131 // to represent the sign of the number.
132 //
133 // fMagnitude
134 // the buffer holding the number.
135 //
136 // fRawData
137 // to preserve the original string used to construct this object,
138 // needed for pattern matching.
139 //
140 // -----------------------------------------------------------------------
141
142 int fSign;
143 XMLCh* fMagnitude; //null terminated
144 XMLCh* fRawData;
145 MemoryManager* fMemoryManager;
146};
147
148 inline int XMLBigInteger::getSign() const
149{
150 return fSign;
151}
152
153 inline unsigned int XMLBigInteger::getTotalDigit() const
154{
155 return ((getSign() ==0) ? 0 : (unsigned int)XMLString::stringLen(fMagnitude));
156}
157
158 inline bool XMLBigInteger::operator==(const XMLBigInteger& toCompare) const
159{
160 return ( compareValues(this, &toCompare, fMemoryManager) ==0 ? true : false);
161}
162
163 inline void XMLBigInteger::setSign(int newSign)
164{
165 fSign = newSign;
166}
167
168 inline XMLCh* XMLBigInteger::getRawData() const
169{
170 return fRawData;
171}
172
173 XERCES_CPP_NAMESPACE_END
174
175#endif
XMLString.hpp
XMemory.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
XMLBigInteger
Definition XMLBigInteger.hpp:31
XMLBigInteger::XMLBigInteger
XMLBigInteger(const XMLBigInteger &toCopy)
XMLBigInteger::multiply
void multiply(const unsigned int byteToShift)
XMLBigInteger::getTotalDigit
unsigned int getTotalDigit() const
Definition XMLBigInteger.hpp:153
XMLBigInteger::divide
void divide(const unsigned int byteToShift)
XMLBigInteger::XMLBigInteger
XMLBigInteger(const XMLCh *const strValue, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Constructs a newly allocated XMLBigInteger object that represents the value represented by the string...
XMLBigInteger::intValue
int intValue() const
XMLBigInteger::compareValues
static int compareValues(const XMLCh *const lString, const int &lSign, const XMLCh *const rString, const int &rSign, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLBigInteger::operator==
bool operator==(const XMLBigInteger &toCompare) const
Compares this object to the specified object.
Definition XMLBigInteger.hpp:158
XMLBigInteger::getSign
int getSign() const
Returns the signum function of this number (i.e., -1, 0 or 1 as the value of this number is negative,...
Definition XMLBigInteger.hpp:148
XMLBigInteger::~XMLBigInteger
~XMLBigInteger()
XMLBigInteger::getCanonicalRepresentation
static XMLCh * getCanonicalRepresentation(const XMLCh *const rawData, MemoryManager *const memMgr=XMLPlatformUtils::fgMemoryManager, bool isNonPositiveInteger=false)
XMLBigInteger::compareValues
static int compareValues(const XMLBigInteger *const lValue, const XMLBigInteger *const rValue, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLBigInteger::parseBigInteger
static void parseBigInteger(const XMLCh *const toConvert, XMLCh *const retBuffer, int &signValue, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLBigInteger::getRawData
XMLCh * getRawData() const
Return a copy of the fMagnitude.
Definition XMLBigInteger.hpp:168
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition PlatformUtils.hpp:121
XMLString::stringLen
static XMLSize_t stringLen(const char *const src)
Get the length of the string.
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition XMemory.hpp:41