Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:14

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XML_BIGINTEGER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XML_BIGINTEGER_HPP
0024 
0025 #include <xercesc/util/XMemory.hpp>
0026 #include <xercesc/util/XMLString.hpp>
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 class XMLUTIL_EXPORT XMLBigInteger : public XMemory
0031 {
0032 public:
0033 
0034     /**
0035      * Constructs a newly allocated <code>XMLBigInteger</code> object that
0036      * represents the value represented by the string. The string is
0037      * converted to an int value as if by the <code>valueOf</code> method.
0038      *
0039      * @param      strValue   the <code>String</code> to be converted to an
0040      *                       <code>XMLBigInteger</code>.
0041      * @param manager    Pointer to the memory manager to be used to
0042      *                   allocate objects.
0043      * @exception  NumberFormatException  if the <code>String</code> does not
0044      *               contain a parsable XMLBigInteger.
0045      */
0046 
0047     XMLBigInteger
0048     (
0049         const XMLCh* const strValue
0050         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0051     );
0052     ~XMLBigInteger();
0053 
0054     XMLBigInteger(const XMLBigInteger& toCopy);
0055 
0056     static XMLCh* getCanonicalRepresentation
0057                         (
0058                           const XMLCh*         const rawData
0059                         ,       MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager
0060                         ,       bool                 isNonPositiveInteger = false
0061                         );
0062 
0063     static void parseBigInteger(const XMLCh* const toConvert
0064                               , XMLCh* const       retBuffer
0065                               , int&   signValue
0066                               , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0067 
0068     static int  compareValues(const XMLBigInteger* const lValue
0069                              ,const XMLBigInteger* const rValue
0070                              , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0071 
0072 
0073     static int  compareValues(const XMLCh*         const lString
0074                             , const int&                 lSign
0075                             , const XMLCh*         const rString
0076                             , const int&                 rSign
0077                             ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0078 
0079     void        multiply(const unsigned int byteToShift);
0080 
0081     void        divide(const unsigned int byteToShift);
0082 
0083     unsigned int       getTotalDigit() const;
0084    
0085     /**
0086      *  Return a copy of the fMagnitude.
0087      *  This is similar to toString, except the internal buffer is returned directly
0088      *  Caller is not required to delete the returned memory.
0089      */
0090     inline XMLCh*      getRawData() const;
0091 
0092     /**
0093      * Compares this object to the specified object.
0094      * The result is <code>true</code> if and only if the argument is not
0095      * <code>null</code> and is an <code>XMLBigInteger</code> object that contains
0096      * the same <code>int</code> value as this object.
0097      *
0098      * @param   toCompare   the object to compare with.
0099      * @return  <code>true</code> if the objects are the same;
0100      *          <code>false</code> otherwise.
0101      */
0102     bool operator==(const XMLBigInteger& toCompare) const;
0103 
0104     /**
0105      * Returns the signum function of this number (i.e., -1, 0 or 1 as
0106      * the value of this number is negative, zero or positive).
0107      */
0108     int getSign() const;
0109 
0110     int intValue() const;
0111 
0112 private:
0113     // -----------------------------------------------------------------------
0114     //  Unimplemented constructors and operators
0115     // -----------------------------------------------------------------------    
0116     XMLBigInteger& operator=(const XMLBigInteger&);
0117 
0118 
0119     void setSign(int);
0120 
0121     /*
0122      * The number is internally stored in "minimal" sign-fMagnitude format
0123      * (i.e., no BigIntegers have a leading zero byte in their magnitudes).
0124      * Zero is represented with a signum of 0 (and a zero-length fMagnitude).
0125      * Thus, there is exactly one representation for each value.
0126      */
0127     // -----------------------------------------------------------------------
0128     //  Private data members
0129     //
0130     //  fSign
0131     //     to represent the sign of the number.
0132     //
0133     //  fMagnitude
0134     //     the buffer holding the number.
0135     //
0136     //  fRawData
0137     //     to preserve the original string used to construct this object,
0138     //     needed for pattern matching.
0139     //
0140     // -----------------------------------------------------------------------
0141 
0142     int         fSign;
0143     XMLCh*      fMagnitude;  //null terminated
0144     XMLCh*      fRawData;
0145     MemoryManager* fMemoryManager;
0146 };
0147 
0148 inline int XMLBigInteger::getSign() const
0149 {    
0150     return fSign;
0151 }
0152 
0153 inline unsigned int XMLBigInteger::getTotalDigit() const
0154 {
0155     return ((getSign() ==0) ? 0 : (unsigned int)XMLString::stringLen(fMagnitude));
0156 }
0157 
0158 inline bool XMLBigInteger::operator==(const XMLBigInteger& toCompare) const
0159 {
0160     return ( compareValues(this, &toCompare, fMemoryManager) ==0 ? true : false);
0161 }
0162 
0163 inline void XMLBigInteger::setSign(int newSign)
0164 {
0165     fSign = newSign;
0166 }
0167 
0168 inline XMLCh*  XMLBigInteger::getRawData() const
0169 {
0170     return fRawData;
0171 }
0172 
0173 XERCES_CPP_NAMESPACE_END
0174 
0175 #endif