#include "../../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include "ATBooleanOrDerivedImpl.hpp" #include #include #include #include #include #include #include #include "../../exceptions/XPath2TypeCastException.hpp" #include "../../exceptions/InvalidLexicalSpaceException.hpp" #include #include #include // defines X() and XMLCh* #include #include #include #include ATBooleanOrDerivedImpl:: ATBooleanOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const XMLCh* value, XPath2MemoryManager* memMgr, const DynamicContext* context): ATBooleanOrDerived(memMgr), _typeName(typeName), _typeURI(typeURI) { // canonical value "0" static const XMLCh zero[] = {XERCES_CPP_NAMESPACE_QUALIFIER chDigit_0, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; if( XERCES_CPP_NAMESPACE_QUALIFIER XMLString::equals(value, zero) || XERCES_CPP_NAMESPACE_QUALIFIER XMLString::equals(value, XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgATTVAL_FALSE)) { _value = false; } else { _value = true; } } ATBooleanOrDerivedImpl:: ATBooleanOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, bool value, XPath2MemoryManager* memMgr, const DynamicContext* context): ATBooleanOrDerived(memMgr), _value(value), _typeName(typeName), _typeURI(typeURI) { } /* Get the name of the primitive type (basic type) of this type * (ie "decimal" for xs:decimal) */ const XMLCh* ATBooleanOrDerivedImpl::getPrimitiveTypeName() const { return this->getPrimitiveName(); } const XMLCh* ATBooleanOrDerivedImpl::getPrimitiveName() { return XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgDT_BOOLEAN; } /* Get the name of this type (ie "integer" for xs:integer) */ const XMLCh* ATBooleanOrDerivedImpl::getTypeName() const { return _typeName; } /* Get the namespace URI for this type */ const XMLCh* ATBooleanOrDerivedImpl::getTypeURI() const { return _typeURI; } AnyAtomicType::AtomicObjectType ATBooleanOrDerivedImpl::getTypeIndex() { return AnyAtomicType::BOOLEAN; } /* If possible, cast this type to the target type */ const AnyAtomicType* ATBooleanOrDerivedImpl::castAsInternal(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const { const DatatypeFactory* target = context->getDatatypeFactory(targetURI, targetType); AnyAtomicType::AtomicObjectType targetIndex = target->getPrimitiveTypeIndex(); // deviation from spec -- they say to convert to 1.0 and 0.0, but we don't see the point, // and it doesn't make casting to integer a special case (crioux) const XMLCh one[] = { XERCES_CPP_NAMESPACE_QUALIFIER chDigit_1, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; const XMLCh zero[] = { XERCES_CPP_NAMESPACE_QUALIFIER chDigit_0, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; const XMLCh* chValue = _value ? one : zero; switch(targetIndex) { case FLOAT: { return DatatypeFactory::STR2AT::createFloatOrDerived(context->getMemoryManager(), targetURI, targetType, chValue, context); } case DECIMAL: { return DatatypeFactory::STR2AT::createDecimalOrDerived(context->getMemoryManager(), targetURI, targetType, chValue, context); } case DOUBLE: { return DatatypeFactory::STR2AT::createDoubleOrDerived(context->getMemoryManager(), targetURI, targetType, chValue, context); } default: return AnyAtomicType::castAsInternal(targetURI, targetType, context); } } /* returns the XMLCh* (canonical) representation of this type */ const XMLCh* ATBooleanOrDerivedImpl::asString(const DynamicContext* context) const { if(_value) { return XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgATTVAL_TRUE; } else { return XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgATTVAL_FALSE; } } /* returns true if the two objects have the same boolean value * false otherwise */ bool ATBooleanOrDerivedImpl::equals(const AnyAtomicType* target, const DynamicContext* context) const { if(this->getPrimitiveTypeIndex() != target->getPrimitiveTypeIndex()) { DSLthrow(IllegalArgumentException,X("ATBooleanOrDerivedImpl::equals"), X("Equality operator for given types not supported")); } return _value == ((ATBooleanOrDerivedImpl*)target)->_value; } /* returns true if 'this' is true and 'other' is false, otherwise * returns false */ bool ATBooleanOrDerivedImpl::greaterThan(const ATBooleanOrDerived* other, const DynamicContext* context) const { if(this->isTrue() && other->isFalse()) { return true; } return false; } /* returns true if 'other' is true and 'this' is false, otherwise * returns false */ bool ATBooleanOrDerivedImpl::lessThan(const ATBooleanOrDerived* other, const DynamicContext* context) const { if(this->isFalse() && other->isTrue()) { return true; } return false; } /* returns true if boolean value evaluates to true * false otherwise */ bool ATBooleanOrDerivedImpl::isTrue() const { return _value; } /* returns false if boolean value evaluates to true * true otherwise */ bool ATBooleanOrDerivedImpl::isFalse() const { return !isTrue(); } AnyAtomicType::AtomicObjectType ATBooleanOrDerivedImpl::getPrimitiveTypeIndex() const { return getTypeIndex(); } /** Releases the memory used by this Item */ void ATBooleanOrDerivedImpl::release() const { //TODO needs to check for ownership before releasing! getMemoryManager()->deallocate((void*)this); }