00001 #include <CLAM/TypedOutControlRegistry.hxx> 00002 #include <CLAM/BaseTypedOutControl.hxx> 00003 #include <CLAM/Assert.hxx> 00004 00005 namespace CLAM 00006 { 00007 std::string TypedOutControlRegistry::AvailableNames() const 00008 { 00009 std::string result; 00010 std::string separator = ""; 00011 for (ConstIterator it=mTypedOutControls.begin(); it!=mTypedOutControls.end(); it++) 00012 { 00013 BaseTypedOutControl & control = *(*it); 00014 result += separator + "'" + control.GetName() + "'"; 00015 separator = ","; 00016 } 00017 return result; 00018 } 00019 00020 BaseTypedOutControl& TypedOutControlRegistry::Get(const std::string & name) const 00021 { 00022 ConstIterator it; 00023 for (it=mTypedOutControls.begin(); it!=mTypedOutControls.end(); it++) 00024 if (name == (*it)->GetName()) 00025 return **it; 00026 00027 std::string error = 00028 "No typed in control named '" + name + "'.\nTry with: " + AvailableNames(); 00029 CLAM_ASSERT( false, error.c_str() ); 00030 00031 return *(BaseTypedOutControl*)NULL; // just to get rid of warnings 00032 } 00033 00034 BaseTypedOutControl& TypedOutControlRegistry::GetByNumber(int index) const 00035 { 00036 CLAM_ASSERT(index>=0, "index for Control must be >=0"); 00037 CLAM_ASSERT(index<Size(), "index for Control must be < than Size"); 00038 00039 return *mTypedOutControls.at(index); 00040 } 00041 00042 bool TypedOutControlRegistry::Has(const std::string& name) const 00043 { 00044 ConstIterator it; 00045 for (it=mTypedOutControls.begin(); it!=mTypedOutControls.end(); it++) 00046 if(name == (*it)->GetName()) 00047 return true; 00048 00049 return false; 00050 } 00051 00052 int TypedOutControlRegistry::Size() const 00053 { 00054 return mTypedOutControls.size(); 00055 } 00056 TypedOutControlRegistry::Iterator TypedOutControlRegistry::Begin() 00057 { 00058 return mTypedOutControls.begin(); 00059 } 00060 00061 TypedOutControlRegistry::Iterator TypedOutControlRegistry::End() 00062 { 00063 return mTypedOutControls.end(); 00064 } 00065 00066 TypedOutControlRegistry::ConstIterator TypedOutControlRegistry::Begin() const 00067 { 00068 return mTypedOutControls.begin(); 00069 } 00070 00071 TypedOutControlRegistry::ConstIterator TypedOutControlRegistry::End() const 00072 { 00073 return mTypedOutControls.end(); 00074 } 00075 void TypedOutControlRegistry::ProcessingInterface_Register( BaseTypedOutControl * in ) 00076 { 00077 mTypedOutControls.push_back( in ); 00078 } 00079 00080 void TypedOutControlRegistry::ProcessingInterface_Unregister( BaseTypedOutControl * out ) 00081 { 00082 for (Iterator it=mTypedOutControls.begin(); it!=mTypedOutControls.end(); it++) 00083 { 00084 if (*it==out) 00085 { 00086 // std::cout << "Removing out control "<< out << std::endl; 00087 mTypedOutControls.erase(it); 00088 return; 00089 } 00090 } 00091 } 00092 } // namespace CLAM