00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #ifndef _OutControl_ 00023 #define _OutControl_ 00024 00025 #include <string> 00026 #include <list> 00027 #include <typeinfo> 00028 #include "Assert.hxx" 00029 #include "InControl.hxx" 00030 #include "OutControlBase.hxx" 00031 00032 namespace CLAM { 00033 class Processing; 00034 00039 template<class ControlDataType> 00040 class OutControl : public OutControlBase 00041 { 00042 // This is required to solve the parsing problem with iterators. 00043 typedef InControl<ControlDataType> PeerInControl; 00044 typedef std::list< PeerInControl * > ProperInControlList; 00045 00046 00047 public: 00048 OutControl(const std::string &name = "unnamed typed in control", Processing * proc = 0); 00049 00050 void SendControl(const ControlDataType& val); 00051 bool IsLinkable(const InControlBase& in); 00052 virtual const std::type_info & GetTypeId() const 00053 { 00054 return typeid(ControlDataType); 00055 }; 00056 }; 00057 00058 template<class ControlDataType> 00059 OutControl<ControlDataType>::OutControl(const std::string &name, Processing * proc) 00060 : OutControlBase(name,proc) 00061 { 00062 } 00063 00064 template<class ControlDataType> 00065 void OutControl<ControlDataType>::SendControl(const ControlDataType& val) 00066 { 00067 typename std::list< InControlBase * >::iterator it; 00068 00069 for (it=mLinks.begin(); it!=mLinks.end(); it++) 00070 { 00071 InControl<ControlDataType>* control = static_cast<InControl<ControlDataType>*>(*it); 00072 control->DoControl(val); 00073 } 00074 } 00075 00076 template<class ControlDataType> 00077 bool OutControl<ControlDataType>::IsLinkable(const InControlBase& in) 00078 { 00079 return typeid(ControlDataType) == in.GetTypeId(); 00080 00081 } 00082 00083 typedef OutControl<float> FloatOutControl; 00084 00085 } // END NAMESPACE CLAM 00086 00087 00088 #endif //_OutControl_ 00089