| API Docs for SAX and DOM |

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

# XMLBigInteger.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright 2001,2004 The Apache Software Foundation.
    00003  *
    00004  * Licensed under the Apache License, Version 2.0 (the "License");
    00005  * you may not use this file except in compliance with the License.
    00006  * You may obtain a copy of the License at
    00007  *
    00008  *      http://www.apache.org/licenses/LICENSE-2.0
    00009  *
    00010  * Unless required by applicable law or agreed to in writing, software
    00011  * distributed under the License is distributed on an "AS IS" BASIS,
    00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013  * See the License for the specific language governing permissions and
    00014  * limitations under the License.
    00015  */
    00016
    00017 /*
    00018  * $Id: XMLBigInteger.hpp 176026 2004-09-08 13:57:07Z peiyongz $
    00019  */
    00020
    00021 #ifndef XML_BIGINTEGER_HPP
    00022 #define XML_BIGINTEGER_HPP
    00023
    00024 #include <xercesc/util/XMemory.hpp>
    00025 #include <xercesc/util/XMLString.hpp>
    00026
    00027 XERCES_CPP_NAMESPACE_BEGIN
    00028
    00029 class  XMLBigInteger : public XMemory
    00030 {
    00031 public:
    00032
    00046     XMLBigInteger
    00047     (
    00048         const XMLCh* const strValue
    00049         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00050     );
    00051     ~XMLBigInteger();
    00052
    00053     XMLBigInteger(const XMLBigInteger& toCopy);
    00054
    00055     static XMLCh* getCanonicalRepresentation
    00056                         (
    00057                           const XMLCh*         const rawData
    00058                         ,       MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
    00059                         ,       bool                 isNonPositiveInteger = false
    00060                         );
    00061
    00062     static void parseBigInteger(const XMLCh* const toConvert
    00063                               , XMLCh* const       retBuffer
    00064                               , int&   signValue
    00065                               , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00066
    00067     static int  compareValues(const XMLBigInteger* const lValue
    00068                              ,const XMLBigInteger* const rValue
    00069                              , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00070
    00071
    00072     static int  compareValues(const XMLCh*         const lString
    00073                             , const int&                 lSign
    00074                             , const XMLCh*         const rString
    00075                             , const int&                 rSign
    00076                             ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00077
    00078     void        multiply(const unsigned int byteToShift);
    00079
    00080     void        divide(const unsigned int byteToShift);
    00081
    00082     int         getTotalDigit() const;
    00083
    00092     inline XMLCh*      toString() const;
    00093
    00099     inline XMLCh*      getRawData() const;
    00100
    00111     bool operator==(const XMLBigInteger& toCompare) const;
    00112
    00117     int getSign() const;
    00118
    00119     int intValue() const;
    00120
    00121 private:
    00122     // -----------------------------------------------------------------------
    00123     //  Unimplemented constructors and operators
    00124     // -----------------------------------------------------------------------
    00125     XMLBigInteger& operator=(const XMLBigInteger&);
    00126
    00127
    00128     void setSign(int);
    00129
    00130     /*
    00131      * The number is internally stored in "minimal" sign-fMagnitude format
    00132      * (i.e., no BigIntegers have a leading zero byte in their magnitudes).
    00133      * Zero is represented with a signum of 0 (and a zero-length fMagnitude).
    00134      * Thus, there is exactly one representation for each value.
    00135      */
    00136     // -----------------------------------------------------------------------
    00137     //  Private data members
    00138     //
    00139     //  fSign
    00140     //     to represent the sign of the number.
    00141     //
    00142     //  fMagnitude
    00143     //     the buffer holding the number.
    00144     //
    00145     //  fRawData
    00146     //     to preserve the original string used to construct this object,
    00147     //     needed for pattern matching.
    00148     //
    00149     // -----------------------------------------------------------------------
    00150
    00151     int         fSign;
    00152     XMLCh*      fMagnitude;  //null terminated
    00153     XMLCh*      fRawData;
    00154     MemoryManager* fMemoryManager;
    00155 };
    00156
    00157 inline int XMLBigInteger::getSign() const
    00158 {
    00159     return fSign;
    00160 }
    00161
    00162 inline int XMLBigInteger::getTotalDigit() const
    00163 {
    00164     return ((getSign() ==0) ? 0 : XMLString::stringLen(fMagnitude));
    00165 }
    00166
    00167 inline bool XMLBigInteger::operator==(const XMLBigInteger& toCompare) const
    00168 {
    00169     return ( compareValues(this, &toCompare, fMemoryManager) ==0 ? true : false);
    00170 }
    00171
    00172 inline void XMLBigInteger::setSign(int newSign)
    00173 {
    00174     fSign = newSign;
    00175 }
    00176
    00177 inline XMLCh*  XMLBigInteger::getRawData() const
    00178 {
    00179     return fRawData;
    00180 }
    00181
    00182 //
    00183 // The caller needs to de-allocate the memory allocated by this function
    00184 //
    00185 inline XMLCh*  XMLBigInteger::toString() const
    00186 {
    00187     // Return data using global operator new
    00188     return XMLString::replicate(fRawData, fMemoryManager);
    00189 }
    00190
    00191 XERCES_CPP_NAMESPACE_END
    00192
    00193 #endif

Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.