CLAM-Development  1.4.0
InPortRegistry.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "InPortRegistry.hxx"
23 #include "InPort.hxx"
24 
25 namespace CLAM
26 {
27 
29 {
30  CLAM_ASSERT(index>=0, "index for Port must be >=0");
31  CLAM_ASSERT(index<Size(), "index for Port must be < than Size");
32 
33  return *mInPorts[index];
34 }
35 
36 InPortBase& InPortRegistry::Get(const std::string & name) const
37 {
38  ConstIterator it;
39  for (it=mInPorts.begin(); it!=mInPorts.end(); it++)
40  if(name == (*it)->GetName())
41  return **it;
42 
43  std::string error =
44  "No in port named '" + name + "'.\nTry with: " + AvailableNames();
45  CLAM_ASSERT( false, error.c_str() );
46 
47  return *(InPortBase*)NULL; // just to get rid of warnings
48 }
49 
50 bool InPortRegistry::Has(const std::string& name) const
51 {
52  ConstIterator it;
53  for (it=mInPorts.begin(); it!=mInPorts.end(); it++)
54  if(name == (*it)->GetName())
55  return true;
56 
57  return false;
58 }
59 
61 {
62  return mInPorts.size();
63 }
64 
66 {
67  return mInPorts.begin();
68 }
69 
71 {
72  return mInPorts.end();
73 }
74 
76 {
77  return mInPorts.begin();
78 }
79 
81 {
82  return mInPorts.end();
83 }
84 
86 {
87  Iterator in;
88  for ( in=mInPorts.begin(); in!=mInPorts.end(); in++)
89  if (!(*in)->CanConsume()) return false;
90 
91  return true;
92 }
93 
95 {
96  mInPorts.push_back( in );
97 }
98 
100 {
101  for (Iterator it=mInPorts.begin(); it!=mInPorts.end(); it++)
102  {
103  if (*it==in)
104  {
105  mInPorts.erase(it);
106  return;
107  }
108  }
109 }
110 
111 std::string InPortRegistry::AvailableNames() const
112 {
113  std::string result;
114  std::string separator = "";
115  for (ConstIterator it=mInPorts.begin(); it!=mInPorts.end(); it++)
116  {
117  InPortBase & port = *(*it);
118  result += separator + "'" + port.GetName() + "'";
119  separator = ",";
120  }
121  return result;
122 }
123 } // namespace CLAM
124