abstractnumericfacetvalidator.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,053 行 · 第 1/3 页

CPP
1,053
字号
            }        }    }    // check 4.3.10.c2 error:    // minInclusive < base.minInclusive   minInclusive != base.minInclusive if (base.fixed)    // minInclusive > base.maxInclusive    // minInclusive <= base.minExclusive    // minInclusive >= base.maxExclusive    if ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)    {        if ((baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0)        {            int result = compareValues(thisMinInclusive, baseMinInclusive);            if (((baseFixed & DatatypeValidator::FACET_MININCLUSIVE) != 0) &&                 (result != 0 ))            {                REPORT_FACET_ERROR(thisMinInclusive                                 , baseMinInclusive                                 , XMLExcepts::FACET_minIncl_base_fixed                                 , manager)            }            if (result == -1 || result == INDETERMINATE)            {                REPORT_FACET_ERROR(thisMinInclusive                                 , baseMinInclusive                                 , XMLExcepts::FACET_minIncl_base_minIncl                                 , manager)            }        }        if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0)        {            int result = compareValues(thisMinInclusive, baseMaxInclusive);            if (result == 1 || result == INDETERMINATE)            {                REPORT_FACET_ERROR(thisMinInclusive                                 , baseMaxInclusive                                 , XMLExcepts::FACET_minIncl_base_maxIncl                                 , manager)            }        }        if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0)        {            int result = compareValues(thisMinInclusive, baseMinExclusive);            if (result != 1)            {                REPORT_FACET_ERROR(thisMinInclusive                                 , baseMinExclusive                                 , XMLExcepts::FACET_minIncl_base_minExcl                                 , manager)            }        }        if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0)        {            int result = compareValues(thisMinInclusive, baseMaxExclusive);            if (result != -1)            {                REPORT_FACET_ERROR(thisMinInclusive                                 , baseMaxExclusive                                 , XMLExcepts::FACET_minIncl_base_maxExcl                                 , manager)            }        }    }    checkAdditionalFacetConstraintsBase(manager);    // check 4.3.5.c0 must: enumeration values from the value space of base    //    // In fact, the values in the enumeration shall go through validation    // of this class as well.    // this->checkContent(value, false);    //    if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&        ( fStrEnumeration ))    {        setEnumeration(manager);    }    //    // maxInclusive, maxExclusive, minInclusive and minExclusive    // shall come from the base's value space as well    //    FROM_BASE_VALUE_SPACE(thisMaxInclusive                        , DatatypeValidator::FACET_MAXINCLUSIVE                        , XMLExcepts::FACET_maxIncl_notFromBase                        , manager)    FROM_BASE_VALUE_SPACE(thisMinInclusive                        , DatatypeValidator::FACET_MININCLUSIVE                        , XMLExcepts::FACET_minIncl_notFromBase                        , manager)} //end of inspectFacetBase////  Inherit facet from base//    a. inherit common facets//    b. inherit additional facet//void AbstractNumericFacetValidator::inheritFacet(){    AbstractNumericFacetValidator* numBase = (AbstractNumericFacetValidator*) getBaseValidator();    if (!numBase)        return;    int thisFacetsDefined = getFacetsDefined();    int baseFacetsDefined = numBase->getFacetsDefined();    // inherit enumeration    if ((( baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0))    {        fEnumeration = numBase->fEnumeration;        fEnumerationInherited = true;        setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);    }    // inherit maxInclusive    if ((( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) == 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) == 0) )    {        fMaxInclusive = numBase->getMaxInclusive();        fMaxInclusiveInherited = true;        setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE);    }    // inherit maxExclusive    if ((( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) == 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) == 0) )    {        fMaxExclusive = numBase->getMaxExclusive();        fMaxExclusiveInherited = true;        setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE);    }    // inherit minExclusive    if ((( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) == 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) == 0) )    {        fMinInclusive = numBase->getMinInclusive();        fMinInclusiveInherited = true;        setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE);    }    // inherit minExclusive    if ((( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) == 0) &&        (( thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) == 0) )    {        fMinExclusive = numBase->getMinExclusive();        fMinExclusiveInherited = true;        setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE);    }    inheritAdditionalFacet();    // inherit "fixed" option    setFixed(getFixed() | numBase->getFixed());}const RefArrayVectorOf<XMLCh>* AbstractNumericFacetValidator::getEnumString() const{	return (fEnumerationInherited? getBaseValidator()->getEnumString() : fStrEnumeration );}void AbstractNumericFacetValidator::checkAdditionalFacetConstraints(MemoryManager* const) const{    return;}void AbstractNumericFacetValidator::checkAdditionalFacetConstraintsBase(MemoryManager* const) const{    return;}void AbstractNumericFacetValidator::inheritAdditionalFacet(){    return;}void AbstractNumericFacetValidator::assignAdditionalFacet( const XMLCh* const key                                                   , const XMLCh* const                                                   , MemoryManager* const manager){    ThrowXMLwithMemMgr1(InvalidDatatypeFacetException            , XMLExcepts::FACET_Invalid_Tag            , key            , manager);}/*** * Support for Serialization/De-serialization ***/IMPL_XSERIALIZABLE_NOCREATE(AbstractNumericFacetValidator)/*** *  This dv needs to serialize/deserialize four boundary data members *  which are derivatives of XMLlNumber. *  The derivatives of this class, namely, Deciamldv, Doubledv, Floatdv and *  DateTimedv needs to write a typeEnum into the binary data stream, so *  during loading, this method reads the typeEnum first, and then instantiate *  the right type of objects, say XMLDouble, XMLFloat, XMLBigDecimal and  *  XMLDateTime. * *   ***/void AbstractNumericFacetValidator::serialize(XSerializeEngine& serEng){    if (serEng.isStoring())    {        /***         * don't move this line out of the if statement,         * it is done purposely to allow AbstractNumericFacetValidator         * read the number type information before DatatypeValidator         * during loading         ***/        DatatypeValidator::serialize(serEng);        // need not write type info for the XMLNumber since        // the derivative class has done that               storeClusive(serEng, fMaxInclusiveInherited, fMaxInclusive);        storeClusive(serEng, fMaxExclusiveInherited, fMaxExclusive);        storeClusive(serEng, fMinInclusiveInherited, fMinInclusive);        storeClusive(serEng, fMinExclusiveInherited, fMinExclusive);        serEng<<fEnumerationInherited;        /***         * Serialize RefArrayVectorOf<XMLCh>         * Serialize RefVectorOf<XMLNumber>         ***/        XTemplateSerializer::storeObject(fStrEnumeration, serEng);        XTemplateSerializer::storeObject(fEnumeration, serEng);       }    else    {        // Read the number type info for the XMLNumber FIRST!!!        int                     nType;        XMLNumber::NumberType   numType;        serEng>>nType;        numType = (XMLNumber::NumberType) nType;        DatatypeValidator::serialize(serEng);        loadClusive(serEng, fMaxInclusiveInherited, fMaxInclusive, numType, 1);        loadClusive(serEng, fMaxExclusiveInherited, fMaxExclusive, numType, 2);        loadClusive(serEng, fMinInclusiveInherited, fMinInclusive, numType, 3);        loadClusive(serEng, fMinExclusiveInherited, fMinExclusive, numType, 4);        serEng>>fEnumerationInherited;        /***         *  Deserialize RefArrayVectorOf<XMLCh>                  *  Deserialize RefVectorOf<XMLNumber>            ***/        XTemplateSerializer::loadObject(&fStrEnumeration, 8, true, serEng);        XTemplateSerializer::loadObject(&fEnumeration, 8, true, numType, serEng);    }}//// A user defined dv may inherit any of the Max/Min/Inc/Exc from a// built dv, which will create its own Max/Min/Inc/Exc during the// loading. Therefore if the user defined store and load this // facet, and does not own it, that will cause leakage.//// To avoid checking if the facet belongs to a builtIn dv or not, we// do this way, for any inherited *clusive, we will not store it, and later // on during loading, we get it from the base dv.//void AbstractNumericFacetValidator::storeClusive(XSerializeEngine&       serEng                                               , bool                    inherited                                               , XMLNumber*              data){    serEng<<inherited;    //store only if own it    if (!inherited)        serEng<<data;}// it is guranteed that the base dv is loaded before this dv//void AbstractNumericFacetValidator::loadClusive(XSerializeEngine&       serEng                                              , bool&                   inherited                                              , XMLNumber*&             data                                              , XMLNumber::NumberType   numType                                              , int                     flag){    serEng>>inherited;    if (!inherited)        data = XMLNumber::loadNumber(numType, serEng);    else    {        AbstractNumericFacetValidator* basedv = (AbstractNumericFacetValidator*) getBaseValidator();        switch(flag)        {        case 1:             data = basedv->getMaxInclusive();            break;        case 2:            data = basedv->getMaxExclusive();            break;        case 3:            data = basedv->getMinInclusive();            break;        case 4:            data = basedv->getMinExclusive();            break;        default:            break;        }    }}XERCES_CPP_NAMESPACE_END/**  * End of file AbstractNumericFacetValidator::cpp  */

⌨️ 快捷键说明

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