SourceForge.net Logo

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.13 2007/02/07 12:13:11 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(AnyAtomicType::AtomicObjectType typeIndex,
00048                                                const DynamicContext* context) const = 0;
00049   
00050   /* returns true if the two Numeric values are equal 
00051    * false otherwise */
00052   virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const;
00053 
00055   virtual bool lessThan(const Numeric::Ptr &other, const DynamicContext* context) const;
00056 
00058   virtual bool greaterThan(const Numeric::Ptr &other, const DynamicContext* context) const;
00059 
00062   virtual int compare(const Numeric::Ptr &other, const DynamicContext *context) const;
00063 
00065   virtual Numeric::Ptr add(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00066 
00069   virtual Numeric::Ptr subtract(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00070 
00072   virtual Numeric::Ptr multiply(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00073 
00075   virtual Numeric::Ptr divide(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00076 
00078   virtual Numeric::Ptr mod(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
00079   
00081   virtual Numeric::Ptr floor(const DynamicContext* context) const = 0;
00082 
00084   virtual Numeric::Ptr ceiling(const DynamicContext* context) const = 0;
00085 
00087   virtual Numeric::Ptr round(const DynamicContext* context) const = 0;
00088 
00090   virtual Numeric::Ptr roundHalfToEven(const Numeric::Ptr &precision, const DynamicContext* context) const = 0;
00091 
00093   virtual Numeric::Ptr invert(const DynamicContext* context) const = 0;
00094 
00096   virtual bool isZero() const = 0;
00097 
00099   virtual bool isPositive() const = 0;
00100 
00102   virtual bool isNegative() const = 0;
00103 
00104   /* Is this floating point value not a number? */
00105   virtual bool isNaN() const = 0;
00106 
00107   /* Is this floating point value infinite? */
00108   virtual bool isInfinite() const = 0;
00109 
00110   virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const = 0;
00111 
00112   virtual const MAPM &asMAPM() const = 0;
00113 
00114   enum State {
00115     NEG_INF = 0,
00116     NEG_NUM = 1,
00117     NUM = 2,
00118     INF = 3,
00119     NaN = 4
00120   };
00121 
00122   virtual State getState() const = 0;
00123 
00124   static const XMLCh NaN_string[];
00125   static const XMLCh NAN_string[];
00126   static const XMLCh INF_string[];
00127   static const XMLCh NegINF_string[];
00128   static const XMLCh NegZero_string[];
00129   static const XMLCh PosZero_string[];
00130 
00131   static void checkFloatLimits(Numeric::State &state, MAPM &value);
00132   static void checkDoubleLimits(Numeric::State &state, MAPM &value);
00133 
00134   static const XMLCh *asDecimalString(const MAPM &value, int significantDigits, const StaticContext* context);
00135   static const XMLCh *asDoubleString(State state, const MAPM &value, int significantDigits, const StaticContext* context);
00136 
00137 protected:
00138   virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
00139                                             const XMLCh* targetType, const DynamicContext* context) const;
00140 
00141   const XMLCh *asDecimalString(int significantDigits, const StaticContext* context) const;
00142   const XMLCh *asDoubleString(int significantDigits, const StaticContext* context) const;
00143   
00144 };
00145 
00146 #endif //  __NUMERIC_HPP

Generated on Fri Aug 31 14:37:35 2007 for XQilla Simple API by  doxygen 1.5.1