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