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