source: icXML/icXML-devel/src/xercesc/validators/schema/identity/XPathMatcher.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 6.9 KB
RevLine 
[2722]1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XPathMatcher.hpp 803869 2009-08-13 12:56:21Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XPATHMATCHER_HPP)
23#define XERCESC_INCLUDE_GUARD_XPATHMATCHER_HPP
24
25
26// ---------------------------------------------------------------------------
27//  Includes
28// ---------------------------------------------------------------------------
29#include <xercesc/util/ValueStackOf.hpp>
30#include <xercesc/util/RefVectorOf.hpp>
31#include <icxercesc/framework/XMLBuffer.hpp>
32
33XERCES_CPP_NAMESPACE_BEGIN
34
35// ---------------------------------------------------------------------------
36//  Forward Declaration
37// ---------------------------------------------------------------------------
38class XMLElementDecl;
39class XercesXPath;
40class IdentityConstraint;
41class DatatypeValidator;
42class XMLStringPool;
43class XercesLocationPath;
44class XMLAttr;
45class XercesNodeTest;
46class QName;
47class ValidationContext;
48
49class VALIDATORS_EXPORT XPathMatcher : public XMemory
50{
51public:
52    // -----------------------------------------------------------------------
53    //  Constructors/Destructor
54    // -----------------------------------------------------------------------
55    XPathMatcher(XercesXPath* const xpath,
56                 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
57    XPathMatcher(XercesXPath* const xpath,
58                 IdentityConstraint* const ic,
59                 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
60    virtual ~XPathMatcher();
61
62    // -----------------------------------------------------------------------
63    //  Getter methods
64    // -----------------------------------------------------------------------
65    IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
66    MemoryManager* getMemoryManager() const { return fMemoryManager; }
67
68    // -----------------------------------------------------------------------
69    //  Match methods
70    // -----------------------------------------------------------------------
71    /**
72      * Returns true if XPath has been matched.
73      */
74    unsigned char isMatched();
75    virtual int getInitialDepth() const;
76
77    // -----------------------------------------------------------------------
78    //  XMLDocumentHandler methods
79    // -----------------------------------------------------------------------
80    virtual void startDocumentFragment();
81    virtual void startElement(const XMLElementDecl& elemDecl,
82                              const unsigned int urlId,
83                              const XMLCh* const elemPrefix,
84                              const RefVectorOf<XMLAttr>& attrList,
85                              const XMLSize_t attrCount,
86                              ValidationContext* validationContext = 0);
87    virtual void endElement(const XMLElementDecl& elemDecl,
88                            const XMLCh* const elemContent,
89                            ValidationContext* validationContext = 0,
90                            DatatypeValidator* actualValidator = 0);
91
92    enum
93    {
94        XP_MATCHED = 1        // matched any way
95        , XP_MATCHED_A = 3    // matched on the attribute axis
96        , XP_MATCHED_D = 5    // matched on the descendant-or-self axixs
97        , XP_MATCHED_DP = 13  // matched some previous (ancestor) node on the
98                              // descendant-or-self-axis, but not this node
99    };
100
101protected:
102
103    // -----------------------------------------------------------------------
104    //  Match methods
105    // -----------------------------------------------------------------------
106    /**
107      * This method is called when the XPath handler matches the XPath
108      * expression. Subclasses can override this method to provide default
109      * handling upon a match.
110      */
111    virtual void matched(const XMLCh* const content,
112                         DatatypeValidator* const dv, const bool isNil);
113
114    bool matches(const XercesNodeTest* nodeTest, const QName* qName);
115
116private:
117    // -----------------------------------------------------------------------
118    //  Unimplemented constructors and operators
119    // -----------------------------------------------------------------------
120    XPathMatcher(const XPathMatcher&);
121    XPathMatcher& operator=(const XPathMatcher&);
122
123    // -----------------------------------------------------------------------
124    //  Helper methods
125    // -----------------------------------------------------------------------
126    void init(XercesXPath* const xpath);
127    void cleanUp();
128
129    // -----------------------------------------------------------------------
130    //  Data members
131    //
132    //  fMatched
133    //      Indicates whether XPath has been matched or not
134    //
135    //  fNoMatchDepth
136    //      Indicates whether matching is successful for the given xpath
137    //      expression.
138    //
139    //  fCurrentStep
140    //      Stores current step.
141    //
142    //  fStepIndexes
143    //      Integer stack of step indexes.
144    //
145    //  fLocationPaths
146    //  fLocationPathSize
147    //      XPath location path, and its size.
148    //
149    //  fIdentityConstraint
150    //      The identity constraint we're the matcher for.  Only used for
151    //      selectors.
152    //
153    // -----------------------------------------------------------------------
154    XMLSize_t                               fLocationPathSize;
155    unsigned char*                          fMatched;
156    XMLSize_t*                              fNoMatchDepth;
157    XMLSize_t*                              fCurrentStep;
158    RefVectorOf<ValueStackOf<XMLSize_t> >*  fStepIndexes;
159    RefVectorOf<XercesLocationPath>*        fLocationPaths;
160    IdentityConstraint*                     fIdentityConstraint;
161    MemoryManager*                          fMemoryManager;
162};
163
164// ---------------------------------------------------------------------------
165//  XPathMatcher: Helper methods
166// ---------------------------------------------------------------------------
167inline void XPathMatcher::cleanUp() {
168
169    fMemoryManager->deallocate(fMatched);//delete [] fMatched;
170    fMemoryManager->deallocate(fNoMatchDepth);//delete [] fNoMatchDepth;
171    fMemoryManager->deallocate(fCurrentStep);//delete [] fCurrentStep;
172    delete fStepIndexes;
173}
174
175XERCES_CPP_NAMESPACE_END
176
177#endif
178
179/**
180  * End of file XPathMatcher.hpp
181  */
182
Note: See TracBrowser for help on using the repository browser.