doubledatatypevalidator.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 328 行
CPP
328 行
/* * Copyright 2001,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: DoubleDatatypeValidator.cpp,v 1.14 2004/09/08 13:56:52 peiyongz Exp $ * $Log: DoubleDatatypeValidator.cpp,v $ * Revision 1.14 2004/09/08 13:56:52 peiyongz * Apache License Version 2.0 * * Revision 1.13 2004/01/13 20:57:06 peiyongz * revert code back to previous version * * Revision 1.10 2003/12/17 00:18:38 cargilld * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. * * Revision 1.9 2003/11/12 20:32:03 peiyongz * Statless Grammar: ValidationContext * * Revision 1.8 2003/11/06 15:30:07 neilg * first part of PSVI/schema component model implementation, thanks to David Cargill. This covers setting the PSVIHandler on parser objects, as well as implementing XSNotation, XSSimpleTypeDefinition, XSIDCDefinition, and most of XSWildcard, XSComplexTypeDefinition, XSElementDeclaration, XSAttributeDeclaration and XSAttributeUse. * * Revision 1.7 2003/10/02 19:21:06 peiyongz * Implementation of Serialization/Deserialization * * Revision 1.6 2003/05/18 14:02:07 knoaman * Memory manager implementation: pass per instance manager. * * Revision 1.5 2003/05/16 06:01:57 knoaman * Partial implementation of the configurable memory manager. * * Revision 1.4 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * * Revision 1.3 2002/12/18 14:17:55 gareth * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf. * * Revision 1.2 2002/11/04 14:53:28 tng * C++ Namespace Support. * * Revision 1.1.1.1 2002/02/01 22:22:41 peiyongz * sane_include * * Revision 1.6 2001/10/02 18:59:29 peiyongz * Invalid_Facet_Tag to display the tag name * * Revision 1.5 2001/10/01 21:03:55 peiyongz * DTV Reorganization:derived from AbstractNumericValidator * * Revision 1.4 2001/09/20 13:11:42 knoaman * Regx + misc. fixes * * Revision 1.3 2001/08/21 18:42:53 peiyongz * Bugzilla# 2816: cleanUp() declared with external linkage and called * before defined as inline * * Revision 1.2 2001/08/15 18:08:44 peiyongz * Fix to potential leakage in strEnumeration * * Revision 1.1 2001/07/24 13:59:03 peiyongz * DoubleDTV * */// ---------------------------------------------------------------------------// Includes// ---------------------------------------------------------------------------#include <xercesc/validators/datatype/DoubleDatatypeValidator.hpp>#include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>#include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------// Constructors and Destructor// ---------------------------------------------------------------------------DoubleDatatypeValidator::DoubleDatatypeValidator(MemoryManager* const manager):AbstractNumericValidator(0, 0, 0, DatatypeValidator::Double, manager){ setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL); setBounded(true); setFinite(true); setNumeric(true);}DoubleDatatypeValidator::DoubleDatatypeValidator( DatatypeValidator* const baseValidator , RefHashTableOf<KVStringPair>* const facets , RefArrayVectorOf<XMLCh>* const enums , const int finalSet , MemoryManager* const manager):AbstractNumericValidator(baseValidator, facets, finalSet, DatatypeValidator::Double, manager){ init(enums, manager);}DoubleDatatypeValidator::~DoubleDatatypeValidator(){}// -----------------------------------------------------------------------// Compare methods// -----------------------------------------------------------------------int DoubleDatatypeValidator::compare(const XMLCh* const lValue , const XMLCh* const rValue , MemoryManager* const manager){ XMLDouble lObj(lValue, manager); XMLDouble rObj(rValue, manager); return compareValues(&lObj, &rObj);}DatatypeValidator* DoubleDatatypeValidator::newInstance( RefHashTableOf<KVStringPair>* const facets , RefArrayVectorOf<XMLCh>* const enums , const int finalSet , MemoryManager* const manager){ return (DatatypeValidator*) new (manager) DoubleDatatypeValidator(this, facets, enums, finalSet, manager);}// -----------------------------------------------------------------------// ctor provided to be used by derived classes// -----------------------------------------------------------------------DoubleDatatypeValidator::DoubleDatatypeValidator(DatatypeValidator* const baseValidator , RefHashTableOf<KVStringPair>* const facets , const int finalSet , const ValidatorType type , MemoryManager* const manager):AbstractNumericValidator(baseValidator, facets, finalSet, type, manager){ //do not invoke init here !!!}int DoubleDatatypeValidator::compareValues(const XMLNumber* const lValue , const XMLNumber* const rValue){ return XMLDouble::compareValues((XMLDouble*) lValue, (XMLDouble*) rValue);}void DoubleDatatypeValidator::setMaxInclusive(const XMLCh* const value){ fMaxInclusive = new (fMemoryManager) XMLDouble(value, fMemoryManager);}void DoubleDatatypeValidator::setMaxExclusive(const XMLCh* const value){ fMaxExclusive = new (fMemoryManager) XMLDouble(value, fMemoryManager);}void DoubleDatatypeValidator::setMinInclusive(const XMLCh* const value){ fMinInclusive = new (fMemoryManager) XMLDouble(value, fMemoryManager);}void DoubleDatatypeValidator::setMinExclusive(const XMLCh* const value){ fMinExclusive = new (fMemoryManager) XMLDouble(value, fMemoryManager);}void DoubleDatatypeValidator::setEnumeration(MemoryManager* const manager){ // check 4.3.5.c0 must: enumeration values from the value space of base // // 1. shall be from base value space // 2. shall be from current value space as well ( shall go through boundsCheck() ) // if (!fStrEnumeration) return; int i = 0; int enumLength = fStrEnumeration->size(); DoubleDatatypeValidator *numBase = (DoubleDatatypeValidator*) getBaseValidator(); if (numBase) { try { for ( i = 0; i < enumLength; i++) { numBase->checkContent(fStrEnumeration->elementAt(i), (ValidationContext*)0, false, manager); } } catch (XMLException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException , XMLExcepts::FACET_enum_base , fStrEnumeration->elementAt(i) , manager); } } // We put the this->checkContent in a separate loop // to not block original message with in that method. // for ( i = 0; i < enumLength; i++) { checkContent(fStrEnumeration->elementAt(i), (ValidationContext*)0, false, manager); } fEnumeration = new (manager) RefVectorOf<XMLNumber>(enumLength, true, manager); fEnumerationInherited = false; for ( i = 0; i < enumLength; i++) { fEnumeration->insertElementAt(new (manager) XMLDouble(fStrEnumeration->elementAt(i), manager), i); }}// -----------------------------------------------------------------------// Abstract interface from AbstractNumericValidator// -----------------------------------------------------------------------void DoubleDatatypeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager){ //validate against base validator if any DoubleDatatypeValidator *pBase = (DoubleDatatypeValidator*) this->getBaseValidator(); if (pBase) pBase->checkContent(content, context, true, manager); // we check pattern first if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) { // lazy construction if (getRegex() ==0) { try { setRegex(new (fMemoryManager) RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption, fMemoryManager)); } catch (XMLException &e) { ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage(), fMemoryManager); } } if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; try { XMLDouble theValue(content, manager); XMLDouble *theData = &theValue; if (getEnumeration()) { int i=0; int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { if (compareValues(theData, (XMLDouble*) getEnumeration()->elementAt(i)) ==0 ) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } boundsCheck(theData, manager); } catch (XMLException &e) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::RethrowError, e.getMessage(), manager); }}/*** * Support for Serialization/De-serialization ***/IMPL_XSERIALIZABLE_TOCREATE(DoubleDatatypeValidator)void DoubleDatatypeValidator::serialize(XSerializeEngine& serEng){ /*** * Note: * * During storing, we need write the specific number * type info before calling base::serialize(). * * While loading, we do nothing here ***/ if (serEng.isStoring()) { serEng<<(int) (XMLNumber::Double); } AbstractNumericValidator::serialize(serEng);}XERCES_CPP_NAMESPACE_END/** * End of file DoubleDatatypeValidator::cpp */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?