• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • xpath
expression.h
Go to the documentation of this file.
1/*
2 * expression.h - Copyright 2005 Frerich Raabe <raabe@kde.org>
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 EXPRESSION_H
26#define EXPRESSION_H
27
28#include "util.h"
29
30#include <QHash>
31#include <QList>
32
33#include <dom/dom_string.h>
34#include <xml/dom_stringimpl.h>
35#include <xml/dom_nodelistimpl.h>
36#include <misc/shared.h>
37
38namespace DOM {
39 class NodeImpl;
40}
41
42namespace khtml {
43
44class XPathNSResolverImpl;
45namespace XPath {
46
47struct EvaluationContext
48{
49 EvaluationContext() { reset(0, 0); }
50
51 void reset(DOM::NodeImpl* ctx, XPathNSResolverImpl* res) {
52 node = ctx;
53 resolver = res;
54 size = 1;
55 position = 1;
56 exceptionCode = 0;
57 }
58
59 DOM::NodeImpl *node;
60 unsigned long size;
61 unsigned long position;
62 QHash<DOM::DOMString, DOM::DOMString> variableBindings;
63
64 // reports only first one.
65 void reportException(int ec) { if (!exceptionCode) exceptionCode = ec; }
66
67 int exceptionCode;
68
69 /* The function library is globally accessible through
70 * FunctionLibrary::self()
71 */
72 XPathNSResolverImpl *resolver;
73};
74
75class Value
76{
77 public:
78 enum Type {
79 Nodeset, Boolean, Number, String
80 };
81
82 Value();
83 explicit Value( DOM::NodeImpl *value );
84 explicit Value( const DomNodeList &value );
85 explicit Value( bool value );
86 explicit Value( double value );
87 explicit Value( const DOM::DOMString &value );
88
89 Type type() const;
90 bool isNodeset() const;
91 bool isBoolean() const;
92 bool isNumber() const;
93 bool isString() const;
94
95 DomNodeList &toNodeset(); // may return 0
96 const DomNodeList &toNodeset() const;
97 bool toBoolean() const;
98 double toNumber() const;
99 DOM::DOMString toString() const;
100
101 QString dump() const;
102
103 private:
104 // Catch undesired conversions -- this manages to go to bool otherwise!
105 explicit Value( const char* );
106
107 Type m_type;
108 DomNodeList m_nodeset;
109 bool m_bool;
110 double m_number;
111 DOM::DOMString m_string;
112};
113
114class Expression
115{
116 public:
117 static EvaluationContext &evaluationContext();
118
119 Expression();
120 virtual ~Expression();
121 virtual Value evaluate() const;
122
123 void addSubExpression( Expression *expr );
124 void optimize();
125 virtual bool isConstant() const;
126
127 virtual QString dump() const = 0;
128
129 static void reportInvalidExpressionErr();
130 static void reportNamespaceErr();
131 protected:
132 unsigned int subExprCount() const;
133 Expression *subExpr( unsigned int i );
134 const Expression *subExpr( unsigned int i ) const;
135
136 private:
137 virtual Value doEvaluate() const = 0;
138
139 QList<Expression *> m_subExpressions;
140 Value *m_constantValue;
141};
142
143} // namespace XPath
144
145} // namespace khtml
146
147#endif // EXPRESSION_H
148
149// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off;
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
QHash
QList
khtml::XPath::Expression
Definition: expression.h:115
khtml::XPath::Expression::subExprCount
unsigned int subExprCount() const
Definition: expression.cpp:261
khtml::XPath::Expression::evaluationContext
static EvaluationContext & evaluationContext()
Definition: expression.cpp:212
khtml::XPath::Expression::~Expression
virtual ~Expression()
Definition: expression.cpp:223
khtml::XPath::Expression::evaluate
virtual Value evaluate() const
Definition: expression.cpp:229
khtml::XPath::Expression::optimize
void optimize()
Definition: expression.cpp:242
khtml::XPath::Expression::dump
virtual QString dump() const =0
khtml::XPath::Expression::isConstant
virtual bool isConstant() const
Definition: expression.cpp:278
khtml::XPath::Expression::addSubExpression
void addSubExpression(Expression *expr)
Definition: expression.cpp:237
khtml::XPath::Expression::subExpr
Expression * subExpr(unsigned int i)
Definition: expression.cpp:266
khtml::XPath::Expression::reportNamespaceErr
static void reportNamespaceErr()
Definition: expression.cpp:293
khtml::XPath::Expression::reportInvalidExpressionErr
static void reportInvalidExpressionErr()
Definition: expression.cpp:288
khtml::XPath::Expression::Expression
Expression()
Definition: expression.cpp:218
khtml::XPath::String
Definition: predicate.h:48
khtml::XPath::Value
Definition: expression.h:76
khtml::XPath::Value::isString
bool isString() const
Definition: expression.cpp:101
khtml::XPath::Value::toString
DOM::DOMString toString() const
Definition: expression.cpp:160
khtml::XPath::Value::isNodeset
bool isNodeset() const
Definition: expression.cpp:86
khtml::XPath::Value::Type
Type
Definition: expression.h:78
khtml::XPath::Value::Number
@ Number
Definition: expression.h:79
khtml::XPath::Value::Nodeset
@ Nodeset
Definition: expression.h:79
khtml::XPath::Value::Boolean
@ Boolean
Definition: expression.h:79
khtml::XPath::Value::dump
QString dump() const
Definition: expression.cpp:191
khtml::XPath::Value::type
Type type() const
Definition: expression.cpp:81
khtml::XPath::Value::isNumber
bool isNumber() const
Definition: expression.cpp:96
khtml::XPath::Value::toNodeset
DomNodeList & toNodeset()
Definition: expression.cpp:106
khtml::XPath::Value::isBoolean
bool isBoolean() const
Definition: expression.cpp:91
khtml::XPath::Value::Value
Value()
Definition: expression.cpp:43
khtml::XPath::Value::Value
Value(DOM::NodeImpl *value)
khtml::XPath::Value::toBoolean
bool toBoolean() const
Definition: expression.cpp:122
khtml::XPath::Value::toNumber
double toNumber() const
Definition: expression.cpp:137
dom_string.h
DOM
This library provides a full-featured HTML parser and widget.
Definition: design.h:55
khtml::XPath::DomNodeList
SharedPtr< DOM::StaticNodeListImpl > DomNodeList
Definition: util.h:41
khtml
khtml::XPath::EvaluationContext
Definition: expression.h:48
khtml::XPath::EvaluationContext::reset
void reset(DOM::NodeImpl *ctx, XPathNSResolverImpl *res)
Definition: expression.h:51
khtml::XPath::EvaluationContext::position
unsigned long position
Definition: expression.h:61
khtml::XPath::EvaluationContext::resolver
XPathNSResolverImpl * resolver
Definition: expression.h:72
khtml::XPath::EvaluationContext::variableBindings
QHash< DOM::DOMString, DOM::DOMString > variableBindings
Definition: expression.h:62
khtml::XPath::EvaluationContext::exceptionCode
int exceptionCode
Definition: expression.h:67
khtml::XPath::EvaluationContext::size
unsigned long size
Definition: expression.h:60
khtml::XPath::EvaluationContext::reportException
void reportException(int ec)
Definition: expression.h:65
khtml::XPath::EvaluationContext::EvaluationContext
EvaluationContext()
Definition: expression.h:49
khtml::XPath::EvaluationContext::node
DOM::NodeImpl * node
Definition: expression.h:59
util.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal