QGpCoreTools/ExpressionContext.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2007-04-20
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef EXPRESSIONCONTEXT_H
00029 #define EXPRESSIONCONTEXT_H
00030 
00031 #include <QtCore>
00032 
00033 #include "QGpCoreToolsDLLExport.h"
00034 
00035 namespace QGpCoreTools {
00036 
00037 class ExpressionStorage;
00038 class ExpressionAction;
00039 
00040 class QGPCORETOOLS_EXPORT ExpressionContext
00041 {
00042 public:
00043   ExpressionContext(ExpressionContext * parent=0) {_parent=parent;}
00044   virtual ~ExpressionContext();
00045 
00046   void addVariable(const QString& name, const QVariant& val) {addVariable(name, "0", val);}
00047   void addVariable(const QString& name, const QString& index, const QVariant& val);
00048   int addVariable(const QString& name, ExpressionStorage * var);
00049 
00050   QStringList variables() const;
00051   bool isValidVariable(const QString& name) const;
00052   QVariant variableValue(const QString& name, const QString& index=QString::null) const;
00053   ExpressionStorage * variable(int varIndex) const {return _varValues[varIndex];}
00054 
00055   virtual QStringList functions() const;
00056   virtual bool isValidFunction(const QString& name) const;
00057   virtual QVariant functionValue(const QString& name, const QVector<ExpressionAction *>& args) const;
00058 private:
00059   ExpressionContext * _parent;
00060   QMap<QString, int> _varNames;
00061   QVector<ExpressionStorage *> _varValues;
00062 };
00063 
00064 } // namespace QGpCoreTools
00065 
00066 #endif // EXPRESSIONCONTEXT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines