SourceForge.net Logo
Numeric.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2008
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004-2008
5  * Oracle. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * $Id$
20  */
21 
22 #ifndef __NUMERIC_HPP
23 #define __NUMERIC_HPP
24 
25 #include <xercesc/util/XercesDefs.hpp>
26 #include <xqilla/framework/XQillaExport.hpp>
28 
29 class DynamicContext;
30 class StaticContext;
31 class MAPM;
32 
33 class XQILLA_API Numeric : public AnyAtomicType
34 {
35 public:
37 
38  /* is this type numeric? Return true */
39  virtual bool isNumericValue() const { return true; };
40 
41  /* Get the name of the primitive type (basic type) of this type
42  * (ie "decimal" for xs:decimal) */
43  virtual const XMLCh* getPrimitiveTypeName() const = 0;
44 
45  /* Get the namespace URI for this type */
46  virtual const XMLCh* getTypeURI() const = 0;
47 
48  /* Get the name of this type (ie "integer" for xs:integer) */
49  virtual const XMLCh* getTypeName() const = 0;
50 
51  /* returns the XMLCh* (canonical) representation of this type */
52  virtual const XMLCh* asString(const DynamicContext* context) const = 0;
53 
54  /* Promote this to the given type, if possible */
55  virtual Numeric::Ptr promoteTypeIfApplicable(AnyAtomicType::AtomicObjectType typeIndex,
56  const DynamicContext* context) const = 0;
57 
58  /* returns true if the two Numeric values are equal
59  * false otherwise */
60  virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const;
61 
63  virtual bool lessThan(const Numeric::Ptr &other, const DynamicContext* context) const;
64 
66  virtual bool greaterThan(const Numeric::Ptr &other, const DynamicContext* context) const;
67 
70  virtual int compare(const Numeric::Ptr &other, const DynamicContext *context) const;
71 
73  virtual Numeric::Ptr add(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
74 
77  virtual Numeric::Ptr subtract(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
78 
80  virtual Numeric::Ptr multiply(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
81 
83  virtual Numeric::Ptr divide(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
84 
86  virtual Numeric::Ptr mod(const Numeric::Ptr &other, const DynamicContext* context) const = 0;
87 
89  virtual Numeric::Ptr floor(const DynamicContext* context) const = 0;
90 
92  virtual Numeric::Ptr ceiling(const DynamicContext* context) const = 0;
93 
95  virtual Numeric::Ptr round(const DynamicContext* context) const = 0;
96 
98  virtual Numeric::Ptr roundHalfToEven(const Numeric::Ptr &precision, const DynamicContext* context) const = 0;
99 
101  virtual Numeric::Ptr invert(const DynamicContext* context) const = 0;
102 
104  virtual bool isZero() const = 0;
105 
107  virtual bool isPositive() const = 0;
108 
110  virtual bool isNegative() const = 0;
111 
112  /* Is this floating point value not a number? */
113  virtual bool isNaN() const = 0;
114 
115  /* Is this floating point value infinite? */
116  virtual bool isInfinite() const = 0;
117 
119 
120  virtual const MAPM &asMAPM() const = 0;
121  virtual double asDouble() const;
122  virtual int asInt() const;
123 
124  enum State {
125  NEG_INF = 0,
126  NEG_NUM = 1,
127  NUM = 2,
128  INF = 3,
129  NaN = 4
130  };
131 
132  virtual State getState() const = 0;
133 
134  static const XMLCh NaN_string[];
135  static const XMLCh NAN_string[];
136  static const XMLCh INF_string[];
137  static const XMLCh NegINF_string[];
138  static const XMLCh NegZero_string[];
139  static const XMLCh PosZero_string[];
140 
141  static void checkFloatLimits(Numeric::State &state, MAPM &value);
142  static void checkDoubleLimits(Numeric::State &state, MAPM &value);
143 
144  static const XMLCh *asDecimalString(const MAPM &value, int significantDigits, const StaticContext* context);
145  static const XMLCh *asDoubleString(State state, const MAPM &value, int significantDigits, const StaticContext* context);
146 
147 protected:
148  virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
149  const XMLCh* targetType, const DynamicContext* context) const;
150 
151  const XMLCh *asDecimalString(int significantDigits, const StaticContext* context) const;
152  const XMLCh *asDoubleString(int significantDigits, const StaticContext* context) const;
153 
154 };
155 
156 #endif // __NUMERIC_HPP