Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2005 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 #include <marsyas/sched/TmControlValue.h> 00020 #include <marsyas/system/MarControlValue.h> 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 TmControlValue::TmControlValue() 00026 { 00027 type_ = tmcv_null; 00028 } 00029 00030 TmControlValue::TmControlValue(const TmControlValue& val) 00031 { 00032 type_=val.type_; 00033 r_=val.r_; 00034 n_=val.n_; 00035 b_=val.b_; 00036 s_=val.s_; 00037 ms_=val.ms_; 00038 } 00039 00040 TmControlValue::TmControlValue(double re) 00041 { 00042 r_ = (mrs_real)re; 00043 type_ = tmcv_real; 00044 } 00045 00046 TmControlValue::TmControlValue(float re) 00047 { 00048 r_ = (mrs_real)re; 00049 type_ = tmcv_real; 00050 } 00051 00052 TmControlValue::TmControlValue(int ne) 00053 { 00054 n_ = ne; 00055 type_ = tmcv_natural; 00056 } 00057 00058 TmControlValue::TmControlValue(long int ne) 00059 { 00060 n_ = ne; 00061 type_ = tmcv_natural; 00062 } 00063 00064 TmControlValue::TmControlValue(std::string st) 00065 { 00066 s_ = st; 00067 type_ = tmcv_string; 00068 } 00069 00070 TmControlValue::TmControlValue(const char *c) 00071 { 00072 s_ = c; 00073 type_ = tmcv_string; 00074 } 00075 00076 TmControlValue::TmControlValue(bool be) 00077 { 00078 b_ = be; 00079 type_ = tmcv_bool; 00080 } 00081 00082 TmControlValue::TmControlValue(MarSystem* me) 00083 { 00084 ms_ = me; 00085 type_ = tmcv_marsystem; 00086 } 00087 00088 mrs_real 00089 TmControlValue::toReal() 00090 { 00091 if(type_ != tmcv_real) { 00092 MRSWARN("MarControlValue::toReal Incorrect type"); 00093 return 0.0; 00094 } 00095 else 00096 return r_; 00097 } 00098 00099 bool 00100 TmControlValue::toBool() 00101 { 00102 if(type_ != tmcv_bool) { 00103 MRSWARN("MarControlValue::toBool Incorrect type"); 00104 return false; 00105 } 00106 else 00107 return b_; 00108 } 00109 00110 mrs_natural 00111 TmControlValue::toNatural() 00112 { 00113 if(type_ != tmcv_natural) { 00114 MRSWARN("MarControlValue::toNatural Incorrect type"); 00115 return 0; 00116 } 00117 else 00118 return n_; 00119 } 00120 00121 std::string 00122 TmControlValue::toString() 00123 { 00124 if(type_ != tmcv_string) { 00125 MRSWARN("MarControlValue::toString Incorrect type"); 00126 return ""; 00127 } 00128 else 00129 return s_; 00130 } 00131 00132 MarSystem* 00133 TmControlValue::toMarSystem() 00134 { 00135 if(type_ != tmcv_marsystem) { 00136 MRSWARN("MarControlValue::toMarSystem Incorrect type"); 00137 return NULL; 00138 } 00139 else 00140 return ms_; 00141 } 00142 00143 int 00144 TmControlValue::getType() 00145 { 00146 return type_; 00147 } 00148 00149 mrs_string 00150 TmControlValue::getSType() 00151 { 00152 mrs_string res; 00153 00154 if(getType() == tmcv_string) res = "mrs_string"; 00155 else if(getType() == tmcv_real) res = "mrs_real"; 00156 else if(getType() == tmcv_vec) res = "mrs_realvec"; 00157 else if(getType() == tmcv_natural) res = "mrs_natural"; 00158 else if(getType() == tmcv_bool) res = "mrs_bool"; 00159 else if(getType() == tmcv_marsystem) res = "mrs_marsystem"; 00160 return res; 00161 } 00162 00163 namespace Marsyas { 00164 ostream& 00165 operator<<(ostream& o, const TmControlValue& m) 00166 { 00167 if(m.type_ == tmcv_string) o << m.s_; 00168 if(m.type_ == tmcv_real) o << m.r_; 00169 if(m.type_ == tmcv_natural) o << m.n_; 00170 if(m.type_ == tmcv_bool) o << m.b_; 00171 if(m.type_ == tmcv_marsystem) o << "MarSystem"; 00172 if(m.type_ == tmcv_vec) o << "realvec"; 00173 return o; 00174 } 00175 }