/* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #ifndef _ATDECIMALORDERIVEDIMPL_HPP #define _ATDECIMALORDERIVEDIMPL_HPP #include #include #include #include #define DECIMAL_MAX_DIGITS 50 class PATHAN_EXPORT ATDecimalOrDerivedImpl : public ATDecimalOrDerived { public: /** Releases the memory used by this Item */ virtual void release() const; /* constructor */ ATDecimalOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const XMLCh* value, XPath2MemoryManager* memMgr, const DynamicContext* context); /* constructor */ ATDecimalOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const MAPM value, XPath2MemoryManager* memMgr, const DynamicContext* context); /** destructor -- do nothing*/ virtual ~ATDecimalOrDerivedImpl() { }; /* Get the name of the primitive type (basic type) of this type * (ie "decimal" for xs:decimal) */ virtual const XMLCh* getPrimitiveTypeName() const; /* Get the namespace URI for this type */ virtual const XMLCh* getTypeURI() const; /* Get the name of this type (ie "integer" for xs:integer) */ virtual const XMLCh* getTypeName() const; /* returns the XMLCh* (canonical) representation of this type */ virtual const XMLCh* asString(const DynamicContext* context) const; /* returns an XMLCh* representation of this Numeric with precision signinficant digits */ virtual const XMLCh* asString(int precision, const DynamicContext* context) const; /* Promote this to the given type, if possible */ virtual const Numeric* promoteTypeIfApplicable(const XMLCh* typeURI, const XMLCh* typeName, const DynamicContext* context) const; /* returns true if the two objects' decimal values are equal * false otherwise */ virtual bool equals(const AnyAtomicType* target, const DynamicContext* context) const; /** Returns true if this is less than other, false otherwise */ virtual bool lessThan(const Numeric* other, const DynamicContext* context) const; /** Returns true if this is greater than other, false otherwise */ virtual bool greaterThan(const Numeric* other, const DynamicContext* context) const; /** Returns a Numeric object which is the sum of this and other */ virtual const Numeric* add(const Numeric* other, const DynamicContext* context) const; /** Returns a Numeric object which is the difference of this and * other */ virtual const Numeric* subtract(const Numeric* other, const DynamicContext* context) const; /** Returns a Numeric object which is the product of this and other */ virtual const Numeric* multiply(const Numeric* other, const DynamicContext* context) const; /** Returns a Numeric object which is the quotient of this and other */ virtual const Numeric* divide(const Numeric* other, const DynamicContext* context) const; /** Returns a ATDecimalOrDerived (integer) object which is the quotient of this and other */ virtual const ATDecimalOrDerived* integerDivide(const ATDecimalOrDerived* other, const DynamicContext* context) const; /** Returns the arithmetic product of its operands as a Numeric */ virtual const Numeric* mod(const Numeric* other, const DynamicContext* context) const; /** Returns the floor of this Numeric */ virtual const Numeric* floor(const DynamicContext* context) const; /** Returns the ceiling of this Numeric */ virtual const Numeric* ceiling(const DynamicContext* context) const; /** Rounds this Numeric */ virtual const Numeric* round(const DynamicContext* context) const; /** Rounds this Numeric to the given precision, and rounds a half to even */ virtual const Numeric* roundHalfToEven(const ATDecimalOrDerived* &precision, const DynamicContext* context) const; /** Returns the Additive inverse of this Numeric */ virtual const Numeric* invert(const DynamicContext* context) const; /** Returns the absolute value of this Numeric */ virtual const Numeric* abs(const DynamicContext* context) const; /** Does this Numeric have value 0? */ virtual bool isZero() const; /** Is this Numeric negative? */ virtual bool isNegative() const; /** Is this Numeric positive? */ virtual bool isPositive() const; /** Treat this decimal (must be integer) as a codepoint **/ virtual XMLCh treatAsCodepoint(const DynamicContext* context) const; /* Get the primitive index associated with this type */ static AnyAtomicType::AtomicObjectType getTypeIndex(); /* Get the primitive type name */ static const XMLCh* getPrimitiveName(); /* Get the primitive index associated with this type */ virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const; protected: ////////////////////////////////////// // Horrible Hack to make Dates // // work for now. Loss of Precision! // ////////////////////////////////////// virtual MAPM asMAPM() const; /* If possible, cast this type to the target type */ virtual const AnyAtomicType* castAsInternal(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const; private: /* set the value of this decimal */ void setDecimal(const XMLCh* const value); /* flag to note that we are an Integer -- to avoid many calls to * isInstanceOfType */ bool _isInteger; /*The value of this decimal*/ MAPM _decimal; /* the name of this type */ const XMLCh* _typeName; /* the uri of this type */ const XMLCh* _typeURI; }; #endif // _ATDECIMALORDERIVEDIMPL_HPP