File indexing completed on 2024-05-12 05:39:42
0001 /*************************************************************************** 0002 * Copyright (C) 2016 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef FORMULAMANAGER_H 0021 #define FORMULAMANAGER_H 0022 0023 #include <QHash> 0024 #include <QObject> 0025 #include <QString> 0026 #include <QVariant> 0027 0028 #include <charactersheet_formula/formula_global.h> 0029 /** 0030 * @page FormulaManager Formula Manager 0031 * 0032 * @section Intro Introduction 0033 * FormulaManager is the software component dedicated to compute charactersheet formula in rolisteam.<br/> 0034 * 0035 * @section grammar The Grammar 0036 * 0037 * The grammar looks like this: 0038 * 0039 * Formula =: Operand | ScalarOperator Operand<br/> 0040 * Operand =: number | Field Ref | operator <br/> 0041 * Field Ref =: ${[A-z[A-z|0-9]+}<br/> 0042 * Operator =: [abs | min | max | floor | ceil | avg](Formula[,Formula]*) 0043 * ScalarOperator =: [x,-,*,/]<br/> 0044 * number =: [0-9]+<br/> 0045 * Word =: [A-z]+<br/> 0046 * 0047 */ 0048 0049 /** 0050 * Formala namespace is gathering all classes required for formula management. 0051 */ 0052 namespace Formula 0053 { 0054 class ParsingToolFormula; 0055 class StartNode; 0056 /** 0057 * @brief The FormulaManager class 0058 */ 0059 class CHARACTERSHEET_FORMULA_EXPORT FormulaManager 0060 { 0061 public: 0062 FormulaManager(); 0063 ~FormulaManager(); 0064 0065 QVariant getValue(QString i); 0066 void setConstantHash(const QHash<QString, QString>& hash); 0067 0068 protected: 0069 bool parseLine(QString& str); 0070 QVariant startComputing(); 0071 0072 bool readFormula(QString& str); 0073 0074 private: 0075 QString m_formula; 0076 ParsingToolFormula* m_parsingTool; 0077 StartNode* m_startingNode; 0078 }; 0079 } // namespace Formula 0080 #endif // FORMULAMANAGER_H