Warning, file /rolisteam/rolisteam/src/libraries/charactersheet/src/formula/formulamanager.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 #include <charactersheet_formula/formulamanager.h> 0021 0022 #include "charactersheet_formula/nodes/formulanode.h" 0023 #include "charactersheet_formula/nodes/startnode.h" 0024 #include "charactersheet_formula/parsingtoolformula.h" 0025 0026 namespace Formula 0027 { 0028 0029 FormulaManager::FormulaManager() : m_startingNode(nullptr) 0030 { 0031 m_parsingTool= new ParsingToolFormula(); 0032 } 0033 FormulaManager::~FormulaManager() 0034 { 0035 if(nullptr != m_parsingTool) 0036 { 0037 delete m_parsingTool; 0038 } 0039 } 0040 0041 QVariant FormulaManager::getValue(QString i) 0042 { 0043 m_formula= i; 0044 if(parseLine(i)) 0045 { 0046 return startComputing(); 0047 } 0048 return QVariant(); 0049 } 0050 0051 bool FormulaManager::parseLine(QString& str) 0052 { 0053 return readFormula(str); 0054 } 0055 0056 QVariant FormulaManager::startComputing() 0057 { 0058 m_startingNode->run(nullptr); 0059 0060 FormulaNode* node= m_startingNode; 0061 while(nullptr != node->next()) 0062 { 0063 node= node->next(); 0064 } 0065 0066 QVariant var= node->getResult(); 0067 delete m_startingNode; 0068 return var; 0069 } 0070 0071 bool FormulaManager::readFormula(QString& str) 0072 { 0073 m_startingNode= new StartNode(); 0074 FormulaNode* node= nullptr; 0075 bool a= m_parsingTool->readFormula(str, node); 0076 0077 m_startingNode->setNext(node); 0078 return a; 0079 } 0080 void FormulaManager::setConstantHash(const QHash<QString, QString>& hash) 0081 { 0082 if(nullptr != m_parsingTool) 0083 { 0084 m_parsingTool->setVariableHash(hash); 0085 } 0086 } 0087 } // namespace Formula