CLAM-Development  1.4.0
OutControlRegistry.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 "OutControlRegistry.hxx"
23 #include "OutControl.hxx"
24 
25 namespace CLAM
26 {
27 
29 {
30  CLAM_ASSERT(index>=0, "index for Control must be >=0");
31  CLAM_ASSERT(index<Size(), "index for Control must be < than Size");
32 
33  return *mOutControls[index];
34 }
35 
36 OutControlBase& OutControlRegistry::Get(const std::string & name) const
37 {
38  ConstIterator it;
39  for (it=mOutControls.begin(); it!=mOutControls.end(); it++)
40  if (name == (*it)->GetName())
41  return **it;
42 
43  std::string error =
44  "No out control named '" + name + "'.\nTry with: " + AvailableNames();
45  CLAM_ASSERT( false, error.c_str() );
46 
47  return *(OutControlBase*)NULL; // Just to get rid of warnings
48 }
49 
50 bool OutControlRegistry::Has(const std::string& name) const
51 {
52  ConstIterator it;
53  for (it=mOutControls.begin(); it!=mOutControls.end(); it++)
54  if(name == (*it)->GetName())
55  return true;
56 
57  return false;
58 }
59 
61 {
62  return mOutControls.size();
63 }
64 
66 {
67  return mOutControls.begin();
68 }
69 
71 {
72  return mOutControls.end();
73 }
74 
76 {
77  return mOutControls.begin();
78 }
79 
81 {
82  return mOutControls.end();
83 }
84 
86 {
87  mOutControls.push_back( out );
88 }
89 
91 {
92  for (Iterator it=mOutControls.begin(); it!=mOutControls.end(); it++)
93  {
94  if (*it==out)
95  {
96  //std::cout << "Removing out control "<< out << std::endl;
97  mOutControls.erase(it);
98  return;
99  }
100  }
101 }
102 
103 
104 std::string OutControlRegistry::AvailableNames() const
105 {
106  std::string result;
107  std::string separator = "";
108  for (ConstIterator it=mOutControls.begin(); it!=mOutControls.end(); it++)
109  {
110  OutControlBase & control = *(*it);
111  result += separator + "'" + control.GetName() + "'";
112  separator = ",";
113  }
114  return result;
115 }
116 } // namespace CLAM
117