00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __NUMERIC_HPP
00023 #define __NUMERIC_HPP
00024
00025 #include <xercesc/util/XercesDefs.hpp>
00026 #include <xqilla/framework/XQillaExport.hpp>
00027 #include <xqilla/items/AnyAtomicType.hpp>
00028
00029 class DynamicContext;
00030 class StaticContext;
00031 class MAPM;
00032
00033 class XQILLA_API Numeric : public AnyAtomicType
00034 {
00035 public:
00036 typedef RefCountPointer<const Numeric> Ptr;
00037
00038
00039 virtual bool isNumericValue() const { return true; };
00040
00041
00042
00043 virtual const XMLCh* getPrimitiveTypeName() const = 0;
00044
00045
00046 virtual const XMLCh* getTypeURI() const = 0;
00047
00048
00049 virtual const XMLCh* getTypeName() const = 0;
00050
00051
00052 virtual const XMLCh* asString(const DynamicContext* context) const = 0;
00053
00054
00055 virtual Numeric::Ptr promoteTypeIfApplicable(AnyAtomicType::AtomicObjectType typeIndex,
00056 const DynamicContext* context) const = 0;
00057
00058
00059
00060 virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const;
00061
00063 virtual bool lessThan(const Numeric::Ptr &other, const DynamicContext* context) const;
00064
00066 virtual bool greaterThan(const Numeric::Ptr &other, const DynamicContext* context) const;
00067
00070 virtual int compare(const Numeric::Ptr &other, const DynamicContext *context) const;
00071
00073 virtual Numeric::Ptr add(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00074
00077 virtual Numeric::Ptr subtract(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00078
00080 virtual Numeric::Ptr multiply(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00081
00083 virtual Numeric::Ptr divide(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00084
00086 virtual Numeric::Ptr mod(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00087
00089 virtual Numeric::Ptr floor(const DynamicContext* context) const = 0;
00090
00092 virtual Numeric::Ptr ceiling(const DynamicContext* context) const = 0;
00093
00095 virtual Numeric::Ptr round(const DynamicContext* context) const = 0;
00096
00098 virtual Numeric::Ptr roundHalfToEven(const Numeric::Ptr &precision, const DynamicContext* context) const = 0;
00099
00101 virtual Numeric::Ptr invert(const DynamicContext* context) const = 0;
00102
00104 virtual bool isZero() const = 0;
00105
00107 virtual bool isPositive() const = 0;
00108
00110 virtual bool isNegative() const = 0;
00111
00112
00113 virtual bool isNaN() const = 0;
00114
00115
00116 virtual bool isInfinite() const = 0;
00117
00118 virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const = 0;
00119
00120 virtual const MAPM &asMAPM() const = 0;
00121 virtual double asDouble() const;
00122 virtual int asInt() const;
00123
00124 enum State {
00125 NEG_INF = 0,
00126 NEG_NUM = 1,
00127 NUM = 2,
00128 INF = 3,
00129 NaN = 4
00130 };
00131
00132 virtual State getState() const = 0;
00133
00134 static const XMLCh NaN_string[];
00135 static const XMLCh NAN_string[];
00136 static const XMLCh INF_string[];
00137 static const XMLCh NegINF_string[];
00138 static const XMLCh NegZero_string[];
00139 static const XMLCh PosZero_string[];
00140
00141 static void checkFloatLimits(Numeric::State &state, MAPM &value);
00142 static void checkDoubleLimits(Numeric::State &state, MAPM &value);
00143
00144 static const XMLCh *asDecimalString(const MAPM &value, int significantDigits, const StaticContext* context);
00145 static const XMLCh *asDoubleString(State state, const MAPM &value, int significantDigits, const StaticContext* context);
00146
00147 protected:
00148 virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
00149 const XMLCh* targetType, const DynamicContext* context) const;
00150
00151 const XMLCh *asDecimalString(int significantDigits, const StaticContext* context) const;
00152 const XMLCh *asDoubleString(int significantDigits, const StaticContext* context) const;
00153
00154 };
00155
00156 #endif // __NUMERIC_HPP