CLAM-Development  1.4.0
OutPortRegistry.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 "OutPortRegistry.hxx"
23 #include "OutPort.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 *mOutPorts[index];
34 }
35 
36 OutPortBase & OutPortRegistry::Get(const std::string & name) const
37 {
38  ConstIterator it;
39  for (it=mOutPorts.begin(); it!=mOutPorts.end(); it++)
40  if (name == (*it)->GetName())
41  return **it;
42  std::string error =
43  "No out port named '" + name + "'.\nTry with: " + AvailableNames();
44  CLAM_ASSERT( false, error.c_str() );
45 
46  return *(OutPortBase*)NULL; // just to get rid of warnings
47 }
48 
49 bool OutPortRegistry::Has(const std::string& name) const
50 {
51  ConstIterator it;
52  for (it=mOutPorts.begin(); it!=mOutPorts.end(); it++)
53  if(name == (*it)->GetName())
54  return true;
55 
56  return false;
57 }
58 
60 {
61  return mOutPorts.size();
62 }
63 
65 {
66  Iterator out;
67  for ( out=mOutPorts.begin(); out!=mOutPorts.end(); out++)
68  if (!(*out)->CanProduce()) return false;
69 
70  return true;
71 }
72 
74 {
75  return mOutPorts.begin();
76 }
77 
79 {
80  return mOutPorts.end();
81 }
82 
84 {
85  return mOutPorts.begin();
86 }
87 
89 {
90  return mOutPorts.end();
91 }
92 
94 {
95  mOutPorts.push_back( out );
96 }
97 
99 {
100  for (Iterator it=mOutPorts.begin(); it!=mOutPorts.end(); it++)
101  {
102  if (*it==out)
103  {
104  mOutPorts.erase(it);
105  return;
106  }
107  }
108 }
109 
110 std::string OutPortRegistry::AvailableNames() const
111 {
112  std::string result;
113  std::string separator = "";
114  for (ConstIterator it=mOutPorts.begin(); it!=mOutPorts.end(); it++)
115  {
116  OutPortBase & port = *(*it);
117  result += separator + "'" + port.GetName() + "'";
118  separator = ",";
119  }
120  return result;
121 }
122 }// namespace CLAM
123