andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 1 | /* |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 2 | * Copyright 2005 Frerich Raabe <raabe@kde.org> |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 3 | * 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 | */ |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 26 | |
eseidel | 8eddecf | 2007-01-16 00:49:43 +0000 | [diff] [blame] | 27 | #ifndef XPathStep_h |
| 28 | #define XPathStep_h |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 29 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 30 | #if ENABLE(XPATH) |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 31 | |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 32 | #include "Node.h" |
| 33 | #include "XPathExpressionNode.h" |
ap | ce79f36 | 2007-03-20 17:21:07 +0000 | [diff] [blame] | 34 | #include "XPathNodeSet.h" |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 35 | |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 36 | namespace WebCore { |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 37 | |
| 38 | namespace XPath { |
| 39 | |
| 40 | class Predicate; |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 41 | |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 42 | 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 | }; |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 51 | |
| 52 | class NodeTest { |
| 53 | public: |
| 54 | enum Kind { |
| 55 | TextNodeTest, CommentNodeTest, ProcessingInstructionNodeTest, AnyNodeTest, NameTest, |
| 56 | ElementNodeTest // XPath 2.0 |
| 57 | }; |
| 58 | |
ap | 16c9b5f | 2007-03-28 16:48:16 +0000 | [diff] [blame] | 59 | 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) {} |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 62 | |
| 63 | Kind kind() const { return m_kind; } |
| 64 | const String data() const { return m_data; } |
ap | 16c9b5f | 2007-03-28 16:48:16 +0000 | [diff] [blame] | 65 | const String namespaceURI() const { return m_namespaceURI; } |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 66 | |
| 67 | private: |
| 68 | Kind m_kind; |
| 69 | String m_data; |
ap | 16c9b5f | 2007-03-28 16:48:16 +0000 | [diff] [blame] | 70 | String m_namespaceURI; |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 71 | }; |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 72 | |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 73 | Step(Axis, const NodeTest& nodeTest, const Vector<Predicate*>& predicates = Vector<Predicate*>()); |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 74 | ~Step(); |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 75 | |
ap | f0b81e0 | 2007-03-30 20:31:26 +0000 | [diff] [blame] | 76 | void evaluate(Node* context, NodeSet&) const; |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 77 | |
| 78 | Axis axis() const { return m_axis; } |
| 79 | NodeTest nodeTest() const { return m_nodeTest; } |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 80 | 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; } |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 84 | void setPredicates(const Vector<Predicate*>& predicates) { m_predicates = predicates; } |
| 85 | |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 86 | private: |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 87 | void parseNodeTest(const String&); |
ap | f0b81e0 | 2007-03-30 20:31:26 +0000 | [diff] [blame] | 88 | void nodesInAxis(Node* context, NodeSet&) const; |
ap | b437182 | 2007-03-25 08:39:27 +0000 | [diff] [blame] | 89 | bool nodeMatches(Node*) const; |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 90 | String namespaceFromNodetest(const String& nodeTest) const; |
| 91 | Node::NodeType primaryNodeType(Axis) const; |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 92 | |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 93 | Axis m_axis; |
ap | 94457f1 | 2007-03-11 08:21:13 +0000 | [diff] [blame] | 94 | NodeTest m_nodeTest; |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 95 | Vector<Predicate*> m_predicates; |
| 96 | }; |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 97 | |
darin | a9406af | 2006-06-04 23:03:41 +0000 | [diff] [blame] | 98 | } |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 99 | |
| 100 | } |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 101 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 102 | #endif // ENABLE(XPATH) |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 103 | |
| 104 | #endif // XPath_Step_H |