1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
7 #include <boost/filesystem.hpp>
8 #include <boost/program_options.hpp>
9 #include <cpPlugins/Pipeline.h>
11 int main( int argc, char* argv[] )
13 typedef cpPlugins::Pipeline TPipeline;
14 namespace bpo = boost::program_options;
16 // Declare the supported options.
17 bpo::options_description d( "Allowed options" );
19 ( "help,h", "produce help message" )
20 ( "interactive,i", bpo::bool_switch( )->default_value( false ), "Run an interactive menu to configure pipeline" )
21 ( "overwrite,o", bpo::bool_switch( )->default_value( false ), "Overwrite XML file" )
22 ( "contents,c", bpo::bool_switch( )->default_value( false ), "Print pipeline contents" )
23 ( "value,v", bpo::value< std::vector< std::string > >( ), "Parameter values" )
24 ( "pipeline,p", bpo::value< std::string >( )->required( ), "Pipeline file" )
26 bpo::positional_options_description p;
27 p.add( "pipeline", -1 );
29 // Parse input arguments
35 command_line_parser( argc, argv ).options( d ).positional( p ).run( ),
39 if( v.count( "help" ) > 0 )
41 std::cerr << d << std::endl;
46 catch( std::exception& err )
48 std::cerr << "Error caught: " << err.what( ) << std::endl;
49 std::cerr << d << std::endl;
57 TPipeline::SharedPtr pipeline = TPipeline::New( );
58 pipeline->ExecutionDebugOn( );
59 pipeline->LoadXML( v[ "pipeline" ].as< std::string >( ) );
62 if( v.count( "value" ) > 0 )
65 const std::string& pv:
66 v[ "value" ].as< std::vector< std::string > >( )
69 std::size_t b = pv.find_first_of( "=" );
70 pipeline->SetInValue( pv.substr( 0, b ), pv.substr( b + 1 ) );
76 // Just print pipeline contents
77 if( v[ "contents" ].as< bool >( ) )
80 TPipeline::TParametersMap pmap = pipeline->GetParametersMap( );
81 TPipeline::TParametersMap::const_iterator pIt;
82 for( pIt = pmap.begin( ); pIt != pmap.end( ); ++pIt )
86 << pIt->second.first << "="
87 << pIt->second.second << ")"
96 // Interactively configure pipeline
97 if( v[ "interactive" ].as< bool >( ) )
99 std::cout << "** Interactively configuring pipeline **" << std::endl;
101 TPipeline::TParametersMap pmap = pipeline->GetParametersMap( );
102 TPipeline::TParametersMap::const_iterator pIt;
103 for( pIt = pmap.begin( ); pIt != pmap.end( ); ++pIt )
106 << pIt->first << " ("
107 << pIt->second.first << "="
108 << pIt->second.second << "): "
111 std::getline( std::cin, line );
114 std::size_t p = pIt->first.find( "@" );
115 pipeline->SetParameter(
116 pIt->first.substr( p + 1 ),
117 pIt->first.substr( 0, p ),
131 if( v[ "overwrite" ].as< bool >( ) )
132 pipeline->SaveXML( v[ "pipeline" ].as< std::string >( ) );
134 catch( std::exception& err )
136 std::cerr << "ERROR CAUGHT: " << err.what( ) << std::endl;