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