1 /* 2 * The Doomsday Engine Project -- libcore 3 * 4 * Copyright © 2004-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 5 * 6 * @par License 7 * LGPL: http://www.gnu.org/licenses/lgpl.html 8 * 9 * <small>This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU Lesser General Public License as published by 11 * the Free Software Foundation; either version 3 of the License, or (at your 12 * option) any later version. This program is distributed in the hope that it 13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 15 * General Public License for more details. You should have received a copy of 16 * the GNU Lesser General Public License along with this program; if not, see: 17 * http://www.gnu.org/licenses</small> 18 */ 19 20 #ifndef LIBDENG2_IFSTATEMENT_H 21 #define LIBDENG2_IFSTATEMENT_H 22 23 #include "../Statement" 24 #include "../Compound" 25 26 #include <list> 27 28 namespace de { 29 30 class Expression; 31 32 /** 33 * Branching statement for conditionally executing one or more compounds. 34 * 35 * @ingroup script 36 */ 37 class IfStatement : public Statement 38 { 39 public: 40 ~IfStatement(); 41 42 void clear(); 43 44 /** 45 * Add a new branch to the statement. 46 */ 47 void newBranch(); 48 49 /** 50 * Sets the condition expression of the latest branch. 51 */ 52 void setBranchCondition(Expression *expression); 53 54 /** 55 * Returns the compound of the latest branch. 56 */ 57 Compound &branchCompound(); 58 59 /** 60 * Returns the else-compound of the statement. 61 */ elseCompound()62 Compound &elseCompound() { 63 return _elseCompound; 64 } 65 66 void execute(Context &context) const; 67 68 // Implements ISerializable. 69 void operator >> (Writer &to) const; 70 void operator << (Reader &from); 71 72 private: 73 struct Branch { 74 Expression *condition; 75 Compound *compound; 76 Branch(Compound *c = 0) : condition(0), compound(c) {} 77 }; 78 typedef std::list<Branch> Branches; 79 80 Branches _branches; 81 Compound _elseCompound; 82 }; 83 84 } // namespace de 85 86 #endif /* LIBDENG2_IFSTATEMENT_H */ 87