SourceForge.net Logo

Numeric.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2008
00003  *     DecisionSoft Limited. All rights reserved.
00004  * Copyright (c) 2004-2008
00005  *     Oracle. All rights reserved.
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  *
00019  * $Id: Numeric.hpp,v 1.15 2008/01/08 18:47:32 jpcs Exp $
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   /* is this type numeric?  Return true */
00039   virtual bool isNumericValue() const { return true; };
00040 
00041   /* Get the name of the primitive type (basic type) of this type
00042    * (ie "decimal" for xs:decimal) */
00043   virtual const XMLCh* getPrimitiveTypeName() const = 0;
00044 
00045   /* Get the namespace URI for this type */
00046   virtual const XMLCh* getTypeURI() const = 0;
00047 
00048   /* Get the name of this type  (ie "integer" for xs:integer) */
00049   virtual const XMLCh* getTypeName() const = 0;
00050 
00051   /* returns the XMLCh* (canonical) representation of this type */
00052   virtual const XMLCh* asString(const DynamicContext* context) const = 0;
00053 
00054   /* Promote this to the given type, if possible */
00055   virtual Numeric::Ptr promoteTypeIfApplicable(AnyAtomicType::AtomicObjectType typeIndex,
00056                                                const DynamicContext* context) const = 0;
00057   
00058   /* returns true if the two Numeric values are equal 
00059    * false otherwise */
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   /* Is this floating point value not a number? */
00113   virtual bool isNaN() const = 0;
00114 
00115   /* Is this floating point value infinite? */
00116   virtual bool isInfinite() const = 0;
00117 
00118   virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const = 0;
00119 
00120   virtual const MAPM &asMAPM() const = 0;
00121 
00122   enum State {
00123     NEG_INF = 0,
00124     NEG_NUM = 1,
00125     NUM = 2,
00126     INF = 3,
00127     NaN = 4
00128   };
00129 
00130   virtual State getState() const = 0;
00131 
00132   static const XMLCh NaN_string[];
00133   static const XMLCh NAN_string[];
00134   static const XMLCh INF_string[];
00135   static const XMLCh NegINF_string[];
00136   static const XMLCh NegZero_string[];
00137   static const XMLCh PosZero_string[];
00138 
00139   static void checkFloatLimits(Numeric::State &state, MAPM &value);
00140   static void checkDoubleLimits(Numeric::State &state, MAPM &value);
00141 
00142   static const XMLCh *asDecimalString(const MAPM &value, int significantDigits, const StaticContext* context);
00143   static const XMLCh *asDoubleString(State state, const MAPM &value, int significantDigits, const StaticContext* context);
00144 
00145 protected:
00146   virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
00147                                             const XMLCh* targetType, const DynamicContext* context) const;
00148 
00149   const XMLCh *asDecimalString(int significantDigits, const StaticContext* context) const;
00150   const XMLCh *asDoubleString(int significantDigits, const StaticContext* context) const;
00151   
00152 };
00153 
00154 #endif //  __NUMERIC_HPP

Generated on Tue Apr 8 14:29:40 2008 for XQilla Simple API by  doxygen 1.5.1