00001 /* 00002 * Copyright (c) 2005 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 #include "OutPortRegistry.hxx" 00023 #include "OutPort.hxx" 00024 00025 namespace CLAM 00026 { 00027 00028 OutPortBase & OutPortRegistry::GetByNumber(int index) const 00029 { 00030 CLAM_ASSERT(index>=0, "index for Port must be >=0"); 00031 CLAM_ASSERT(index<Size(), "index for Port must be < than Size"); 00032 00033 return *mOutPorts[index]; 00034 } 00035 00036 OutPortBase & OutPortRegistry::Get(const std::string & name) const 00037 { 00038 ConstIterator it; 00039 for (it=mOutPorts.begin(); it!=mOutPorts.end(); it++) 00040 if (name == (*it)->GetName()) 00041 return **it; 00042 std::string error = 00043 "No out port named '" + name + "'.\nTry with: " + AvailableNames(); 00044 CLAM_ASSERT( false, error.c_str() ); 00045 00046 return *(OutPortBase*)NULL; // just to get rid of warnings 00047 } 00048 00049 bool OutPortRegistry::Has(const std::string& name) const 00050 { 00051 ConstIterator it; 00052 for (it=mOutPorts.begin(); it!=mOutPorts.end(); it++) 00053 if(name == (*it)->GetName()) 00054 return true; 00055 00056 return false; 00057 } 00058 00059 int OutPortRegistry::Size() const 00060 { 00061 return mOutPorts.size(); 00062 } 00063 00064 bool OutPortRegistry::AreReadyForWriting() 00065 { 00066 Iterator out; 00067 for ( out=mOutPorts.begin(); out!=mOutPorts.end(); out++) 00068 if (!(*out)->CanProduce()) return false; 00069 00070 return true; 00071 } 00072 00073 OutPortRegistry::Iterator OutPortRegistry::Begin() 00074 { 00075 return mOutPorts.begin(); 00076 } 00077 00078 OutPortRegistry::Iterator OutPortRegistry::End() 00079 { 00080 return mOutPorts.end(); 00081 } 00082 00083 OutPortRegistry::ConstIterator OutPortRegistry::Begin() const 00084 { 00085 return mOutPorts.begin(); 00086 } 00087 00088 OutPortRegistry::ConstIterator OutPortRegistry::End() const 00089 { 00090 return mOutPorts.end(); 00091 } 00092 00093 void OutPortRegistry::ProcessingInterface_Register( OutPortBase * out ) 00094 { 00095 mOutPorts.push_back( out ); 00096 } 00097 00098 void OutPortRegistry::ProcessingInterface_Unregister( OutPortBase * out ) 00099 { 00100 for (Iterator it=mOutPorts.begin(); it!=mOutPorts.end(); it++) 00101 { 00102 if (*it==out) 00103 { 00104 mOutPorts.erase(it); 00105 return; 00106 } 00107 } 00108 } 00109 00110 std::string OutPortRegistry::AvailableNames() const 00111 { 00112 std::string result; 00113 std::string separator = ""; 00114 for (ConstIterator it=mOutPorts.begin(); it!=mOutPorts.end(); it++) 00115 { 00116 OutPortBase & port = *(*it); 00117 result += separator + "'" + port.GetName() + "'"; 00118 separator = ","; 00119 } 00120 return result; 00121 } 00122 }// namespace CLAM 00123