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 #include "parenthesesnode.h" 0023 0024 ParenthesesNode::ParenthesesNode() : m_internalNode(nullptr) {} 0025 void ParenthesesNode::setInternelNode(ExecutionNode* node) 0026 { 0027 m_internalNode= node; 0028 } 0029 void ParenthesesNode::run(ExecutionNode* previous) 0030 { 0031 m_previousNode= previous; 0032 if(nullptr != m_internalNode) 0033 { 0034 m_internalNode->run(this); 0035 ExecutionNode* temp= m_internalNode; 0036 while(nullptr != temp->getNextNode()) 0037 { 0038 temp= temp->getNextNode(); 0039 } 0040 m_result= temp->getResult(); 0041 } 0042 0043 if(nullptr != m_nextNode) 0044 { 0045 m_nextNode->run(this); 0046 } 0047 } 0048 QString ParenthesesNode::toString(bool b) const 0049 { 0050 if(b) 0051 { 0052 return QString("%1 [label=\"ParenthesesNode\"]").arg(m_id); 0053 } 0054 else 0055 { 0056 return m_id; 0057 } 0058 } 0059 qint64 ParenthesesNode::getPriority() const 0060 { 0061 qint64 priority= 3; 0062 return priority; 0063 } 0064 ExecutionNode* ParenthesesNode::getCopy() const 0065 { 0066 ParenthesesNode* node= new ParenthesesNode(); 0067 if(nullptr != m_internalNode) 0068 { 0069 node->setInternelNode(m_internalNode->getCopy()); 0070 } 0071 if(nullptr != m_nextNode) 0072 { 0073 node->setNextNode(m_nextNode->getCopy()); 0074 } 0075 return node; 0076 } 0077 0078 void ParenthesesNode::generateDotTree(QString& s) 0079 { 0080 auto str= toString(true); 0081 if(s.contains(str)) 0082 return; 0083 s.append(str); 0084 s.append(";\n"); 0085 0086 if(nullptr != m_internalNode) 0087 { 0088 s.append(toString(false)); 0089 s.append(" -> "); 0090 s.append(m_internalNode->toString(false)); 0091 s.append("[label=\"internal\"];\n"); 0092 m_internalNode->generateDotTree(s); 0093 } 0094 0095 if(nullptr != m_nextNode) 0096 { 0097 s.append(toString(false)); 0098 s.append(" -> "); 0099 s.append(m_nextNode->toString(false)); 0100 s.append(" [label=\"next\"];\n"); 0101 // s.append(" [label=\"nextNode\"];\n"); 0102 m_nextNode->generateDotTree(s); 0103 } 0104 else 0105 { 0106 s.append(toString(false)); 0107 s.append(" -> "); 0108 s.append("nullptr;\n"); 0109 } 0110 if(nullptr != m_result) 0111 { 0112 s.append(toString(false)); 0113 s.append(" ->"); 0114 s.append(m_result->toString(false)); 0115 s.append(" [label=\"Result\", style=\"dashed\"];\n"); 0116 if(nullptr == m_nextNode) 0117 m_result->generateDotTree(s); 0118 } 0119 }