File indexing completed on 2024-05-12 05:39:28
0001 /*************************************************************************** 0002 * Copyright (C) 2014 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * This file is part of DiceParser * 0006 * * 0007 * DiceParser is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (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, write to the * 0019 * Free Software Foundation, Inc., * 0020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0021 ***************************************************************************/ 0022 #ifndef SCALAROPERATORNODE_H 0023 #define SCALAROPERATORNODE_H 0024 0025 #include <QChar> 0026 #include <QMap> 0027 0028 #include "die.h" 0029 #include "executionnode.h" 0030 #include "result/scalarresult.h" 0031 0032 /** 0033 * @brief The ScalarOperatorNode class 0034 */ 0035 class ScalarOperatorNode : public ExecutionNode 0036 { 0037 public: 0038 /** 0039 * @brief The ArithmeticOperator enum 0040 */ 0041 // enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION}; 0042 /** 0043 * @brief ScalarOperatorNode 0044 */ 0045 ScalarOperatorNode(); 0046 /** 0047 * @brief ~ScalarOperatorNode 0048 */ 0049 virtual ~ScalarOperatorNode(); 0050 /** 0051 * @brief run 0052 */ 0053 virtual void run(ExecutionNode*); 0054 /** 0055 * @brief setInternalNode 0056 * @param node 0057 */ 0058 void setInternalNode(ExecutionNode* node); 0059 /** 0060 * @brief toString 0061 * @param wl 0062 * @return 0063 */ 0064 virtual QString toString(bool wl) const; 0065 /** 0066 * @brief getPriority 0067 * @return 0068 */ 0069 virtual qint64 getPriority() const; 0070 /** 0071 * @brief generateDotTree 0072 * @param s 0073 */ 0074 void generateDotTree(QString& s); 0075 /** 0076 * @brief getErrorList 0077 * @return 0078 */ 0079 virtual QMap<Dice::ERROR_CODE, QString> getExecutionErrorMap(); 0080 /** 0081 * @brief getArithmeticOperator 0082 * @return 0083 */ 0084 Dice::ArithmeticOperator getArithmeticOperator() const; 0085 /** 0086 * @brief setArithmeticOperator 0087 * @param arithmeticOperator 0088 */ 0089 void setArithmeticOperator(const Dice::ArithmeticOperator& arithmeticOperator); 0090 0091 /** 0092 * @brief getCopy 0093 * @return 0094 */ 0095 virtual ExecutionNode* getCopy() const; 0096 0097 private: 0098 /** 0099 * @brief add 0100 * @return 0101 */ 0102 static qint64 add(qreal, qreal); 0103 /** 0104 * @brief substract 0105 * @return 0106 */ 0107 static qint64 substract(qreal, qreal); 0108 /** 0109 * @brief divide not static because of error management 0110 * @return 0111 */ 0112 qreal divide(qreal, qreal); 0113 /** 0114 * @brief multiple 0115 * @return 0116 */ 0117 static qint64 multiple(qreal, qreal); 0118 0119 static qint64 pow(qreal a, qreal b); 0120 0121 private: 0122 ExecutionNode* m_internalNode; 0123 ScalarResult* m_scalarResult; 0124 Dice::ArithmeticOperator m_arithmeticOperator; 0125 }; 0126 0127 #endif // SCALAROPERATORNODE_H