00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __NUMERIC_HPP
00021 #define __NUMERIC_HPP
00022
00023 #include <xercesc/util/XercesDefs.hpp>
00024 #include <xqilla/framework/XQillaExport.hpp>
00025 #include <xqilla/items/AnyAtomicType.hpp>
00026
00027 class DynamicContext;
00028 class StaticContext;
00029 class MAPM;
00030
00031 class XQILLA_API Numeric : public AnyAtomicType
00032 {
00033 public:
00034 typedef RefCountPointer<const Numeric> Ptr;
00035
00036
00037 virtual bool isNumericValue() const { return true; };
00038
00039
00040
00041 virtual const XMLCh* getPrimitiveTypeName() const = 0;
00042
00043
00044 virtual const XMLCh* getTypeURI() const = 0;
00045
00046
00047 virtual const XMLCh* getTypeName() const = 0;
00048
00049
00050 virtual const XMLCh* asString(const DynamicContext* context) const = 0;
00051
00052
00053 virtual Numeric::Ptr promoteTypeIfApplicable(AnyAtomicType::AtomicObjectType typeIndex,
00054 const DynamicContext* context) const = 0;
00055
00056
00057
00058 virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const;
00059
00061 virtual bool lessThan(const Numeric::Ptr &other, const DynamicContext* context) const;
00062
00064 virtual bool greaterThan(const Numeric::Ptr &other, const DynamicContext* context) const;
00065
00068 virtual int compare(const Numeric::Ptr &other, const DynamicContext *context) const;
00069
00071 virtual Numeric::Ptr add(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00072
00075 virtual Numeric::Ptr subtract(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00076
00078 virtual Numeric::Ptr multiply(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00079
00081 virtual Numeric::Ptr divide(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00082
00084 virtual Numeric::Ptr mod(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00085
00087 virtual Numeric::Ptr floor(const DynamicContext* context) const = 0;
00088
00090 virtual Numeric::Ptr ceiling(const DynamicContext* context) const = 0;
00091
00093 virtual Numeric::Ptr round(const DynamicContext* context) const = 0;
00094
00096 virtual Numeric::Ptr roundHalfToEven(const Numeric::Ptr &precision, const DynamicContext* context) const = 0;
00097
00099 virtual Numeric::Ptr invert(const DynamicContext* context) const = 0;
00100
00102 virtual Numeric::Ptr abs(const DynamicContext* context) const = 0;
00103
00105 virtual Numeric::Ptr sqrt(const DynamicContext* context) const = 0;
00106
00108 virtual Numeric::Ptr sin(const DynamicContext* context) const = 0;
00109
00111 virtual Numeric::Ptr cos(const DynamicContext* context) const = 0;
00112
00114 virtual Numeric::Ptr tan(const DynamicContext* context) const = 0;
00115
00117 virtual Numeric::Ptr asin(const DynamicContext* context) const = 0;
00118
00120 virtual Numeric::Ptr acos(const DynamicContext* context) const = 0;
00121
00123 virtual Numeric::Ptr atan(const DynamicContext* context) const = 0;
00124
00126 virtual Numeric::Ptr log(const DynamicContext* context) const = 0;
00127
00129 virtual Numeric::Ptr exp(const DynamicContext* context) const = 0;
00130
00132 virtual Numeric::Ptr power(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00133
00134
00136 virtual bool isZero() const = 0;
00137
00139 virtual bool isPositive() const = 0;
00140
00142 virtual bool isNegative() const = 0;
00143
00144
00145 virtual bool isNaN() const = 0;
00146
00147
00148 virtual bool isInfinite() const = 0;
00149
00150
00151 virtual bool isInteger() const;
00152
00153 virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const = 0;
00154
00155 virtual const MAPM &asMAPM() const = 0;
00156 virtual double asDouble() const;
00157 virtual int asInt() const;
00158
00159 enum State {
00160 NEG_INF = 0,
00161 NEG_NUM = 1,
00162 NUM = 2,
00163 INF = 3,
00164 NaN = 4
00165 };
00166
00167 virtual State getState() const = 0;
00168
00169 static const XMLCh NaN_string[];
00170 static const XMLCh NAN_string[];
00171 static const XMLCh INF_string[];
00172 static const XMLCh NegINF_string[];
00173 static const XMLCh NegZero_string[];
00174 static const XMLCh PosZero_string[];
00175
00176 static void checkFloatLimits(Numeric::State &state, MAPM &value);
00177 static void checkDoubleLimits(Numeric::State &state, MAPM &value);
00178
00179 static const XMLCh *asDecimalString(const MAPM &value, int significantDigits, const StaticContext* context);
00180 static const XMLCh *asDoubleString(State state, const MAPM &value, int significantDigits, const StaticContext* context);
00181
00182 protected:
00183 virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
00184 const XMLCh* targetType, const DynamicContext* context) const;
00185
00186 const XMLCh *asDecimalString(int significantDigits, const StaticContext* context) const;
00187 const XMLCh *asDoubleString(int significantDigits, const StaticContext* context) const;
00188
00189 };
00190
00191 #endif // __NUMERIC_HPP