KHtml

predicate.h
1 /*
2  * predicate.h - Copyright 2005 Frerich Raabe <[email protected]>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #ifndef PREDICATE_H
26 #define PREDICATE_H
27 
28 #include "expression.h"
29 
30 namespace khtml
31 {
32 namespace XPath
33 {
34 
35 class Number : public Expression
36 {
37 public:
38  Number(double value);
39 
40  bool isConstant() const override;
41  QString dump() const override;
42 
43 private:
44  Value doEvaluate() const override;
45 
46  double m_value;
47 };
48 
49 class String : public Expression
50 {
51 public:
52  String(const DOM::DOMString &value);
53 
54  bool isConstant() const override;
55  QString dump() const override;
56 
57 private:
58  Value doEvaluate() const override;
59 
60  DOM::DOMString m_value;
61 };
62 
63 class Negative : public Expression
64 {
65 public:
66  QString dump() const override;
67 
68 private:
69  Value doEvaluate() const override;
70 };
71 
72 class BinaryExprBase : public Expression
73 {
74 public:
75  QString dump() const override;
76 
77 protected:
78  virtual QString opName() const = 0;
79 };
80 
81 class NumericOp : public BinaryExprBase
82 {
83 public:
84  enum {
85  OP_Add = 1,
86  OP_Sub,
87  OP_Mul,
88  OP_Div,
89  OP_Mod
90  };
91 
92  NumericOp(int opCode, Expression *lhs, Expression *rhs);
93 
94 private:
95  QString opName() const override;
96  Value doEvaluate() const override;
97  int opCode;
98 };
99 
100 class RelationOp : public BinaryExprBase
101 {
102 public:
103  enum {
104  OP_GT = 1,
105  OP_LT,
106  OP_GE,
107  OP_LE,
108  OP_EQ,
109  OP_NE
110  };
111 
112  RelationOp(int opCode, Expression *lhs, Expression *rhs);
113 
114 private:
115  QString opName() const override;
116  Value doEvaluate() const override;
117  int opCode;
118 
119  // compares strings based on the op-code
120  bool compareStrings(const DOM::DOMString &l, const DOM::DOMString &r) const;
121  bool compareNumbers(double l, double r) const;
122 };
123 
124 class LogicalOp : public BinaryExprBase
125 {
126 public:
127  enum {
128  OP_And = 1,
129  OP_Or
130  };
131 
132  LogicalOp(int opCode, Expression *lhs, Expression *rhs);
133 
134  bool isConstant() const override;
135 
136 private:
137  bool shortCircuitOn() const;
138  QString opName() const override;
139  Value doEvaluate() const override;
140  int opCode;
141 };
142 
143 class Union : public BinaryExprBase
144 {
145 private:
146  QString opName() const override;
147  Value doEvaluate() const override;
148 };
149 
150 class Predicate
151 {
152 public:
153  Predicate(Expression *expr);
154  ~Predicate();
155 
156  bool evaluate() const;
157 
158  void optimize();
159  QString dump() const;
160 
161 private:
162  Predicate(const Predicate &rhs);
163  Predicate &operator=(const Predicate &rhs);
164 
165  Expression *m_expr;
166 };
167 
168 } // namespace XPath
169 
170 } // namespace khtml
171 
172 #endif // PREDICATE_H
173 
This file is part of the HTML rendering engine for KDE.
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.