You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2001/11/19 22:33:43 UTC
cvs commit: xml-xerces/c/src/util XMLAbstractDoubleFloat.hpp XMLAbstractDoubleFloat.cpp XMLFloat.hpp XMLFloat.cpp XMLDouble.hpp XMLDouble.cpp
peiyongz 01/11/19 13:33:43
Modified: c/src/util XMLFloat.hpp XMLFloat.cpp XMLDouble.hpp
XMLDouble.cpp
Added: c/src/util XMLAbstractDoubleFloat.hpp
XMLAbstractDoubleFloat.cpp
Log:
Reorganization: Double/Float
Revision Changes Path
1.7 +21 -91 xml-xerces/c/src/util/XMLFloat.hpp
Index: XMLFloat.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLFloat.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLFloat.hpp 2001/10/26 16:37:46 1.6
+++ XMLFloat.hpp 2001/11/19 21:33:42 1.7
@@ -55,13 +55,16 @@
*/
/*
- * $Id: XMLFloat.hpp,v 1.6 2001/10/26 16:37:46 peiyongz Exp $
+ * $Id: XMLFloat.hpp,v 1.7 2001/11/19 21:33:42 peiyongz Exp $
* $Log: XMLFloat.hpp,v $
+ * Revision 1.7 2001/11/19 21:33:42 peiyongz
+ * Reorganization: Double/Float
+ *
* Revision 1.6 2001/10/26 16:37:46 peiyongz
* Add thread safe code
*
* Revision 1.4 2001/09/27 14:54:20 peiyongz
- * DTV Reorganization: derived from XMLNumber
+ * DTV Reorganization: derived from XMLAbstractDoubleFloat
*
* Revision 1.3 2001/08/29 19:03:03 peiyongz
* Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
@@ -78,26 +81,9 @@
#ifndef XML_FLOAT_HPP
#define XML_FLOAT_HPP
-#include <util/XercesDefs.hpp>
-#include <util/XMLNumber.hpp>
-#include <util/XMLBigDecimal.hpp>
-
-/***
- * 3.2.4.1 Lexical representation
- *
- * float values have a lexical representation consisting of a mantissa followed,
- * optionally, by the character "E" or "e", followed by an exponent.
- *
- * The exponent �must� be an integer.
- * The mantissa must be a decimal number.
- * The representations for exponent and mantissa must follow the lexical rules
- * for integer and decimal.
- *
- * If the "E" or "e" and the following exponent are omitted,
- * an exponent value of 0 is assumed.
-***/
+#include <util/XMLAbstractDoubleFloat.hpp>
-class XMLUTIL_EXPORT XMLFloat : public XMLNumber
+class XMLUTIL_EXPORT XMLFloat : public XMLAbstractDoubleFloat
{
public:
@@ -111,27 +97,10 @@
* contain a parsable XMLFloat.
*/
- enum LiteralType
- {
- NegINF,
- NegZero,
- PosZero,
- PosINF,
- NaN,
- SpecialTypeNum = 5,
- Normal
- };
-
XMLFloat(const XMLCh* const strValue);
~XMLFloat();
-
- XMLFloat(const XMLFloat& toCopy);
-
- virtual XMLCh* toString() const;
-
- virtual int getSign() const;
-
+
/**
* Compares this object to the specified object.
* The result is <code>true</code> if and only if the argument is not
@@ -142,75 +111,36 @@
* @return <code>true</code> if the objects are the same;
* <code>false</code> otherwise.
*/
- bool operator==(const XMLFloat& toCompare) const;
- static int compareValues(const XMLFloat* const lValue
- , const XMLFloat* const rValue);
+ inline static int compareValues(const XMLFloat* const lValue
+ , const XMLFloat* const rValue);
// -----------------------------------------------------------------------
// Notification that lazy data has been deleted
// -----------------------------------------------------------------------
static void reinitXMLFloat();
-private:
+protected:
- void init(const XMLCh* const strValue);
-
void checkBoundary(const XMLCh* const strValue);
-
- void cleanUp();
-
- bool isSpecialValue() const;
- static int compareSpecial(const XMLFloat* const specialValue
- , const XMLFloat* const normalValue);
-
- // -----------------------------------------------------------------------
- // Private data members
- //
- // fMantissa
- // the XMLBigDecimal holding the value of mantissa.
+private:
//
- // fExponent
- // the XMLBigInteger holding the value of exponent.
+ // Unimplemented
//
- // fType
- // the type of the object.
+ // copy ctor
+ // assignment ctor
//
- // -----------------------------------------------------------------------
+ XMLFloat(const XMLFloat& toCopy);
+ operator=(const XMLFloat& toAssign);
- XMLBigDecimal* fMantissa;
- XMLBigInteger* fExponent;
- LiteralType fType;
};
-
-inline bool XMLFloat::operator==(const XMLFloat& toCompare) const
-{
- return ( XMLFloat::compareValues(this, &toCompare) == 0 ? true : false);
-}
-
-inline bool XMLFloat::isSpecialValue() const
-{
- return (fType < SpecialTypeNum);
-}
-
-inline void XMLFloat::cleanUp()
-{
- if (fMantissa)
- delete fMantissa;
-
- if (fExponent)
- delete fExponent;
-}
-
-inline int XMLFloat::getSign() const
-{
- return fMantissa->getSign();
-}
-inline XMLFloat::~XMLFloat()
+int XMLFloat::compareValues(const XMLFloat* const lValue
+ , const XMLFloat* const rValue)
{
- cleanUp();
+ return XMLAbstractDoubleFloat::compareValues((const XMLAbstractDoubleFloat* const) lValue,
+ (const XMLAbstractDoubleFloat* const) rValue );
}
#endif
1.13 +10 -280 xml-xerces/c/src/util/XMLFloat.cpp
Index: XMLFloat.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLFloat.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- XMLFloat.cpp 2001/11/19 17:27:55 1.12
+++ XMLFloat.cpp 2001/11/19 21:33:42 1.13
@@ -55,8 +55,11 @@
*/
/*
- * $Id: XMLFloat.cpp,v 1.12 2001/11/19 17:27:55 peiyongz Exp $
+ * $Id: XMLFloat.cpp,v 1.13 2001/11/19 21:33:42 peiyongz Exp $
* $Log: XMLFloat.cpp,v $
+ * Revision 1.13 2001/11/19 21:33:42 peiyongz
+ * Reorganization: Double/Float
+ *
* Revision 1.12 2001/11/19 17:27:55 peiyongz
* Boundary Values updated
*
@@ -103,34 +106,10 @@
#include <util/XMLString.hpp>
#include <util/XMLUniDefs.hpp>
#include <util/NumberFormatException.hpp>
-#include <util/TransService.hpp>
-#include <util/Janitor.hpp>
-#include <util/XMLUni.hpp>
-#include <math.h>
-//---------
-// TODO:
-//
-// Double is supposed to hold 64 bit number and currently
-// we have implemented the checking on boundary values, such
-// the maximum/minimum positive/negative number.
-//
-// We also need to do roundup/roundoff for extra bit in the
-// lexical representation.
-// In order to do that, we need to store them in a canonical form,
-// like this.
-// [-]?[1-9].[0-9]+[E|e][-]?[0-9]+
-//
-// Then we can impose the limit of length after the '.' before 'E'.
-//
-//---------
-
// ---------------------------------------------------------------------------
// local data member
// ---------------------------------------------------------------------------
-static const int BUF_LEN = 64;
-static XMLCh value1[BUF_LEN+1];
-
//
// 2^24 x 2^104 = 2^128 = 3.4028236692093846346337460743177e+38
// +
@@ -204,108 +183,17 @@
static XMLMutex* sFloatMutex = 0;
static XMLRegisterCleanup XMLFloatCleanup;
-/***
- * Algo:
- *
- * . Check for special cases
- * . Construct fMantissa, fExponent (optional)
- * . Checking boundary
- * .
-***/
+// ---------------------------------------------------------------------------
+// ctor/dtor
+// ---------------------------------------------------------------------------
XMLFloat::XMLFloat(const XMLCh* const strValue)
-:fMantissa(0)
-,fExponent(0)
-,fType(Normal)
+:XMLAbstractDoubleFloat()
{
- try
- {
- init(strValue);
- }
- catch (...)
- {
- cleanUp();
- throw;
- }
-
+ init(strValue);
}
-void XMLFloat::init(const XMLCh* const strValue)
+XMLFloat::~XMLFloat()
{
- if ((!strValue) || (!*strValue))
- ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
-
- XMLCh* tmpStrValue = XMLString::replicate(strValue);
- ArrayJanitor<XMLCh> janTmpName(tmpStrValue);
- XMLString::trim(tmpStrValue);
-
- if (XMLString::compareString(tmpStrValue, XMLUni::fgNegINFString) == 0)
- {
- fType = NegINF;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgNegZeroString) == 0)
- {
- fType = NegZero;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosZeroString) == 0)
- {
- fType = PosZero;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosINFString) == 0)
- {
- fType = PosINF;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgNaNString) == 0)
- {
- fType = NaN;
- return;
- }
-
- //
- // Normal case
- //
- int ePos = 0;
- int tmpStrLen = XMLString::stringLen(tmpStrValue);
-
- if ((( ePos = XMLString::indexOf(tmpStrValue, chLatin_E)) != -1 ) ||
- (( ePos = XMLString::indexOf(tmpStrValue, chLatin_e)) != -1 ) )
- {
- XMLCh* tmpMantissa = new XMLCh [ePos+1];
- XMLString::subString(tmpMantissa, tmpStrValue, 0, ePos);
- ArrayJanitor<XMLCh> janMantissa(tmpMantissa);
- fMantissa = new XMLBigDecimal(tmpMantissa);
-
- //
- // 1234.56E78
- //
- if ( ePos < tmpStrLen - 1)
- {
- XMLCh* tmpExponent = new XMLCh [tmpStrLen - ePos];
- XMLString::subString(tmpExponent, tmpStrValue, ePos + 1, tmpStrLen);
- ArrayJanitor<XMLCh> janExponent(tmpExponent);
- fExponent = new XMLBigInteger(tmpExponent);
- }
- //
- // 1234.56E
- //
- else
- {
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_No_Exponent
- , strValue);
- }
-
- }
- else
- {
- fMantissa = new XMLBigDecimal(tmpStrValue);
- fExponent = new XMLBigInteger(XMLUni::fgZeroString);
- }
-
- checkBoundary(tmpStrValue);
}
//
@@ -375,164 +263,6 @@
, FLT_MIN_POSITIVE);
}
-}
-
-XMLFloat::XMLFloat(const XMLFloat& toCopy)
-:fMantissa(0)
-,fExponent(0)
-,fType(Normal)
-{
- if (!toCopy.isSpecialValue())
- {
- fMantissa = new XMLBigDecimal(*(toCopy.fMantissa));
- fExponent = new XMLBigInteger(*(toCopy.fExponent));
- }
-
- fType = toCopy.fType;
-}
-
-//
-// Add the 'E' as necessary
-// The caller needs to de-allocate the memory allocated by this function
-// Deallocate the memory allocated by XMLBigInteger
-//
-XMLCh* XMLFloat::toString() const
-{
- switch (fType)
- {
- case NegINF:
- return XMLString::replicate(XMLUni::fgNegINFString);
-
- case NegZero:
- return XMLString::replicate(XMLUni::fgNegZeroString);
-
- case PosZero:
- return XMLString::replicate(XMLUni::fgPosZeroString);
-
- case PosINF:
- return XMLString::replicate(XMLUni::fgPosINFString);
-
- case NaN:
- return XMLString::replicate(XMLUni::fgNaNString);
-
- case Normal:
-
- XMLCh *ret_mantissa;
- ret_mantissa = fMantissa->toString();
-
- if (fExponent)
- {
- XMLCh *ret_exponent = fExponent->toString();
- XMLCh *ret_val = new XMLCh [ XMLString::stringLen(ret_mantissa) +
- XMLString::stringLen(ret_exponent) + 2];
- *ret_val = 0;
- XMLString::catString(ret_val, ret_mantissa);
- XMLString::catString(ret_val, XMLUni::fgEString);
- XMLString::catString(ret_val, ret_exponent);
-
- delete [] ret_mantissa;
- delete [] ret_exponent;
- return ret_val;
- }
- else
- return ret_mantissa;
-
- break;
- default:
- XMLString::binToText(fType, value1, 16, 10);
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_InvalidType
- , value1);
- };
-
- return (XMLCh*) 0;
-}
-
-//
-//
-//
-int XMLFloat::compareValues(const XMLFloat* const lValue
- , const XMLFloat* const rValue)
-{
- //
- // case#1: lValue normal
- // rValue normal
- //
- if ((!lValue->isSpecialValue()) &&
- (!rValue->isSpecialValue()) )
- {
- //
- // if we use fValue to compare two
- // sequences "12.3456E4" and "1234.56E2",
- // they are _NOT_ the same. so we ask
- // BigDecimal to compare.
- //
- XMLBigDecimal ldv = XMLBigDecimal(*(lValue->fMantissa), lValue->fExponent->intValue());
- XMLBigDecimal rdv = XMLBigDecimal(*(rValue->fMantissa), rValue->fExponent->intValue());
-
- return XMLBigDecimal::compareValues(&ldv, &rdv);
- }
- //
- // case#2: lValue special
- // rValue special
- //
- else
- if ((lValue->isSpecialValue()) &&
- (rValue->isSpecialValue()) )
- {
- if (lValue->fType == rValue->fType)
- return 0;
- else
- return (lValue->fType > rValue->fType ? 1 : -1);
- }
- //
- // case#3: lValue special
- // rValue normal
- //
- else
- if ((lValue->isSpecialValue()) &&
- (!rValue->isSpecialValue()) )
- {
- return compareSpecial(lValue, rValue);
- }
- //
- // case#4: lValue normal
- // rValue special
- //
- else
- {
- return (-1) * compareSpecial(rValue, lValue);
- }
-
- return 0;
-}
-
-int XMLFloat::compareSpecial(const XMLFloat* const specialValue
- , const XMLFloat* const normalValue)
-{
- switch (specialValue->fType)
- {
- case NegINF:
- return -1;
-
- case NegZero:
- case PosZero:
- return (normalValue->getSign() > 0 ? -1 : 1);
-
- case PosINF:
- return 1;
-
- case NaN:
- return 1;
-
- default:
- XMLString::binToText(specialValue->fType, value1, 16, 10);
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_InvalidType
- , value1);
- return 0;
- //internal error
- }
}
// -----------------------------------------------------------------------
1.9 +21 -91 xml-xerces/c/src/util/XMLDouble.hpp
Index: XMLDouble.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLDouble.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XMLDouble.hpp 2001/10/26 16:37:46 1.8
+++ XMLDouble.hpp 2001/11/19 21:33:42 1.9
@@ -55,13 +55,16 @@
*/
/*
- * $Id: XMLDouble.hpp,v 1.8 2001/10/26 16:37:46 peiyongz Exp $
+ * $Id: XMLDouble.hpp,v 1.9 2001/11/19 21:33:42 peiyongz Exp $
* $Log: XMLDouble.hpp,v $
+ * Revision 1.9 2001/11/19 21:33:42 peiyongz
+ * Reorganization: Double/Float
+ *
* Revision 1.8 2001/10/26 16:37:46 peiyongz
* Add thread safe code
*
* Revision 1.6 2001/09/27 14:54:20 peiyongz
- * DTV Reorganization: derived from XMLNumber
+ * DTV Reorganization: derived from XMLAbstractDoubleFloat
*
* Revision 1.5 2001/08/29 19:03:03 peiyongz
* Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
@@ -83,26 +86,9 @@
#ifndef XML_DOUBLE_HPP
#define XML_DOUBLE_HPP
-#include <util/XercesDefs.hpp>
-#include <util/XMLNumber.hpp>
-#include <util/XMLBigDecimal.hpp>
-
-/***
- * 3.2.5.1 Lexical representation
- *
- * double values have a lexical representation consisting of a mantissa followed,
- * optionally, by the character "E" or "e", followed by an exponent.
- *
- * The exponent �must� be an integer.
- * The mantissa must be a decimal number.
- * The representations for exponent and mantissa must follow the lexical rules
- * for integer and decimal.
- *
- * If the "E" or "e" and the following exponent are omitted,
- * an exponent value of 0 is assumed.
-***/
+#include <util/XMLAbstractDoubleFloat.hpp>
-class XMLUTIL_EXPORT XMLDouble : public XMLNumber
+class XMLUTIL_EXPORT XMLDouble : public XMLAbstractDoubleFloat
{
public:
@@ -116,27 +102,10 @@
* contain a parsable XMLDouble.
*/
- enum LiteralType
- {
- NegINF,
- NegZero,
- PosZero,
- PosINF,
- NaN,
- SpecialTypeNum = 5,
- Normal
- };
-
XMLDouble(const XMLCh* const strValue);
~XMLDouble();
-
- XMLDouble(const XMLDouble& toCopy);
-
- virtual XMLCh* toString() const;
-
- virtual int getSign() const;
-
+
/**
* Compares this object to the specified object.
* The result is <code>true</code> if and only if the argument is not
@@ -147,75 +116,36 @@
* @return <code>true</code> if the objects are the same;
* <code>false</code> otherwise.
*/
- bool operator==(const XMLDouble& toCompare) const;
- static int compareValues(const XMLDouble* const lValue
- , const XMLDouble* const rValue);
+ inline static int compareValues(const XMLDouble* const lValue
+ , const XMLDouble* const rValue);
// -----------------------------------------------------------------------
// Notification that lazy data has been deleted
// -----------------------------------------------------------------------
static void reinitXMLDouble();
-
-private:
- void init(const XMLCh* const strValue);
+protected:
void checkBoundary(const XMLCh* const strValue);
-
- void cleanUp();
-
- bool isSpecialValue() const;
- static int compareSpecial(const XMLDouble* const specialValue
- , const XMLDouble* const normalValue);
-
- // -----------------------------------------------------------------------
- // Private data members
- //
- // fMantissa
- // the XMLBigDecimal holding the value of mantissa.
+private:
//
- // fExponent
- // the XMLBigInteger holding the value of exponent.
+ // Unimplemented
//
- // fType
- // the type of the object.
+ // copy ctor
+ // assignment ctor
//
- // -----------------------------------------------------------------------
+ XMLDouble(const XMLDouble& toCopy);
+ operator=(const XMLDouble& toAssign);
- XMLBigDecimal* fMantissa;
- XMLBigInteger* fExponent;
- LiteralType fType;
};
-
-inline int XMLDouble::getSign() const
-{
- return fMantissa->getSign();
-}
-
-inline bool XMLDouble::operator==(const XMLDouble& toCompare) const
-{
- return ( XMLDouble::compareValues(this, &toCompare) == 0 ? true : false);
-}
-
-inline bool XMLDouble::isSpecialValue() const
-{
- return (fType < SpecialTypeNum);
-}
-
-inline void XMLDouble::cleanUp()
-{
- if (fMantissa)
- delete fMantissa;
-
- if (fExponent)
- delete fExponent;
-}
-inline XMLDouble::~XMLDouble()
+int XMLDouble::compareValues(const XMLDouble* const lValue
+ , const XMLDouble* const rValue)
{
- cleanUp();
+ return XMLAbstractDoubleFloat::compareValues((const XMLAbstractDoubleFloat* const) lValue,
+ (const XMLAbstractDoubleFloat* const) rValue );
}
#endif
1.16 +10 -267 xml-xerces/c/src/util/XMLDouble.cpp
Index: XMLDouble.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLDouble.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XMLDouble.cpp 2001/11/19 17:27:55 1.15
+++ XMLDouble.cpp 2001/11/19 21:33:42 1.16
@@ -55,8 +55,11 @@
*/
/*
- * $Id: XMLDouble.cpp,v 1.15 2001/11/19 17:27:55 peiyongz Exp $
+ * $Id: XMLDouble.cpp,v 1.16 2001/11/19 21:33:42 peiyongz Exp $
* $Log: XMLDouble.cpp,v $
+ * Revision 1.16 2001/11/19 21:33:42 peiyongz
+ * Reorganization: Double/Float
+ *
* Revision 1.15 2001/11/19 17:27:55 peiyongz
* Boundary Values updated
*
@@ -111,10 +114,6 @@
#include <util/XMLString.hpp>
#include <util/XMLUniDefs.hpp>
#include <util/NumberFormatException.hpp>
-#include <util/TransService.hpp>
-#include <util/Janitor.hpp>
-#include <util/XMLUni.hpp>
-#include <math.h>
//---------
// TODO:
@@ -134,14 +133,8 @@
//---------
// ---------------------------------------------------------------------------
-// class data member
-// ---------------------------------------------------------------------------
-
-// ---------------------------------------------------------------------------
// local data member
// ---------------------------------------------------------------------------
-static const int BUF_LEN = 64;
-static XMLCh value1[BUF_LEN+1];
//
// 2^53 x 2^970 = 2^1023 = 8.9884656743115795386465259539451e+307
@@ -216,115 +209,23 @@
static XMLMutex* sDoubleMutex = 0;
static XMLRegisterCleanup XMLDoubleCleanup;
-/***
- * Algo:
- *
- * . Check for special cases
- * . Construct fMantissa, fExponent (optional)
- * . Checking boundary
- * .
-***/
+// ---------------------------------------------------------------------------
+// ctor/dtor
+// ---------------------------------------------------------------------------
XMLDouble::XMLDouble(const XMLCh* const strValue)
-:fMantissa(0)
-,fExponent(0)
-,fType(Normal)
+:XMLAbstractDoubleFloat()
{
- try
- {
- init(strValue);
- }
- catch (...)
- {
- cleanUp();
- throw;
- }
-
+ init(strValue);
}
-void XMLDouble::init(const XMLCh* const strValue)
+XMLDouble::~XMLDouble()
{
- if ((!strValue) || (!*strValue))
- ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
-
- XMLCh* tmpStrValue = XMLString::replicate(strValue);
- ArrayJanitor<XMLCh> janTmpName(tmpStrValue);
- XMLString::trim(tmpStrValue);
-
- if (XMLString::compareString(tmpStrValue, XMLUni::fgNegINFString) == 0)
- {
- fType = NegINF;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgNegZeroString) == 0)
- {
- fType = NegZero;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosZeroString) == 0)
- {
- fType = PosZero;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosINFString) == 0)
- {
- fType = PosINF;
- return;
- }
- else if (XMLString::compareString(tmpStrValue, XMLUni::fgNaNString) == 0)
- {
- fType = NaN;
- return;
- }
-
- //
- // Normal case
- //
- int ePos = 0;
- int tmpStrLen = XMLString::stringLen(tmpStrValue);
-
- if ((( ePos = XMLString::indexOf(tmpStrValue, chLatin_E)) != -1 ) ||
- (( ePos = XMLString::indexOf(tmpStrValue, chLatin_e)) != -1 ) )
- {
- XMLCh* tmpMantissa = new XMLCh [ePos+1];
- XMLString::subString(tmpMantissa, tmpStrValue, 0, ePos);
- ArrayJanitor<XMLCh> janMantissa(tmpMantissa);
- fMantissa = new XMLBigDecimal(tmpMantissa);
-
- //
- // 1234.56E78
- //
- if ( ePos < tmpStrLen - 1)
- {
- XMLCh* tmpExponent = new XMLCh [tmpStrLen - ePos];
- XMLString::subString(tmpExponent, tmpStrValue, ePos + 1, tmpStrLen);
- ArrayJanitor<XMLCh> janExponent(tmpExponent);
- fExponent = new XMLBigInteger(tmpExponent);
- }
- //
- // 1234.56E
- //
- else
- {
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_No_Exponent
- , strValue);
- }
-
- }
- else
- {
- fMantissa = new XMLBigDecimal(tmpStrValue);
- fExponent = new XMLBigInteger(XMLUni::fgZeroString);
- }
-
- checkBoundary(tmpStrValue);
}
//
//
void XMLDouble::checkBoundary(const XMLCh* const strValue)
{
-
if (!sDoubleMutex)
{
XMLMutex* tmpMutex = new XMLMutex;
@@ -388,164 +289,6 @@
, DBL_MIN_POSITIVE);
}
-}
-
-XMLDouble::XMLDouble(const XMLDouble& toCopy)
-:fMantissa(0)
-,fExponent(0)
-,fType(Normal)
-{
- if (!toCopy.isSpecialValue())
- {
- fMantissa = new XMLBigDecimal(*(toCopy.fMantissa));
- fExponent = new XMLBigInteger(*(toCopy.fExponent));
- }
-
- fType = toCopy.fType;
-}
-
-//
-// Add the 'E' as necessary
-// The caller needs to de-allocate the memory allocated by this function
-// Deallocate the memory allocated by XMLBigInteger
-//
-XMLCh* XMLDouble::toString() const
-{
- switch (fType)
- {
- case NegINF:
- return XMLString::replicate(XMLUni::fgNegINFString);
-
- case NegZero:
- return XMLString::replicate(XMLUni::fgNegZeroString);
-
- case PosZero:
- return XMLString::replicate(XMLUni::fgPosZeroString);
-
- case PosINF:
- return XMLString::replicate(XMLUni::fgPosINFString);
-
- case NaN:
- return XMLString::replicate(XMLUni::fgNaNString);
-
- case Normal:
-
- XMLCh *ret_mantissa;
- ret_mantissa = fMantissa->toString();
-
- if (fExponent)
- {
- XMLCh *ret_exponent = fExponent->toString();
- XMLCh *ret_val = new XMLCh [ XMLString::stringLen(ret_mantissa) +
- XMLString::stringLen(ret_exponent) + 2];
- *ret_val = 0;
- XMLString::catString(ret_val, ret_mantissa);
- XMLString::catString(ret_val, XMLUni::fgEString);
- XMLString::catString(ret_val, ret_exponent);
-
- delete [] ret_mantissa;
- delete [] ret_exponent;
- return ret_val;
- }
- else
- return ret_mantissa;
-
- break;
- default:
- XMLString::binToText(fType, value1, 16, 10);
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_InvalidType
- , value1);
- };
-
- return (XMLCh*) 0;
-}
-
-//
-//
-//
-int XMLDouble::compareValues(const XMLDouble* const lValue
- , const XMLDouble* const rValue)
-{
- //
- // case#1: lValue normal
- // rValue normal
- //
- if ((!lValue->isSpecialValue()) &&
- (!rValue->isSpecialValue()) )
- {
- //
- // if we use fValue to compare two
- // sequences "12.3456E4" and "1234.56E2",
- // they are _NOT_ the same. so we ask
- // BigDecimal to compare.
- //
- XMLBigDecimal ldv = XMLBigDecimal(*(lValue->fMantissa), lValue->fExponent->intValue());
- XMLBigDecimal rdv = XMLBigDecimal(*(rValue->fMantissa), rValue->fExponent->intValue());
-
- return XMLBigDecimal::compareValues(&ldv, &rdv);
- }
- //
- // case#2: lValue special
- // rValue special
- //
- else
- if ((lValue->isSpecialValue()) &&
- (rValue->isSpecialValue()) )
- {
- if (lValue->fType == rValue->fType)
- return 0;
- else
- return (lValue->fType > rValue->fType ? 1 : -1);
- }
- //
- // case#3: lValue special
- // rValue normal
- //
- else
- if ((lValue->isSpecialValue()) &&
- (!rValue->isSpecialValue()) )
- {
- return compareSpecial(lValue, rValue);
- }
- //
- // case#4: lValue normal
- // rValue special
- //
- else
- {
- return (-1) * compareSpecial(rValue, lValue);
- }
-
- return 0;
-}
-
-int XMLDouble::compareSpecial(const XMLDouble* const specialValue
- , const XMLDouble* const normalValue)
-{
- switch (specialValue->fType)
- {
- case NegINF:
- return -1;
-
- case NegZero:
- case PosZero:
- return (normalValue->getSign() > 0 ? -1 : 1);
-
- case PosINF:
- return 1;
-
- case NaN:
- return 1;
-
- default:
- XMLString::binToText(specialValue->fType, value1, 16, 10);
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_InvalidType
- , value1);
- //internal error
- return 0;
- }
}
// -----------------------------------------------------------------------
1.1 xml-xerces/c/src/util/XMLAbstractDoubleFloat.hpp
Index: XMLAbstractDoubleFloat.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* $Id: XMLAbstractDoubleFloat.hpp,v 1.1 2001/11/19 21:33:42 peiyongz Exp $
* $Log: XMLAbstractDoubleFloat.hpp,v $
* Revision 1.1 2001/11/19 21:33:42 peiyongz
* Reorganization: Double/Float
*
*
*/
#ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP
#define XML_ABSTRACT_DOUBLE_FLOAT_HPP
#include <util/XercesDefs.hpp>
#include <util/XMLNumber.hpp>
#include <util/XMLBigDecimal.hpp>
/***
* 3.2.5.1 Lexical representation
*
* double values have a lexical representation consisting of a mantissa followed,
* optionally, by the character "E" or "e", followed by an exponent.
*
* The exponent �must� be an integer.
* The mantissa must be a decimal number.
* The representations for exponent and mantissa must follow the lexical rules
* for integer and decimal.
*
* If the "E" or "e" and the following exponent are omitted,
* an exponent value of 0 is assumed.
***/
/***
* 3.2.4.1 Lexical representation
*
* float values have a lexical representation consisting of a mantissa followed,
* optionally, by the character "E" or "e", followed by an exponent.
*
* The exponent �must� be an integer.
* The mantissa must be a decimal number.
* The representations for exponent and mantissa must follow the lexical rules
* for integer and decimal.
*
* If the "E" or "e" and the following exponent are omitted,
* an exponent value of 0 is assumed.
***/
class XMLUTIL_EXPORT XMLAbstractDoubleFloat : public XMLNumber
{
public:
enum LiteralType
{
NegINF,
NegZero,
PosZero,
PosINF,
NaN,
SpecialTypeNum = 5,
Normal
};
virtual ~XMLAbstractDoubleFloat();
virtual XMLCh* toString() const;
virtual int getSign() const;
protected:
//
// To be used by derived class exclusively
//
XMLAbstractDoubleFloat();
void init(const XMLCh* const strValue);
/**
* Compares this object to the specified object.
* The result is <code>true</code> if and only if the argument is not
* <code>null</code> and is an <code>XMLAbstractDoubleFloat</code> object that contains
* the same <code>int</code> value as this object.
*
* @param obj the object to compare with.
* @return <code>true</code> if the objects are the same;
* <code>false</code> otherwise.
*/
static int compareValues(const XMLAbstractDoubleFloat* const lValue
, const XMLAbstractDoubleFloat* const rValue);
//
// to be overwritten by derived class
//
virtual void checkBoundary(const XMLCh* const strValue) = 0;
private:
//
// Unimplemented
//
// copy ctor
// assignment ctor
//
XMLAbstractDoubleFloat(const XMLAbstractDoubleFloat& toCopy);
operator=(const XMLAbstractDoubleFloat& toAssign);
inline bool isSpecialValue() const;
static int compareSpecial(const XMLAbstractDoubleFloat* const specialValue
, const XMLAbstractDoubleFloat* const normalValue);
// -----------------------------------------------------------------------
// Private data members
//
// fMantissa
// the XMLBigDecimal holding the value of mantissa.
//
// fExponent
// the XMLBigInteger holding the value of exponent.
//
// fType
// the type of the object.
//
// -----------------------------------------------------------------------
XMLBigDecimal* fMantissa;
XMLBigInteger* fExponent;
LiteralType fType;
};
bool XMLAbstractDoubleFloat::isSpecialValue() const
{
return (fType < SpecialTypeNum);
}
#endif
1.1 xml-xerces/c/src/util/XMLAbstractDoubleFloat.cpp
Index: XMLAbstractDoubleFloat.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* $Id: XMLAbstractDoubleFloat.cpp,v 1.1 2001/11/19 21:33:42 peiyongz Exp $
* $Log: XMLAbstractDoubleFloat.cpp,v $
* Revision 1.1 2001/11/19 21:33:42 peiyongz
* Reorganization: Double/Float
*
*
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <util/XMLAbstractDoubleFloat.hpp>
#include <util/XMLUniDefs.hpp>
#include <util/NumberFormatException.hpp>
#include <util/Janitor.hpp>
// ---------------------------------------------------------------------------
// local data member
// ---------------------------------------------------------------------------
static const int BUF_LEN = 64;
static XMLCh value1[BUF_LEN+1];
// ---------------------------------------------------------------------------
// ctor/dtor
// ---------------------------------------------------------------------------
XMLAbstractDoubleFloat::XMLAbstractDoubleFloat()
:fMantissa(0)
,fExponent(0)
,fType(Normal)
{
}
XMLAbstractDoubleFloat::~XMLAbstractDoubleFloat()
{
if (fMantissa)
delete fMantissa;
if (fExponent)
delete fExponent;
}
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue)
{
if ((!strValue) || (!*strValue))
ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
XMLCh* tmpStrValue = XMLString::replicate(strValue);
ArrayJanitor<XMLCh> janTmpName(tmpStrValue);
XMLString::trim(tmpStrValue);
if (XMLString::compareString(tmpStrValue, XMLUni::fgNegINFString) == 0)
{
fType = NegINF;
return;
}
else if (XMLString::compareString(tmpStrValue, XMLUni::fgNegZeroString) == 0)
{
fType = NegZero;
return;
}
else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosZeroString) == 0)
{
fType = PosZero;
return;
}
else if (XMLString::compareString(tmpStrValue, XMLUni::fgPosINFString) == 0)
{
fType = PosINF;
return;
}
else if (XMLString::compareString(tmpStrValue, XMLUni::fgNaNString) == 0)
{
fType = NaN;
return;
}
//
// Normal case
//
int ePos = 0;
int tmpStrLen = XMLString::stringLen(tmpStrValue);
if ((( ePos = XMLString::indexOf(tmpStrValue, chLatin_E)) != -1 ) ||
(( ePos = XMLString::indexOf(tmpStrValue, chLatin_e)) != -1 ) )
{
XMLCh* tmpMantissa = new XMLCh [ePos+1];
XMLString::subString(tmpMantissa, tmpStrValue, 0, ePos);
ArrayJanitor<XMLCh> janMantissa(tmpMantissa);
fMantissa = new XMLBigDecimal(tmpMantissa);
//
// 1234.56E78
//
if ( ePos < tmpStrLen - 1)
{
XMLCh* tmpExponent = new XMLCh [tmpStrLen - ePos];
XMLString::subString(tmpExponent, tmpStrValue, ePos + 1, tmpStrLen);
ArrayJanitor<XMLCh> janExponent(tmpExponent);
fExponent = new XMLBigInteger(tmpExponent);
}
//
// 1234.56E
//
else
{
ThrowXML1(NumberFormatException
, XMLExcepts::XMLNUM_DBL_FLT_No_Exponent
, strValue);
}
}
else
{
fMantissa = new XMLBigDecimal(tmpStrValue);
fExponent = new XMLBigInteger(XMLUni::fgZeroString);
}
checkBoundary(tmpStrValue);
}
//
// Add the 'E' as necessary
// The caller needs to de-allocate the memory allocated by this function
// Deallocate the memory allocated by XMLBigInteger
//
XMLCh* XMLAbstractDoubleFloat::toString() const
{
switch (fType)
{
case NegINF:
return XMLString::replicate(XMLUni::fgNegINFString);
case NegZero:
return XMLString::replicate(XMLUni::fgNegZeroString);
case PosZero:
return XMLString::replicate(XMLUni::fgPosZeroString);
case PosINF:
return XMLString::replicate(XMLUni::fgPosINFString);
case NaN:
return XMLString::replicate(XMLUni::fgNaNString);
case Normal:
XMLCh *ret_mantissa;
ret_mantissa = fMantissa->toString();
if (fExponent)
{
XMLCh *ret_exponent = fExponent->toString();
XMLCh *ret_val = new XMLCh [ XMLString::stringLen(ret_mantissa) +
XMLString::stringLen(ret_exponent) + 2];
*ret_val = 0;
XMLString::catString(ret_val, ret_mantissa);
XMLString::catString(ret_val, XMLUni::fgEString);
XMLString::catString(ret_val, ret_exponent);
delete [] ret_mantissa;
delete [] ret_exponent;
return ret_val;
}
else
return ret_mantissa;
break;
default:
XMLString::binToText(fType, value1, 16, 10);
ThrowXML1(NumberFormatException
, XMLExcepts::XMLNUM_DBL_FLT_InvalidType
, value1);
};
return (XMLCh*) 0;
}
int XMLAbstractDoubleFloat::getSign() const
{
return fMantissa->getSign();
}
//
//
//
int XMLAbstractDoubleFloat::compareValues(const XMLAbstractDoubleFloat* const lValue
, const XMLAbstractDoubleFloat* const rValue)
{
//
// case#1: lValue normal
// rValue normal
//
if ((!lValue->isSpecialValue()) &&
(!rValue->isSpecialValue()) )
{
//
// if we use fValue to compare two
// sequences "12.3456E4" and "1234.56E2",
// they are _NOT_ the same. so we ask
// BigDecimal to compare.
//
XMLBigDecimal ldv = XMLBigDecimal(*(lValue->fMantissa), lValue->fExponent->intValue());
XMLBigDecimal rdv = XMLBigDecimal(*(rValue->fMantissa), rValue->fExponent->intValue());
return XMLBigDecimal::compareValues(&ldv, &rdv);
}
//
// case#2: lValue special
// rValue special
//
else
if ((lValue->isSpecialValue()) &&
(rValue->isSpecialValue()) )
{
if (lValue->fType == rValue->fType)
return 0;
else
return (lValue->fType > rValue->fType ? 1 : -1);
}
//
// case#3: lValue special
// rValue normal
//
else
if ((lValue->isSpecialValue()) &&
(!rValue->isSpecialValue()) )
{
return compareSpecial(lValue, rValue);
}
//
// case#4: lValue normal
// rValue special
//
else
{
return (-1) * compareSpecial(rValue, lValue);
}
return 0;
}
int XMLAbstractDoubleFloat::compareSpecial(const XMLAbstractDoubleFloat* const specialValue
, const XMLAbstractDoubleFloat* const normalValue)
{
switch (specialValue->fType)
{
case NegINF:
return -1;
case NegZero:
case PosZero:
return (normalValue->getSign() > 0 ? -1 : 1);
case PosINF:
return 1;
case NaN:
return 1;
default:
XMLString::binToText(specialValue->fType, value1, 16, 10);
ThrowXML1(NumberFormatException
, XMLExcepts::XMLNUM_DBL_FLT_InvalidType
, value1);
//internal error
return 0;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org