00001 #include <CLAM/TypedInControlRegistry.hxx> 00002 #include <CLAM/BaseTypedInControl.hxx> 00003 #include <CLAM/Assert.hxx> 00004 00005 namespace CLAM 00006 { 00007 std::string TypedInControlRegistry::AvailableNames() const 00008 { 00009 std::string result; 00010 std::string separator = ""; 00011 for (ConstIterator it=mTypedInControls.begin(); it!=mTypedInControls.end(); it++) 00012 { 00013 BaseTypedInControl & control = *(*it); 00014 result += separator + "'" + control.GetName() + "'"; 00015 separator = ","; 00016 } 00017 return result; 00018 } 00019 00020 BaseTypedInControl& TypedInControlRegistry::Get(const std::string & name) const 00021 { 00022 ConstIterator it; 00023 for (it=mTypedInControls.begin(); it!=mTypedInControls.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 *(BaseTypedInControl*)NULL; // just to get rid of warnings 00032 } 00033 00034 BaseTypedInControl& TypedInControlRegistry::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 *mTypedInControls.at(index); 00040 } 00041 00042 bool TypedInControlRegistry::Has(const std::string& name) const 00043 { 00044 ConstIterator it; 00045 for (it=mTypedInControls.begin(); it!=mTypedInControls.end(); it++) 00046 if(name == (*it)->GetName()) 00047 return true; 00048 00049 return false; 00050 } 00051 00052 int TypedInControlRegistry::Size() const 00053 { 00054 return mTypedInControls.size(); 00055 } 00056 TypedInControlRegistry::Iterator TypedInControlRegistry::Begin() 00057 { 00058 return mTypedInControls.begin(); 00059 } 00060 00061 TypedInControlRegistry::Iterator TypedInControlRegistry::End() 00062 { 00063 return mTypedInControls.end(); 00064 } 00065 00066 TypedInControlRegistry::ConstIterator TypedInControlRegistry::Begin() const 00067 { 00068 return mTypedInControls.begin(); 00069 } 00070 00071 TypedInControlRegistry::ConstIterator TypedInControlRegistry::End() const 00072 { 00073 return mTypedInControls.end(); 00074 } 00075 00076 void TypedInControlRegistry::ProcessingInterface_Register( BaseTypedInControl * in ) 00077 { 00078 mTypedInControls.push_back( in ); 00079 } 00080 00081 void TypedInControlRegistry::ProcessingInterface_Unregister( BaseTypedInControl * in ) 00082 { 00083 for (Iterator it=mTypedInControls.begin(); it!=mTypedInControls.end(); it++) 00084 { 00085 if (*it==in) 00086 { 00087 // std::cout << "Removing in control "<< in << std::endl; 00088 mTypedInControls.erase(it); 00089 return; 00090 } 00091 } 00092 } 00093 00094 00095 } // namespace CLAM