KHTML
predicate.h
Go to the documentation of this file.
00001 /* 00002 * predicate.h - Copyright 2005 Frerich Raabe <raabe@kde.org> 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 #ifndef PREDICATE_H 00026 #define PREDICATE_H 00027 00028 #include "expression.h" 00029 00030 namespace khtml { 00031 namespace XPath { 00032 00033 class Number : public Expression 00034 { 00035 public: 00036 Number( double value ); 00037 00038 bool isConstant() const; 00039 virtual QString dump() const; 00040 00041 private: 00042 virtual Value doEvaluate() const; 00043 00044 double m_value; 00045 }; 00046 00047 class String : public Expression 00048 { 00049 public: 00050 String( const DOM::DOMString &value ); 00051 00052 bool isConstant() const; 00053 virtual QString dump() const; 00054 00055 private: 00056 virtual Value doEvaluate() const; 00057 00058 DOM::DOMString m_value; 00059 }; 00060 00061 class Negative : public Expression 00062 { 00063 public: 00064 virtual QString dump() const; 00065 00066 private: 00067 virtual Value doEvaluate() const; 00068 }; 00069 00070 class BinaryExprBase : public Expression 00071 { 00072 public: 00073 virtual QString dump() const; 00074 00075 protected: 00076 virtual QString opName() const = 0; 00077 }; 00078 00079 class NumericOp : public BinaryExprBase 00080 { 00081 public: 00082 enum { 00083 OP_Add = 1, 00084 OP_Sub, 00085 OP_Mul, 00086 OP_Div, 00087 OP_Mod 00088 }; 00089 00090 NumericOp( int opCode, Expression* lhs, Expression* rhs ); 00091 00092 private: 00093 virtual QString opName() const; 00094 virtual Value doEvaluate() const; 00095 int opCode; 00096 }; 00097 00098 class RelationOp : public BinaryExprBase 00099 { 00100 public: 00101 enum { 00102 OP_GT = 1, 00103 OP_LT, 00104 OP_GE, 00105 OP_LE, 00106 OP_EQ, 00107 OP_NE 00108 }; 00109 00110 RelationOp( int opCode, Expression* lhs, Expression* rhs ); 00111 00112 private: 00113 virtual QString opName() const; 00114 virtual Value doEvaluate() const; 00115 int opCode; 00116 00117 // compares strings based on the op-code 00118 bool compareStrings(const DOM::DOMString& l, const DOM::DOMString& r) const; 00119 bool compareNumbers(double l, double r) const; 00120 }; 00121 00122 class LogicalOp : public BinaryExprBase 00123 { 00124 public: 00125 enum { 00126 OP_And = 1, 00127 OP_Or 00128 }; 00129 00130 LogicalOp( int opCode, Expression* lhs, Expression* rhs ); 00131 00132 virtual bool isConstant() const; 00133 00134 private: 00135 bool shortCircuitOn() const; 00136 virtual QString opName() const; 00137 virtual Value doEvaluate() const; 00138 int opCode; 00139 }; 00140 00141 class Union : public BinaryExprBase 00142 { 00143 private: 00144 virtual QString opName() const; 00145 virtual Value doEvaluate() const; 00146 }; 00147 00148 class Predicate 00149 { 00150 public: 00151 Predicate( Expression *expr ); 00152 ~Predicate(); 00153 00154 bool evaluate() const; 00155 00156 void optimize(); 00157 QString dump() const; 00158 00159 private: 00160 Predicate( const Predicate &rhs ); 00161 Predicate &operator=( const Predicate &rhs ); 00162 00163 Expression *m_expr; 00164 }; 00165 00166 } // namespace XPath 00167 00168 } // namespace khtml 00169 00170 00171 #endif // PREDICATE_H 00172 00173 // kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off;
KDE 4.6 API Reference