diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | e9ae80694875f869892f13f4fcaf1170a00dea41 (patch) | |
tree | aa2f8d8a217e2d376224c8d46b7397b68d35de2d /kommander/widget/expression.h | |
download | tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.tar.gz tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kommander/widget/expression.h')
-rw-r--r-- | kommander/widget/expression.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/kommander/widget/expression.h b/kommander/widget/expression.h new file mode 100644 index 00000000..7ab163e2 --- /dev/null +++ b/kommander/widget/expression.h @@ -0,0 +1,80 @@ +/*************************************************************************** + expression.h - Expression parser + ------------------- + copyright : (C) 2004 Michal Rudolf <mrudolf@kdewebdwev.org> + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef _HAVE_EXPRESSION_H_ +#define _HAVE_EXPRESSION_H_ + +#include <qstring.h> +#include <qvaluelist.h> +#include <qvariant.h> + +class Expression +{ +public: + Expression(); + Expression(const QString& expr); + /* set string to parse */ + Expression& operator=(const QString& s); + /* calculate value */ + QVariant value(bool* valid = 0); + /* equivalent of setString(s) and value(valid) */ + QVariant value(const QString& s, bool* valid = 0); + /* equivalent of setString(s) and checking if value(valid) is true */ + bool isTrue(const QString& s, bool* valid = 0); +private: + enum Type {TypeInt, TypeDouble, TypeString}; + /* parsing function - top-down approach */ + /* parse terminal (number or string) */ + QVariant parseNumber(); + /* parse -x expression */ + QVariant parseMinus(); + /* parse (x) expression */ + QVariant parseBracket(); + /* parse x*y, x/y and x%y expressions */ + QVariant parseMultiply(); + /* parse x+y and x-y expressions */ + QVariant parseAdd(); + /* parse !x and (equivalent) not x expressions */ + QVariant parseNot(); + /* parse x==y, x<=y, x>=y, x<y and x>y expressions */ + QVariant parseComparison(); + /* parse x && y, (equivalent) x and y expressions */ + QVariant parseAnd(); + /* parse x || y and (equivalent) x or y expressions */ + QVariant parseOr(); + /* starting point of parsing - just call first function above */ + QVariant parse(); + + /* check if we still have next argument */ + bool validate(); + /* return next argument to parse or null if there is none */ + QString next() const; + /* set error position for future error reporting */ + void setError(int pos = -1); + /* compare various types of QVariant (strings, floats, ints */ + int compare(const QVariant v1, const QVariant v2) const; + /* return common type for binary operations */ + Type commonType(const QVariant v1, const QVariant v2) const; + + QValueList<QVariant> m_parts; + uint m_start; + bool m_error; + uint m_errorPosition; + +}; + +#endif + |