# XQilla Simple API Documentation

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# 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, 2015 Oracle and/or its affiliates. All rights reserved.
    00005  *
    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
    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   /* is this type numeric?  Return true */
    00037   virtual bool isNumericValue() const { return true; };
    00038
    00039   /* Get the name of the primitive type (basic type) of this type
    00040    * (ie "decimal" for xs:decimal) */
    00041   virtual const XMLCh* getPrimitiveTypeName() const = 0;
    00042
    00043   /* Get the namespace URI for this type */
    00044   virtual const XMLCh* getTypeURI() const = 0;
    00045
    00046   /* Get the name of this type  (ie "integer" for xs:integer) */
    00047   virtual const XMLCh* getTypeName() const = 0;
    00048
    00049   /* returns the XMLCh* (canonical) representation of this type */
    00050   virtual const XMLCh* asString(const DynamicContext* context) const = 0;
    00051
    00052   /* Promote this to the given type, if possible */
    00053   virtual Numeric::Ptr promoteTypeIfApplicable(AnyAtomicType::AtomicObjectType typeIndex,
    00054                                                const DynamicContext* context) const = 0;
    00055
    00056   /* returns true if the two Numeric values are equal
    00057    * false otherwise */
    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   /* Is this floating point value not a number? */
    00145   virtual bool isNaN() const = 0;
    00146
    00147   /* Is this floating point value infinite? */
    00148   virtual bool isInfinite() const = 0;
    00149
    00150   /* Is this floating point value infinite? */
    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