blob: f1420d0e58c0413729cea7ecf7265ce248c991d8 [file] [log] [blame]
andersca75fd42c2006-05-08 21:27:25 +00001/*
darina9406af2006-06-04 23:03:41 +00002 * Copyright 2005 Frerich Raabe <raabe@kde.org>
andersca75fd42c2006-05-08 21:27:25 +00003 * Copyright (C) 2006 Apple Computer, Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
darina9406af2006-06-04 23:03:41 +000026
eseidel8eddecf2007-01-16 00:49:43 +000027#ifndef XPathStep_h
28#define XPathStep_h
andersca75fd42c2006-05-08 21:27:25 +000029
mjsd2948ef2007-02-26 19:29:04 +000030#if ENABLE(XPATH)
andersca75fd42c2006-05-08 21:27:25 +000031
darina9406af2006-06-04 23:03:41 +000032#include "Node.h"
33#include "XPathExpressionNode.h"
apce79f362007-03-20 17:21:07 +000034#include "XPathNodeSet.h"
andersca75fd42c2006-05-08 21:27:25 +000035
andersca75fd42c2006-05-08 21:27:25 +000036namespace WebCore {
darina9406af2006-06-04 23:03:41 +000037
38 namespace XPath {
39
40 class Predicate;
andersca75fd42c2006-05-08 21:27:25 +000041
darina9406af2006-06-04 23:03:41 +000042 class Step : public ParseNode, Noncopyable {
43 public:
44 enum Axis {
45 AncestorAxis, AncestorOrSelfAxis, AttributeAxis,
46 ChildAxis, DescendantAxis, DescendantOrSelfAxis,
47 FollowingAxis, FollowingSiblingAxis, NamespaceAxis,
48 ParentAxis, PrecedingAxis, PrecedingSiblingAxis,
49 SelfAxis
50 };
ap94457f12007-03-11 08:21:13 +000051
52 class NodeTest {
53 public:
54 enum Kind {
55 TextNodeTest, CommentNodeTest, ProcessingInstructionNodeTest, AnyNodeTest, NameTest,
56 ElementNodeTest // XPath 2.0
57 };
58
ap16c9b5f2007-03-28 16:48:16 +000059 NodeTest(Kind kind) : m_kind(kind) {}
60 NodeTest(Kind kind, const String& data) : m_kind(kind), m_data(data) {}
61 NodeTest(Kind kind, const String& data, const String& namespaceURI) : m_kind(kind), m_data(data), m_namespaceURI(namespaceURI) {}
ap94457f12007-03-11 08:21:13 +000062
63 Kind kind() const { return m_kind; }
64 const String data() const { return m_data; }
ap16c9b5f2007-03-28 16:48:16 +000065 const String namespaceURI() const { return m_namespaceURI; }
ap94457f12007-03-11 08:21:13 +000066
67 private:
68 Kind m_kind;
69 String m_data;
ap16c9b5f2007-03-28 16:48:16 +000070 String m_namespaceURI;
ap94457f12007-03-11 08:21:13 +000071 };
andersca75fd42c2006-05-08 21:27:25 +000072
ap94457f12007-03-11 08:21:13 +000073 Step(Axis, const NodeTest& nodeTest, const Vector<Predicate*>& predicates = Vector<Predicate*>());
darina9406af2006-06-04 23:03:41 +000074 ~Step();
andersca75fd42c2006-05-08 21:27:25 +000075
apf0b81e02007-03-30 20:31:26 +000076 void evaluate(Node* context, NodeSet&) const;
ap94457f12007-03-11 08:21:13 +000077
78 Axis axis() const { return m_axis; }
79 NodeTest nodeTest() const { return m_nodeTest; }
ap94457f12007-03-11 08:21:13 +000080 const Vector<Predicate*>& predicates() const { return m_predicates; }
81
82 void setAxis(Axis axis) { m_axis = axis; }
83 void setNodeTest(NodeTest nodeTest) { m_nodeTest = nodeTest; }
ap94457f12007-03-11 08:21:13 +000084 void setPredicates(const Vector<Predicate*>& predicates) { m_predicates = predicates; }
85
darina9406af2006-06-04 23:03:41 +000086 private:
ap94457f12007-03-11 08:21:13 +000087 void parseNodeTest(const String&);
apf0b81e02007-03-30 20:31:26 +000088 void nodesInAxis(Node* context, NodeSet&) const;
apb4371822007-03-25 08:39:27 +000089 bool nodeMatches(Node*) const;
darina9406af2006-06-04 23:03:41 +000090 String namespaceFromNodetest(const String& nodeTest) const;
91 Node::NodeType primaryNodeType(Axis) const;
andersca75fd42c2006-05-08 21:27:25 +000092
darina9406af2006-06-04 23:03:41 +000093 Axis m_axis;
ap94457f12007-03-11 08:21:13 +000094 NodeTest m_nodeTest;
darina9406af2006-06-04 23:03:41 +000095 Vector<Predicate*> m_predicates;
96 };
andersca75fd42c2006-05-08 21:27:25 +000097
darina9406af2006-06-04 23:03:41 +000098 }
andersca75fd42c2006-05-08 21:27:25 +000099
100}
andersca75fd42c2006-05-08 21:27:25 +0000101
mjsd2948ef2007-02-26 19:29:04 +0000102#endif // ENABLE(XPATH)
andersca75fd42c2006-05-08 21:27:25 +0000103
104#endif // XPath_Step_H