InPortRegistry.cxx

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