1 /* 2 GUIDO Library 3 Copyright (C) 2008 Grame 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France 20 research@grame.fr 21 22 */ 23 24 #ifndef __guidoExpReader__ 25 #define __guidoExpReader__ 26 27 #include <ostream> 28 #include <stack> 29 30 #include "guidoExprTypes.h" 31 #include "visitor.h" 32 33 namespace guidolang 34 { 35 36 //______________________________________________________________________________ 37 /*! 38 \brief a guido language expression printer 39 */ 40 class export guidoExpPrinter : 41 public guido::visitor<Sguidoexpression>, 42 public guido::visitor<SguidoNamedExpr>, 43 public guido::visitor<SguidoGroupedExpr>, 44 public guido::visitor<SguidoAbstractExpr>, 45 public guido::visitor<SguidoIdentExpr>, 46 public guido::visitor<SguidoScoreExpr> 47 { 48 private: 49 bool fInNamed; 50 std::ostream& fOut; ///< the output stream 51 std::stack<const char *> fPendingOp; ///< the pending operations names 52 53 public: guidoExpPrinter(std::ostream & out)54 guidoExpPrinter(std::ostream& out) : fInNamed(false), fOut(out) {} ~guidoExpPrinter()55 virtual ~guidoExpPrinter() {} 56 57 protected: 58 virtual void visitStart( Sguidoexpression&); 59 virtual void visitStart( SguidoNamedExpr&); 60 virtual void visitEnd ( SguidoNamedExpr&); 61 virtual void visitStart( SguidoGroupedExpr&); 62 virtual void visitEnd ( SguidoGroupedExpr&); 63 virtual void visitStart( SguidoAbstractExpr&); 64 virtual void visitStart( SguidoScoreExpr&); 65 virtual void visitStart( SguidoIdentExpr&); 66 67 void checkOp (bool pop=true); // check if operation need to be flushed 68 void push (const char *); // push operation name on a stack 69 void stackPrint (); 70 }; 71 72 } // namespace 73 74 #endif 75