File indexing completed on 2025-01-19 06:54:45
0001 // arith-exp.h - class to compile and evaluate logical/arithmetical expressions 0002 // 0003 /* 0004 Copyright 2005-2011 Tomas Mecir <kmuddy@kmuddy.com> 0005 Copyright 2005 Alex Bache <alexbache@ntlworld.com> 0006 0007 This program is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU General Public License as 0009 published by the Free Software Foundation; either version 2 of 0010 the License, or (at your option) any later version. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #ifndef ARITH_EXP_H 0022 #define ARITH_EXP_H 0023 0024 #include <qstring.h> 0025 #include <list> 0026 0027 #include <kmuddy_export.h> 0028 0029 #include "instructions.h" 0030 0031 using namespace std; 0032 0033 0034 //*************************************************************** 0035 // Pure virtual base class for supplying variable values and 0036 // function call results 0037 //*************************************************************** 0038 0039 class KMUDDY_EXPORT arith_exp_server 0040 { 0041 public: 0042 virtual ~arith_exp_server(); 0043 0044 // implement this function in your derived class 0045 virtual cValue get (QString var_name) = 0; 0046 0047 // implement this function in your derived class 0048 virtual cValue function_call(const QString &function_name, 0049 list<cValue> &arguments) = 0; 0050 0051 }; // arith_exp_server 0052 0053 0054 0055 //*************************************************************** 0056 // Class to compile and evaluate logical/arithmetical expressions 0057 //*************************************************************** 0058 0059 class KMUDDY_EXPORT arith_exp 0060 { 0061 private: 0062 list<instruction> compiled_code; 0063 0064 // Free resources used to store compiled code 0065 void clear_compiled(); 0066 0067 public: 0068 ~arith_exp(); 0069 0070 // Compiles an expression, returns true if successful 0071 bool compile (const QString &expression); 0072 0073 // Returns result of executing compiled expression 0074 cValue evaluate(arith_exp_server *resolver); 0075 0076 }; // arith_exp 0077 0078 0079 0080 #endif // ARITH_EXP_H