xercesxpath.cpp

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

CPP
1,455
字号
/* * 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. *//* * $Log: XercesXPath.cpp,v $ * Revision 1.14  2004/09/08 13:56:59  peiyongz * Apache License Version 2.0 * * Revision 1.13  2004/01/29 11:52:32  cargilld * Code cleanup changes to get rid of various compiler diagnostic messages. * * Revision 1.12  2003/12/17 00:18:41  cargilld * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. * * Revision 1.11  2003/10/17 21:18:04  peiyongz * using XTemplateSerializer * * Revision 1.10  2003/10/14 15:24:23  peiyongz * Implementation of Serialization/Deserialization * * Revision 1.9  2003/10/01 16:32:42  neilg * improve handling of out of memory conditions, bug #23415.  Thanks to David Cargill. * * Revision 1.8  2003/05/18 14:02:09  knoaman * Memory manager implementation: pass per instance manager. * * Revision 1.7  2003/05/16 21:43:22  knoaman * Memory manager implementation: Modify constructors to pass in the memory manager. * * Revision 1.6  2003/05/15 18:59:34  knoaman * Partial implementation of the configurable memory manager. * * Revision 1.5  2002/12/20 22:10:48  tng * XML 1.1 * * Revision 1.4  2002/12/04 18:21:23  knoaman * Identity constraint fix. * * Revision 1.3  2002/11/04 14:47:42  tng * C++ Namespace Support. * * Revision 1.2  2002/10/30 21:52:01  tng * [Bug 13641] compiler-generated copy-constructor for QName doesn't do the right thing. * * Revision 1.1.1.1  2002/02/01 22:22:51  peiyongz * sane_include * * Revision 1.3  2001/11/15 17:10:19  knoaman * Particle derivation checking support. * * Revision 1.2  2001/11/07 14:25:36  knoaman * Fix compliation error on Unix. * * Revision 1.1  2001/11/02 14:08:40  knoaman * Add support for identity constraints. * */// ---------------------------------------------------------------------------//  Includes// ---------------------------------------------------------------------------#include <xercesc/validators/schema/identity/XercesXPath.hpp>#include <xercesc/validators/schema/identity/XPathSymbols.hpp>#include <xercesc/validators/schema/identity/XPathException.hpp>#include <xercesc/validators/schema/NamespaceScope.hpp>#include <xercesc/util/StringPool.hpp>#include <xercesc/util/Janitor.hpp>#include <xercesc/framework/XMLBuffer.hpp>#include <xercesc/internal/XMLReader.hpp>#include <xercesc/util/RuntimeException.hpp>#include <xercesc/util/OutOfMemoryException.hpp>#include <xercesc/internal/XTemplateSerializer.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------//  Static data// ---------------------------------------------------------------------------const XMLByte XPathScanner::fASCIICharMap[128] ={    0,  0,  0,  0,  0,  0,  0,  0,  0,  2,  2,  0,  0,  2,  0,  0,    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,    2,  3,  4,  1,  5,  1,  1,  4,  6,  7,  8,  9, 10, 11, 12, 13,    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15,  1, 16, 17, 18,  1,    19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,  1, 22,  1, 23,    1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  1, 24,  1,  1,  1};// ---------------------------------------------------------------------------//  XercesNodeTest: Constructors and Destructor// ---------------------------------------------------------------------------XercesNodeTest::XercesNodeTest(const short aType,                               MemoryManager* const manager)    : fType(aType)    , fName(new (manager) QName(manager)){}XercesNodeTest::XercesNodeTest(const QName* const qName)    : fType(QNAME)    , fName(new (qName->getMemoryManager()) QName(*qName)){}XercesNodeTest::XercesNodeTest(const XMLCh* const prefix,                               const unsigned int uriId,                               MemoryManager* const manager)    : fType(NAMESPACE)    , fName(new (manager) QName(manager)){    fName->setURI(uriId);    fName->setPrefix(prefix);}XercesNodeTest::XercesNodeTest(const XercesNodeTest& other)    : fType(other.fType)    , fName(new ((other.fName)->getMemoryManager())QName(*other.fName)){}/*** * Support for Serialization/De-serialization ***/IMPL_XSERIALIZABLE_TOCREATE(XercesNodeTest)void XercesNodeTest::serialize(XSerializeEngine& serEng){    if (serEng.isStoring())    {        serEng<<fType;        serEng<<fName;    }    else    {        serEng>>fType;        serEng>>fName;    }}XercesNodeTest::XercesNodeTest(MemoryManager* const):fType(UNKNOWN),fName(0){}// ---------------------------------------------------------------------------//  XercesNodeTest: Operators// ---------------------------------------------------------------------------XercesNodeTest& XercesNodeTest::operator=(const XercesNodeTest& other){    if (this == &other)        return *this;    fType = other.fType;    fName->setValues(*(other.fName));    return *this;}bool XercesNodeTest::operator ==(const XercesNodeTest& other) const {    if (this == &other)        return true;    if (fType != other.fType)        return false;    return (*fName == *(other.fName));}bool XercesNodeTest::operator !=(const XercesNodeTest& other) const {    return !operator==(other);}// ---------------------------------------------------------------------------//  XercesStep: Constructors and Destructor// ---------------------------------------------------------------------------XercesStep::XercesStep(const unsigned short axisType, XercesNodeTest* const nodeTest)    : fAxisType(axisType)    , fNodeTest(nodeTest){}XercesStep::XercesStep(const XercesStep& other)    : fAxisType(other.fAxisType)    , fNodeTest(0){    fNodeTest = new (other.fNodeTest->getName()->getMemoryManager()) XercesNodeTest(*(other.fNodeTest));}// ---------------------------------------------------------------------------//  XercesStep: Operators// ---------------------------------------------------------------------------XercesStep& XercesStep::operator=(const XercesStep& other){    if (this == &other)        return *this;    fAxisType = other.fAxisType;    *fNodeTest = *(other.fNodeTest);    return *this;}bool XercesStep::operator==(const XercesStep& other) const {    if (this == &other)        return true;    if (fAxisType != other.fAxisType)        return false;    if (fAxisType == XercesStep::CHILD ||        fAxisType == XercesStep::ATTRIBUTE) {        return (*fNodeTest == *(other.fNodeTest));    }    return true;}bool XercesStep::operator!=(const XercesStep& other) const {    return !operator==(other);}/*** * Support for Serialization/De-serialization ***/IMPL_XSERIALIZABLE_TOCREATE(XercesStep)void XercesStep::serialize(XSerializeEngine& serEng){    if (serEng.isStoring())    {        serEng<<fAxisType;        serEng<<fNodeTest;    }    else    {        serEng>>fAxisType;        serEng>>fNodeTest;    }}XercesStep::XercesStep(MemoryManager* const):fAxisType(UNKNOWN),fNodeTest(0){}// ---------------------------------------------------------------------------//  XercesLocationPath: Constructors and Destructor// ---------------------------------------------------------------------------XercesLocationPath::XercesLocationPath(RefVectorOf<XercesStep>* const steps)    : fSteps(steps){}// ---------------------------------------------------------------------------//  XercesLocationPath: Operators// ---------------------------------------------------------------------------bool XercesLocationPath::operator==(const XercesLocationPath& other) const {    unsigned int stepsSize = fSteps->size();    if (stepsSize != other.fSteps->size())        return false;    for (unsigned int i=0; i < stepsSize; i++) {        if (*(fSteps->elementAt(i)) != *(other.fSteps->elementAt(i)))            return false;    }    return true;}bool XercesLocationPath::operator!=(const XercesLocationPath& other) const {    return !operator==(other);}/*** * Support for Serialization/De-serialization ***/IMPL_XSERIALIZABLE_TOCREATE(XercesLocationPath)void XercesLocationPath::serialize(XSerializeEngine& serEng){    if (serEng.isStoring())    {        /***         * Serialize RefVectorOf<XercesStep>* fSteps;         ***/        XTemplateSerializer::storeObject(fSteps, serEng);    }    else    {        /***         * Deserialize RefVectorOf<XercesStep>* fSteps;         ***/        XTemplateSerializer::loadObject(&fSteps, 8, true, serEng);    }}XercesLocationPath::XercesLocationPath(MemoryManager* const):fSteps(0){}// ---------------------------------------------------------------------------//  XercesPath: Constructors and Destructor// ---------------------------------------------------------------------------XercesXPath::XercesXPath(const XMLCh* const xpathExpr,                         XMLStringPool* const stringPool,                         NamespaceScope* const scopeContext,                         const unsigned int emptyNamespaceId,                         const bool isSelector,                         MemoryManager* const manager)    : fEmptyNamespaceId(emptyNamespaceId)    , fExpression(0)    , fLocationPaths(0)    , fMemoryManager(manager){    try    {        fExpression = XMLString::replicate(xpathExpr, fMemoryManager);        parseExpression(stringPool, scopeContext);        if (isSelector) {            checkForSelectedAttributes();        }    }    catch(const OutOfMemoryException&)    {        throw;    }    catch(...) {        cleanUp();        throw;    }

⌨️ 快捷键说明

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