File indexing completed on 2024-04-14 04:48:54

0001 /*
0002     This file belong to the KMPlayer project, a movie player plugin for Konqueror
0003     SPDX-FileCopyrightText: 2009 Koos Vriezen <koos.vriezen@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef _KMPLAYER_EXPRESSION_H_
0009 #define _KMPLAYER_EXPRESSION_H_
0010 
0011 #include "kmplayerplaylist.h"
0012 
0013 namespace KMPlayer {
0014 
0015 class NodeValue {
0016 public:
0017     NodeValue (Node *n, Attribute *a=nullptr) : node (n), attr (a) {}
0018     NodeValue (const QString &s) : node (nullptr), attr (nullptr), string (s) {}
0019 
0020     QString value () const;
0021     bool operator ==(const NodeValue& v) const {
0022         return (node && node == v.node && attr == v.attr)
0023             || (!node && string == v.string);
0024     }
0025 
0026     Node *node;
0027     Attribute *attr;
0028     QString string;
0029 };
0030 
0031 class ExprIterator;
0032 
0033 class Expression : public VirtualVoid {
0034 public:
0035     class iterator {
0036         mutable ExprIterator* iter;
0037     public:
0038         iterator(ExprIterator* it=nullptr) : iter(it) {}
0039         iterator(const iterator& it) : iter(it.iter) { it.iter = nullptr; }
0040         ~iterator();
0041         iterator& operator =(const iterator& it);
0042         bool operator ==(const iterator& it) const;
0043         bool operator !=(const iterator& it) const { return !(*this == it); }
0044         iterator& operator ++();
0045         NodeValue& operator*();
0046         NodeValue* operator->();
0047     };
0048     virtual bool toBool () const = 0;
0049     virtual int toInt () const = 0;
0050     virtual float toFloat () const = 0;
0051     virtual QString toString () const = 0;
0052     virtual iterator begin() const = 0;
0053     virtual iterator end() const = 0;
0054     virtual void setRoot (Node *root) = 0;
0055 };
0056 
0057 Expression* evaluateExpr(const QByteArray& expr, const QString& root = QString());
0058 
0059 }
0060 
0061 #endif