/* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #ifndef _ATDURATIONORDERIVEDIMPL_HPP #define _ATDURATIONORDERIVEDIMPL_HPP #include #include class AnyAtomicType; class ATDecimalOrDerived; class XPath2MemoryManager; class MAPM; class PATHAN_EXPORT ATDurationOrDerivedImpl : public ATDurationOrDerived { public: /* constructor */ ATDurationOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const XMLCh* value, XPath2MemoryManager* memMgr, const DynamicContext* context); /* 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 true if this duration is an instance of a xdt:dayTimeDuration */ virtual bool isDayTimeDuration() const; /* returns true if this duration is an instance of a xdt:yearMonthDuration */ virtual bool isYearMonthDuration() const; /* returns true if the two objects have the same duration * false otherwise */ virtual bool equals(const AnyAtomicType* target, const DynamicContext* context) const; /** greaterThan -- only defined for fn:dayTimeDuration and fn:yearMonthDuration */ virtual bool greaterThan(const ATDurationOrDerived* other, const DynamicContext* context) const; /** lessThan -- only defined for fn:dayTimeDuration and fn:yearMonthDuration */ virtual bool lessThan(const ATDurationOrDerived* other, const DynamicContext* context) const; /** Divide this duration by a number -- only available for xdt:dayTimeDuration * and xdt:yearMonthDuration */ virtual const ATDurationOrDerived* divide(const ATDecimalOrDerived* divisor, const DynamicContext* context) const; /** Multiply this duration by a number -- only available for xdt:dayTimeDuration * and xdt:yearMonthDuration */ virtual const ATDurationOrDerived* multiply(const ATDecimalOrDerived* multiplier, const DynamicContext* context) const; /** Add a duration to this duration -- only available for xdt:dayTimeDuration * and xdt:yearMonthDuration */ virtual const ATDurationOrDerived* add(const ATDurationOrDerived* other, const DynamicContext* context) const; /** Subtract a duration from this duration -- only available for xdt:dayTimeDuration * and xdt:yearMonthDuration */ virtual const ATDurationOrDerived* subtract(const ATDurationOrDerived* other, const DynamicContext* context) const; /** Returns the year portion of this duration */ virtual const ATDecimalOrDerived* getYears() const; /** Returns the month portion of this duration */ virtual const ATDecimalOrDerived* getMonths() const; /** Returns the days portion of this duration */ virtual const ATDecimalOrDerived* getDays() const; /** Returns the hours portion of this duration */ virtual const ATDecimalOrDerived* getHours() const; /** Returns the minutes portion of this duration */ virtual const ATDecimalOrDerived* getMinutes() const; /** Returns the seconds portion of this duration */ virtual const ATDecimalOrDerived* getSeconds() const; /** normalize this duration (only available for xdt:dayTimeDuration and * xdt:yearMonthDuration **/ virtual const ATDurationOrDerived* normalize(const DynamicContext* context) const; /** Returns true if this Duration is negative, false otherwise */ virtual bool isNegative() const; /* Get the primitive index associated with this type */ static AnyAtomicType::AtomicObjectType getTypeIndex(); /* Get the primitive type name */ static const XMLCh* getPrimitiveName(); /** Releases the memory used by this Item */ virtual void release() const; virtual AnyAtomicType::AtomicObjectType getPrimitiveTypeIndex() const; protected: /* If possible, cast this type to the target type */ virtual const AnyAtomicType* castAsInternal(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const; private: // private constructor ATDurationOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const ATDecimalOrDerived* year,const ATDecimalOrDerived* month, const ATDecimalOrDerived* day, const ATDecimalOrDerived* hour, const ATDecimalOrDerived* minute, const ATDecimalOrDerived* sec, bool isPositive, XPath2MemoryManager* memMgr, const DynamicContext* context); /** Compare two dayTimeDurations, return true if this < other */ bool dayTimeLessThan(const ATDurationOrDerived* dayTimeDuration, const DynamicContext* context) const; /** Compare two dayTimeDurations, return true if this > other */ bool dayTimeGreaterThan(const ATDurationOrDerived* dayTimeDuration, const DynamicContext* context) const; /** Compare two yearMonthDurations, return true if this < other */ bool yearMonthLessThan(const ATDurationOrDerived* yearMonthDuration, const DynamicContext* context) const; /** Compare two yearMonthDurations, return true if this > other */ bool yearMonthGreaterThan(const ATDurationOrDerived* yearMonthDuration, const DynamicContext* context) const; /* Divide a xdt:dayTimeDuration by a xs:decimal */ const ATDurationOrDerived* dayTimeDivide(const ATDecimalOrDerived* divisor, const DynamicContext* context) const; /* Divide a xdt:yearMonthDuration by an xs:decimal */ const ATDurationOrDerived* yearMonthDivide(MAPM divisor, const DynamicContext* context) const; /* normalize xdt:dayTimeDurations */ const ATDurationOrDerived* normalizeDayTimeDuration(const DynamicContext* context) const; /* normalize xdt:yearMonthDurations */ const ATDurationOrDerived* normalizeYearMonthDuration(const DynamicContext* context) const; /* return this duration in forms of seconds */ const ATDecimalOrDerived* asSeconds(const DynamicContext* context) const; /*The values that make up this duration */ bool _isPositive; const ATDecimalOrDerived* _year; // xs:nonNegativeIngeter const ATDecimalOrDerived* _month; // xs:nonNegativeIngeter const ATDecimalOrDerived* _day; // xs:nonNegativeIngeter const ATDecimalOrDerived* _hour; // xs:nonNegativeIngeter const ATDecimalOrDerived* _minute;// xs:nonNegativeIngeter const ATDecimalOrDerived* _sec; // xs:decimal enum DurationType { DAY_TIME_DURATION, YEAR_MONTH_DURATION, DURATION }; DurationType durationType; /* the name of this type */ const XMLCh* _typeName; /* the uri of this type */ const XMLCh* _typeURI; void setDuration(const XMLCh* const value, const DynamicContext* context); }; #endif // _ATDURATIONORDERIVEDIMPL_HPP