CLAM-Development
1.1
|
00001 #include "ControlPrinter.hxx" 00002 #include <iostream> 00003 #include <sstream> 00004 #include "ProcessingFactory.hxx" 00005 00006 00007 namespace CLAM 00008 { 00009 namespace Hidden 00010 { 00011 static const char * metadata[] = { 00012 "key", "ControlPrinter", 00013 "category", "Controls", 00014 "description", "ControlPrinter", 00015 0 00016 }; 00017 static FactoryRegistrator<ProcessingFactory, ControlPrinter> reg = metadata; 00018 } 00019 00020 void ControlPrinterConfig::DefaultInit() 00021 { 00022 AddAll(); 00023 UpdateData(); 00024 SetIdentifier( "ControlPrinter" ); 00025 SetNumberOfInputs(1.); 00026 SetGuiOnly(true); 00027 } 00028 00029 ControlPrinter::ControlPrinter() 00030 { 00031 Configure( mConfig ); 00032 } 00033 00034 ControlPrinter::ControlPrinter( const ControlPrinterConfig& cfg ) 00035 { 00036 Configure( cfg ); 00037 } 00038 ControlPrinter::~ControlPrinter() 00039 { 00040 RemoveOldControls(); 00041 } 00042 00043 bool ControlPrinter::ConcreteConfigure( const ProcessingConfig& cfg ) 00044 { 00045 RemoveOldControls(); 00046 00047 CopyAsConcreteConfig( mConfig, cfg ); 00048 00049 mConfig.AddAll(); 00050 mConfig.UpdateData(); 00051 00052 int nInputs = int(mConfig.GetNumberOfInputs()); 00053 if (nInputs < 1) 00054 { 00055 mConfig.SetNumberOfInputs(1.); 00056 nInputs = 1; 00057 } 00058 if (nInputs == 1) 00059 { 00060 // preserve old port name 00061 std::list<std::string> names; 00062 names.push_back("In Control"); 00063 mInControls.Resize(1, names, this); 00064 } 00065 else 00066 { 00067 // multi-port names share user-configured identifier 00068 mInControls.Resize(nInputs, 00069 mConfig.GetIdentifier(), this); 00070 } 00071 00072 00073 return true; 00074 } 00075 00076 bool ControlPrinter::Do() 00077 { 00078 if (mConfig.GetGuiOnly()) 00079 return true; 00080 00081 std::string separator = ""; 00082 std::stringstream values; 00083 for (int i = 0; i < mInControls.Size(); i++) 00084 { 00085 values << separator << mInControls[i].GetLastValue(); 00086 separator = ", "; 00087 } 00088 std::cout << mConfig.GetIdentifier() << ": " 00089 << values.str() << std::endl; 00090 return true; 00091 } 00092 00093 void ControlPrinter::RemoveOldControls() 00094 { 00095 mInControls.Clear(); 00096 GetInControls().Clear(); 00097 } 00098 } 00099