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