00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00031 virtual bool isNumericValue() const { return true; };
00032
00033
00034
00035 virtual const XMLCh* getPrimitiveTypeName() const = 0;
00036
00037
00038 virtual const XMLCh* getTypeURI() const = 0;
00039
00040
00041 virtual const XMLCh* getTypeName() const = 0;
00042
00043
00044 virtual const XMLCh* asString(const DynamicContext* context) const = 0;
00045
00046
00047 virtual Numeric::Ptr promoteTypeIfApplicable(const XMLCh* typeURI, const XMLCh* typeName, const DynamicContext* context) const = 0;
00048
00049
00050
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
00104 virtual bool isNaN() const = 0;
00105
00106
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