# Numeric.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001-2006
    00003  *     DecisionSoft Limited. All rights reserved.
    00004  * Copyright (c) 2004-2006
    00005  *     Progress Software Corporation. All rights reserved.
    00006  * Copyright (c) 2004-2006
    00007  *     Oracle. All rights reserved.
    00008  *
    00009  * See the file LICENSE for redistribution information.
    00010  *
    00011  * $Id: Numeric.hpp,v 1.12 2006/11/01 16:37:14 jpcs Exp $
    00012  */
    00013
    00014 #ifndef __NUMERIC_HPP
    00015 #define __NUMERIC_HPP
    00016
    00017 #include <xercesc/util/XercesDefs.hpp>
    00018 #include <xqilla/framework/XQillaExport.hpp>
    00019 #include <xqilla/items/AnyAtomicType.hpp>
    00020
    00021 class DynamicContext;
    00022 class StaticContext;
    00023 class MAPM;
    00024
    00025 class XQILLA_API Numeric : public AnyAtomicType
    00026 {
    00027 public:
    00028   typedef RefCountPointer<const Numeric> Ptr;
    00029
    00030   /* is this type numeric?  Return true */
    00031   virtual bool isNumericValue() const { return true; };
    00032
    00033   /* Get the name of the primitive type (basic type) of this type
    00034    * (ie "decimal" for xs:decimal) */
    00035   virtual const XMLCh* getPrimitiveTypeName() const = 0;
    00036
    00037   /* Get the namespace URI for this type */
    00038   virtual const XMLCh* getTypeURI() const = 0;
    00039
    00040   /* Get the name of this type  (ie "integer" for xs:integer) */
    00041   virtual const XMLCh* getTypeName() const = 0;
    00042
    00043   /* returns the XMLCh* (canonical) representation of this type */
    00044   virtual const XMLCh* asString(const DynamicContext* context) const = 0;
    00045
    00046   /* Promote this to the given type, if possible */
    00047   virtual Numeric::Ptr promoteTypeIfApplicable(const XMLCh* typeURI, const XMLCh* typeName, const DynamicContext* context) const = 0;
    00048
    00049   /* returns true if the two Numeric values are equal
    00050    * false otherwise */
    00051   virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const;
    00052
    00054   virtual bool lessThan(const Numeric::Ptr &other, const DynamicContext* context) const;
    00055
    00057   virtual bool greaterThan(const Numeric::Ptr &other, const DynamicContext* context) const;
    00058
    00061   virtual int compare(const Numeric::Ptr &other, const DynamicContext *context) const;
    00062
    00064   virtual Numeric::Ptr add(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
    00065
    00068   virtual Numeric::Ptr subtract(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
    00069
    00071   virtual Numeric::Ptr multiply(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
    00072
    00074   virtual Numeric::Ptr divide(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
    00075
    00077   virtual Numeric::Ptr mod(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
    00078
    00080   virtual Numeric::Ptr floor(const DynamicContext* context) const = 0;
    00081
    00083   virtual Numeric::Ptr ceiling(const DynamicContext* context) const = 0;
    00084
    00086   virtual Numeric::Ptr round(const DynamicContext* context) const = 0;
    00087
    00089   virtual Numeric::Ptr roundHalfToEven(const Numeric::Ptr &precision, const DynamicContext* context) const = 0;
    00090
    00092   virtual Numeric::Ptr invert(const DynamicContext* context) const = 0;
    00093
    00095   virtual bool isZero() const = 0;
    00096
    00098   virtual bool isPositive() const = 0;
    00099
    00101   virtual bool isNegative() const = 0;
    00102
    00103   /* Is this floating point value not a number? */
    00104   virtual bool isNaN() const = 0;
    00105
    00106   /* Is this floating point value infinite? */
    00107   virtual bool isInfinite() const = 0;
    00108
    00109   virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const = 0;
    00110
    00111   virtual const MAPM &asMAPM() const = 0;
    00112
    00113   enum State {
    00114     NEG_INF = 0,
    00115     NEG_NUM = 1,
    00116     NUM = 2,
    00117     INF = 3,
    00118     NaN = 4
    00119   };
    00120
    00121   virtual State getState() const = 0;
    00122
    00123   static const XMLCh NaN_string[];
    00124   static const XMLCh NAN_string[];
    00125   static const XMLCh INF_string[];
    00126   static const XMLCh NegINF_string[];
    00127   static const XMLCh NegZero_string[];
    00128   static const XMLCh PosZero_string[];
    00129
    00130   static void checkFloatLimits(Numeric::State &state, MAPM &value);
    00131   static void checkDoubleLimits(Numeric::State &state, MAPM &value);
    00132
    00133   static const XMLCh *asDecimalString(const MAPM &value, int significantDigits, const StaticContext* context);
    00134   static const XMLCh *asDoubleString(State state, const MAPM &value, int significantDigits, const StaticContext* context);
    00135
    00136 protected:
    00137   virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
    00138                                             const XMLCh* targetType, const DynamicContext* context) const;
    00139
    00140   const XMLCh *asDecimalString(int significantDigits, const StaticContext* context) const;
    00141   const XMLCh *asDoubleString(int significantDigits, const StaticContext* context) const;
    00142
    00143 };
    00144
    00145 #endif //  __NUMERIC_HPP