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 PARSINGTOOLFORMULA_H
0021 #define PARSINGTOOLFORMULA_H
0022 
0023 #include <QHash>
0024 #include <QString>
0025 
0026 #include "nodes/formulanode.h"
0027 #include "nodes/scalaroperatorfnode.h"
0028 namespace Formula
0029 {
0030 /**
0031  * @brief The ParsingToolFormula class provides methods for parsing formula.
0032  */
0033 class ParsingToolFormula
0034 {
0035 public:
0036     enum FormulaOperator
0037     {
0038         ABS,
0039         MIN,
0040         MAX,
0041         FLOOR,
0042         CEIL,
0043         AVG,
0044         CONCAT
0045     }; //,IF
0046     /**
0047      * @brief ParsingToolFormula
0048      */
0049     ParsingToolFormula();
0050     ~ParsingToolFormula();
0051     /**
0052      * @brief readFormula
0053      * @return
0054      */
0055     bool readFormula(QString&, FormulaNode*&);
0056     /**
0057      * @brief readScalarOperator
0058      * @return
0059      */
0060     bool readScalarOperator(QString&, FormulaNode*);
0061     /**
0062      * @brief readOperand
0063      * @return
0064      */
0065     bool readOperand(QString&, FormulaNode*&);
0066     /**
0067      * @brief readOperator
0068      * @return
0069      */
0070     bool readOperator(QString&, FormulaNode*&);
0071     /**
0072      * @brief readFieldRef
0073      * @return
0074      */
0075     bool readFieldRef(QString&, FormulaNode*&);
0076     /**
0077      * @brief readNumber
0078      * @return
0079      */
0080     bool readNumber(QString&, FormulaNode*&);
0081 
0082     FormulaNode* getLatestNode(FormulaNode* node);
0083 
0084     const QHash<QString, QString> getVariableHash() const;
0085     void setVariableHash(const QHash<QString, QString>& variableHash);
0086 
0087     bool readStringValue(QString& str, FormulaNode*& previous);
0088     bool readParenthese(QString& str, FormulaNode*& previous);
0089 
0090 private:
0091     QHash<QString, QString> m_variableHash;
0092 
0093     std::map<QString, ParsingToolFormula::FormulaOperator> m_hashOp;
0094     std::map<QString, ScalarOperatorFNode::ArithmeticOperator> m_arithmeticOperation;
0095 };
0096 } // namespace Formula
0097 #endif // PARSINGTOOLFORMULA_H