floatdatatypevalidator.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 331 行

CPP
331
字号
/* * 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: FloatDatatypeValidator.cpp,v 1.15 2004/09/08 13:56:53 peiyongz Exp $ * $Log: FloatDatatypeValidator.cpp,v $ * Revision 1.15  2004/09/08 13:56:53  peiyongz * Apache License Version 2.0 * * Revision 1.14  2004/01/13 20:57:06  peiyongz * revert code back to previous version * * Revision 1.11  2003/12/19 23:02:25  cargilld * More memory management updates. * * Revision 1.10  2003/12/17 00:18:39  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/26 20:42:16  peiyongz * FloatDatatypeValidator * * */// ---------------------------------------------------------------------------//  Includes// ---------------------------------------------------------------------------#include <xercesc/validators/datatype/FloatDatatypeValidator.hpp>#include <xercesc/validators/schema/SchemaSymbols.hpp>#include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>#include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------//  Constructors and Destructor// ---------------------------------------------------------------------------FloatDatatypeValidator::FloatDatatypeValidator(MemoryManager* const manager):AbstractNumericValidator(0, 0, 0, DatatypeValidator::Float, manager){    setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL);    setBounded(true);    setFinite(true);    setNumeric(true);}FloatDatatypeValidator::FloatDatatypeValidator(                          DatatypeValidator*            const baseValidator                        , RefHashTableOf<KVStringPair>* const facets                        , RefArrayVectorOf<XMLCh>*      const enums                        , const int                           finalSet                        , MemoryManager* const                manager):AbstractNumericValidator(baseValidator, facets, finalSet, DatatypeValidator::Float, manager){    init(enums, manager);}FloatDatatypeValidator::~FloatDatatypeValidator(){}// -----------------------------------------------------------------------// Compare methods// -----------------------------------------------------------------------int FloatDatatypeValidator::compare(const XMLCh* const lValue                                  , const XMLCh* const rValue                                  , MemoryManager* const manager){    XMLFloat lObj(lValue, manager);    XMLFloat rObj(rValue, manager);    return compareValues(&lObj, &rObj);}DatatypeValidator* FloatDatatypeValidator::newInstance(      RefHashTableOf<KVStringPair>* const facets    , RefArrayVectorOf<XMLCh>* const      enums    , const int                           finalSet    , MemoryManager* const                manager){    return (DatatypeValidator*) new (manager) FloatDatatypeValidator(this, facets, enums, finalSet, manager);}// -----------------------------------------------------------------------// ctor provided to be used by derived classes// -----------------------------------------------------------------------FloatDatatypeValidator::FloatDatatypeValidator(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  FloatDatatypeValidator::compareValues(const XMLNumber* const lValue                                         , const XMLNumber* const rValue){    return XMLFloat::compareValues((XMLFloat*) lValue, (XMLFloat*) rValue);}void  FloatDatatypeValidator::setMaxInclusive(const XMLCh* const value){    fMaxInclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager);}void  FloatDatatypeValidator::setMaxExclusive(const XMLCh* const value){    fMaxExclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager);}void  FloatDatatypeValidator::setMinInclusive(const XMLCh* const value){    fMinInclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager);}void  FloatDatatypeValidator::setMinExclusive(const XMLCh* const value){    fMinExclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager);}void  FloatDatatypeValidator::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();    FloatDatatypeValidator *numBase = (FloatDatatypeValidator*) 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 (fMemoryManager) RefVectorOf<XMLNumber>(enumLength, true,  fMemoryManager);    fEnumerationInherited = false;    for ( i = 0; i < enumLength; i++)    {        fEnumeration->insertElementAt(new (fMemoryManager) XMLFloat(fStrEnumeration->elementAt(i), fMemoryManager), i);    }}// -----------------------------------------------------------------------// Abstract interface from AbstractNumericValidator// -----------------------------------------------------------------------void FloatDatatypeValidator::checkContent(const XMLCh*             const content                                         ,      ValidationContext* const context                                         ,      bool                     asBase                                         ,      MemoryManager*     const manager){    //validate against base validator if any    FloatDatatypeValidator *pBase = (FloatDatatypeValidator*) 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 {        XMLFloat theValue(content, manager);        XMLFloat *theData = &theValue;        if (getEnumeration() != 0)        {            int i=0;            int enumLength = getEnumeration()->size();            for ( ; i < enumLength; i++)            {                if (compareValues(theData, (XMLFloat*) 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(FloatDatatypeValidator)void FloatDatatypeValidator::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::Float);    }    AbstractNumericValidator::serialize(serEng);}XERCES_CPP_NAMESPACE_END/**  * End of file FloatDatatypeValidator::cpp  */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?