~ubuntu-branches/ubuntu/precise/xerces-c/precise

« back to all changes in this revision

Viewing changes to src/xercesc/validators/schema/identity/XPathMatcher.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2009-02-22 16:52:23 UTC
  • Revision ID: james.westby@ubuntu.com-20090222165223-klimp8u8m73yn9zp
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 679382 2008-07-24 12:09:39Z 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 <xercesc/framework/XMLBuffer.hpp>
 
32
 
 
33
XERCES_CPP_NAMESPACE_BEGIN
 
34
 
 
35
// ---------------------------------------------------------------------------
 
36
//  Forward Declaration
 
37
// ---------------------------------------------------------------------------
 
38
class XMLElementDecl;
 
39
class XercesXPath;
 
40
class IdentityConstraint;
 
41
class DatatypeValidator;
 
42
class XMLStringPool;
 
43
class XercesLocationPath;
 
44
class XMLAttr;
 
45
class XercesNodeTest;
 
46
class QName;
 
47
 
 
48
class VALIDATORS_EXPORT XPathMatcher : public XMemory
 
49
{
 
50
public:
 
51
    // -----------------------------------------------------------------------
 
52
    //  Constructors/Destructor
 
53
    // -----------------------------------------------------------------------
 
54
    XPathMatcher(XercesXPath* const xpath,
 
55
                 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
 
56
    XPathMatcher(XercesXPath* const xpath,
 
57
                 IdentityConstraint* const ic,
 
58
                 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
 
59
    virtual ~XPathMatcher();
 
60
 
 
61
    // -----------------------------------------------------------------------
 
62
    //  Getter methods
 
63
    // -----------------------------------------------------------------------
 
64
    IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
 
65
    MemoryManager* getMemoryManager() const { return fMemoryManager; }
 
66
 
 
67
    // -----------------------------------------------------------------------
 
68
    //  Match methods
 
69
    // -----------------------------------------------------------------------
 
70
    /**
 
71
      * Returns true if XPath has been matched.
 
72
      */
 
73
    unsigned char isMatched();
 
74
    virtual int getInitialDepth() const;
 
75
 
 
76
    // -----------------------------------------------------------------------
 
77
    //  XMLDocumentHandler methods
 
78
    // -----------------------------------------------------------------------
 
79
    virtual void startDocumentFragment();
 
80
    virtual void startElement(const XMLElementDecl& elemDecl,
 
81
                              const unsigned int urlId,
 
82
                              const XMLCh* const elemPrefix,
 
83
                              const RefVectorOf<XMLAttr>& attrList,
 
84
                              const XMLSize_t attrCount);
 
85
    virtual void endElement(const XMLElementDecl& elemDecl,
 
86
                            const XMLCh* const elemContent);
 
87
 
 
88
    enum
 
89
    {
 
90
        XP_MATCHED = 1        // matched any way
 
91
        , XP_MATCHED_A = 3    // matched on the attribute axis
 
92
        , XP_MATCHED_D = 5    // matched on the descendant-or-self axixs
 
93
        , XP_MATCHED_DP = 13  // matched some previous (ancestor) node on the
 
94
                              // descendant-or-self-axis, but not this node
 
95
    };
 
96
 
 
97
protected:
 
98
 
 
99
    // -----------------------------------------------------------------------
 
100
    //  Match methods
 
101
    // -----------------------------------------------------------------------
 
102
    /**
 
103
      * This method is called when the XPath handler matches the XPath
 
104
      * expression. Subclasses can override this method to provide default
 
105
      * handling upon a match.
 
106
      */
 
107
    virtual void matched(const XMLCh* const content,
 
108
                         DatatypeValidator* const dv, const bool isNil);
 
109
 
 
110
    bool matches(const XercesNodeTest* nodeTest, const QName* qName);
 
111
 
 
112
private:
 
113
    // -----------------------------------------------------------------------
 
114
    //  Unimplemented constructors and operators
 
115
    // -----------------------------------------------------------------------
 
116
    XPathMatcher(const XPathMatcher&);
 
117
    XPathMatcher& operator=(const XPathMatcher&);
 
118
 
 
119
    // -----------------------------------------------------------------------
 
120
    //  Helper methods
 
121
    // -----------------------------------------------------------------------
 
122
    void init(XercesXPath* const xpath);
 
123
    void cleanUp();
 
124
 
 
125
    // -----------------------------------------------------------------------
 
126
    //  Data members
 
127
    //
 
128
    //  fMatched
 
129
    //      Indicates whether XPath has been matched or not
 
130
    //
 
131
    //  fNoMatchDepth
 
132
    //      Indicates whether matching is successful for the given xpath
 
133
    //      expression.
 
134
    //
 
135
    //  fCurrentStep
 
136
    //      Stores current step.
 
137
    //
 
138
    //  fStepIndexes
 
139
    //      Integer stack of step indexes.
 
140
    //
 
141
    //  fLocationPaths
 
142
    //  fLocationPathSize
 
143
    //      XPath location path, and its size.
 
144
    //
 
145
    //  fIdentityConstraint
 
146
    //      The identity constraint we're the matcher for.  Only used for
 
147
    //      selectors.
 
148
    //
 
149
    // -----------------------------------------------------------------------
 
150
    XMLSize_t                               fLocationPathSize;
 
151
    unsigned char*                          fMatched;
 
152
    XMLSize_t*                              fNoMatchDepth;
 
153
    XMLSize_t*                              fCurrentStep;
 
154
    RefVectorOf<ValueStackOf<XMLSize_t> >*  fStepIndexes;
 
155
    RefVectorOf<XercesLocationPath>*        fLocationPaths;
 
156
    IdentityConstraint*                     fIdentityConstraint;
 
157
    MemoryManager*                          fMemoryManager;
 
158
};
 
159
 
 
160
// ---------------------------------------------------------------------------
 
161
//  XPathMatcher: Helper methods
 
162
// ---------------------------------------------------------------------------
 
163
inline void XPathMatcher::cleanUp() {
 
164
 
 
165
    fMemoryManager->deallocate(fMatched);//delete [] fMatched;
 
166
    fMemoryManager->deallocate(fNoMatchDepth);//delete [] fNoMatchDepth;
 
167
    fMemoryManager->deallocate(fCurrentStep);//delete [] fCurrentStep;
 
168
    delete fStepIndexes;
 
169
}
 
170
 
 
171
XERCES_CPP_NAMESPACE_END
 
172
 
 
173
#endif
 
174
 
 
175
/**
 
176
  * End of file XPathMatcher.hpp
 
177
  */
 
178