- Main Page
- Related Pages
- Classes
- Files

# XMLBigInteger.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Licensed to the Apache Software Foundation (ASF) under one or more
    00003  * contributor license agreements.  See the NOTICE file distributed with
    00004  * this work for additional information regarding copyright ownership.
    00005  * The ASF licenses this file to You under the Apache License, Version 2.0
    00006  * (the "License"); you may not use this file except in compliance with
    00007  * the License.  You may obtain a copy of the License at
    00008  *
    00009  *      http://www.apache.org/licenses/LICENSE-2.0
    00010  *
    00011  * Unless required by applicable law or agreed to in writing, software
    00012  * distributed under the License is distributed on an "AS IS" BASIS,
    00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00014  * See the License for the specific language governing permissions and
    00015  * limitations under the License.
    00016  */
    00017
    00018 /*
    00019  * $Id: XMLBigInteger.hpp 932887 2010-04-11 13:04:59Z borisk $
    00020  */
    00021
    00022 #if !defined(XERCESC_INCLUDE_GUARD_XML_BIGINTEGER_HPP)
    00023 #define XERCESC_INCLUDE_GUARD_XML_BIGINTEGER_HPP
    00024
    00025 #include <xercesc/util/XMemory.hpp>
    00026 #include <xercesc/util/XMLString.hpp>
    00027
    00028 XERCES_CPP_NAMESPACE_BEGIN
    00029
    00030 class XMLUTIL_EXPORT XMLBigInteger : public XMemory
    00031 {
    00032 public:
    00033
    00047     XMLBigInteger
    00048     (
    00049         const XMLCh* const strValue
    00050         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00051     );
    00052     ~XMLBigInteger();
    00053
    00054     XMLBigInteger(const XMLBigInteger& toCopy);
    00055
    00056     static XMLCh* getCanonicalRepresentation
    00057                         (
    00058                           const XMLCh*         const rawData
    00059                         ,       MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
    00060                         ,       bool                 isNonPositiveInteger = false
    00061                         );
    00062
    00063     static void parseBigInteger(const XMLCh* const toConvert
    00064                               , XMLCh* const       retBuffer
    00065                               , int&   signValue
    00066                               , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00067
    00068     static int  compareValues(const XMLBigInteger* const lValue
    00069                              ,const XMLBigInteger* const rValue
    00070                              , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00071
    00072
    00073     static int  compareValues(const XMLCh*         const lString
    00074                             , const int&                 lSign
    00075                             , const XMLCh*         const rString
    00076                             , const int&                 rSign
    00077                             ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00078
    00079     void        multiply(const unsigned int byteToShift);
    00080
    00081     void        divide(const unsigned int byteToShift);
    00082
    00083     unsigned int       getTotalDigit() const;
    00084
    00090     inline XMLCh*      getRawData() const;
    00091
    00102     bool operator==(const XMLBigInteger& toCompare) const;
    00103
    00108     int getSign() const;
    00109
    00110     int intValue() const;
    00111
    00112 private:
    00113     // -----------------------------------------------------------------------
    00114     //  Unimplemented constructors and operators
    00115     // -----------------------------------------------------------------------
    00116     XMLBigInteger& operator=(const XMLBigInteger&);
    00117
    00118
    00119     void setSign(int);
    00120
    00121     /*
    00122      * The number is internally stored in "minimal" sign-fMagnitude format
    00123      * (i.e., no BigIntegers have a leading zero byte in their magnitudes).
    00124      * Zero is represented with a signum of 0 (and a zero-length fMagnitude).
    00125      * Thus, there is exactly one representation for each value.
    00126      */
    00127     // -----------------------------------------------------------------------
    00128     //  Private data members
    00129     //
    00130     //  fSign
    00131     //     to represent the sign of the number.
    00132     //
    00133     //  fMagnitude
    00134     //     the buffer holding the number.
    00135     //
    00136     //  fRawData
    00137     //     to preserve the original string used to construct this object,
    00138     //     needed for pattern matching.
    00139     //
    00140     // -----------------------------------------------------------------------
    00141
    00142     int         fSign;
    00143     XMLCh*      fMagnitude;  //null terminated
    00144     XMLCh*      fRawData;
    00145     MemoryManager* fMemoryManager;
    00146 };
    00147
    00148 inline int XMLBigInteger::getSign() const
    00149 {
    00150     return fSign;
    00151 }
    00152
    00153 inline unsigned int XMLBigInteger::getTotalDigit() const
    00154 {
    00155     return ((getSign() ==0) ? 0 : (unsigned int)XMLString::stringLen(fMagnitude));
    00156 }
    00157
    00158 inline bool XMLBigInteger::operator==(const XMLBigInteger& toCompare) const
    00159 {
    00160     return ( compareValues(this, &toCompare, fMemoryManager) ==0 ? true : false);
    00161 }
    00162
    00163 inline void XMLBigInteger::setSign(int newSign)
    00164 {
    00165     fSign = newSign;
    00166 }
    00167
    00168 inline XMLCh*  XMLBigInteger::getRawData() const
    00169 {
    00170     return fRawData;
    00171 }
    00172
    00173 XERCES_CPP_NAMESPACE_END
    00174
    00175 #endif