Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2007 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef MARSYAS_EXPR_H 00020 #define MARSYAS_EXPR_H 00021 00022 #include <string> 00023 00024 namespace Marsyas 00025 { 00039 class ExNode; 00040 class Expr; 00049 class Ex { 00050 std::string init_; std::string expr_; 00051 public: 00052 Ex(std::string e) { init_=""; expr_=e; }; 00053 Ex(std::string i, std::string e) { init_=i; expr_=e; }; 00054 void parse(Expr* e, ExNode*& init, ExNode*& expr); 00055 }; 00069 class Rp : public Ex { 00070 public: 00071 Rp(std::string e) : Ex(e,"") {}; 00072 Rp(std::string e, std::string r) : Ex(e,r) {}; 00073 }; 00090 class ExFile { 00091 std::string iex_, ex_, rp_, rr_; 00092 bool file_read_; 00093 void read(std::string fname); 00094 void store(int pos, std::string data); 00095 public: 00096 ExFile(std::string n) { file_read_=false; read(n); } 00097 Ex getEx() { return Ex(iex_,ex_); } 00098 Rp getRp() { return Rp(rp_,rr_); } 00099 }; 00100 00101 class ExRecord; 00102 class MarSystem; 00103 class Scheduler; 00104 class TmTimer; 00105 00113 class Expr { 00114 friend class Ex; 00115 bool initialized_; 00116 ExRecord* symbol_table_; 00117 ExNode* init_expr_; ExNode* expr_; 00118 ExNode* rept_; ExNode* rate_; 00119 00120 MarSystem* marsym_; Scheduler* sched_; TmTimer* timer_; 00121 00122 void set(MarSystem* m, Ex& e, Rp& r); 00123 00124 public: 00125 Expr(); 00126 Expr(MarSystem* msym, Ex e); // repeat_ evaluates to false 00127 Expr(MarSystem* msym, Ex e, Rp r); 00128 Expr(MarSystem* msym, ExFile e); 00129 00130 virtual ~Expr(); 00131 00132 virtual void eval(); // evaluate expression_ for side effects 00133 virtual bool repeat(); // evaluate repeat_ expression, return result 00134 std::string repeat_interval(); 00135 bool has_rate() { return rate_!=NULL; } 00136 00137 void setScheduler(Scheduler* v); 00138 void setTimer(TmTimer* t); 00139 void post(); 00140 }; 00141 00142 }//namespace Marsyas 00143 00144 #endif 00145