| API Docs for SAX and DOM |
| Main Page Classes Files Related Pages # 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 568078 2007-08-21 11:43:25Z amassari $
    00020  */
    00021
    00022 #ifndef XML_BIGINTEGER_HPP
    00023 #define 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  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     int         getTotalDigit() const;
    00084
    00093     inline XMLCh*      toString() const;
    00094
    00100     inline XMLCh*      getRawData() const;
    00101
    00112     bool operator==(const XMLBigInteger& toCompare) const;
    00113
    00118     int getSign() const;
    00119
    00120     int intValue() const;
    00121
    00122 private:
    00123     // -----------------------------------------------------------------------
    00124     //  Unimplemented constructors and operators
    00125     // -----------------------------------------------------------------------
    00126     XMLBigInteger& operator=(const XMLBigInteger&);
    00127
    00128
    00129     void setSign(int);
    00130
    00131     /*
    00132      * The number is internally stored in "minimal" sign-fMagnitude format
    00133      * (i.e., no BigIntegers have a leading zero byte in their magnitudes).
    00134      * Zero is represented with a signum of 0 (and a zero-length fMagnitude).
    00135      * Thus, there is exactly one representation for each value.
    00136      */
    00137     // -----------------------------------------------------------------------
    00138     //  Private data members
    00139     //
    00140     //  fSign
    00141     //     to represent the sign of the number.
    00142     //
    00143     //  fMagnitude
    00144     //     the buffer holding the number.
    00145     //
    00146     //  fRawData
    00147     //     to preserve the original string used to construct this object,
    00148     //     needed for pattern matching.
    00149     //
    00150     // -----------------------------------------------------------------------
    00151
    00152     int         fSign;
    00153     XMLCh*      fMagnitude;  //null terminated
    00154     XMLCh*      fRawData;
    00155     MemoryManager* fMemoryManager;
    00156 };
    00157
    00158 inline int XMLBigInteger::getSign() const
    00159 {
    00160     return fSign;
    00161 }
    00162
    00163 inline int XMLBigInteger::getTotalDigit() const
    00164 {
    00165     return ((getSign() ==0) ? 0 : XMLString::stringLen(fMagnitude));
    00166 }
    00167
    00168 inline bool XMLBigInteger::operator==(const XMLBigInteger& toCompare) const
    00169 {
    00170     return ( compareValues(this, &toCompare, fMemoryManager) ==0 ? true : false);
    00171 }
    00172
    00173 inline void XMLBigInteger::setSign(int newSign)
    00174 {
    00175     fSign = newSign;
    00176 }
    00177
    00178 inline XMLCh*  XMLBigInteger::getRawData() const
    00179 {
    00180     return fRawData;
    00181 }
    00182
    00183 //
    00184 // The caller needs to de-allocate the memory allocated by this function
    00185 //
    00186 inline XMLCh*  XMLBigInteger::toString() const
    00187 {
    00188     // Return data using global operator new
    00189     return XMLString::replicate(fRawData, fMemoryManager);
    00190 }
    00191
    00192 XERCES_CPP_NAMESPACE_END
    00193
    00194 #endif

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