Newer
Older
#include <istream>
#include <iostream>
template < class T, class U >
std::istream& operator>> ( std::istream & in, std::pair < T, U > & value ) {
std::string tmp;
in >> tmp;
size_t posEqual = tmp.find ( "=" );
if ( posEqual == std::string::npos )
in.setstate(std::ios_base::failbit);
value.first = tmp.substr ( 0, posEqual );
value.second = tmp.substr ( posEqual + 1, tmp.size ( ) );
if ( value.first.empty ( ) || value.second.empty ( ) )
in.setstate(std::ios_base::failbit);
return in;
}
#include <tclap/CmdLine.h>
#include <global/GlobalData.h>
#include <factory/XmlDataFactory.hpp>
template < class T, class U >
struct ArgTraits < std::pair < T, U > > {
typedef ValueLike ValueCategory;
};
} /* namespace TCLAP */
int main ( int argc, char * argv[] ) {
try {
common::GlobalData::argc = argc;
common::GlobalData::argv = argv;
TCLAP::CmdLine cmd ( "Algorithms query language binary", ' ', "0.01" );
TCLAP::MultiArg < std::string > queries ( "q", "query", "Query string", false, "string" );
cmd.add ( queries );
TCLAP::SwitchArg measure ( "m", "measure", "Measure times", false );
cmd.add ( measure );
TCLAP::SwitchArg verbose ( "v", "verbose", "Be verbose", false );
cmd.add ( verbose );
TCLAP::MultiArg < std::pair < std::string, std::string > > params ( "p", "params", "Query index", false, "pair < string, string >" );
cmd.add ( params );
cmd.parse ( argc, argv );
if(verbose.isSet())
common::GlobalData::verbose = true;
if(measure.isSet())
common::GlobalData::measure = true;
measurements::start ( "Overal", measurements::Type::OVERALL );
environment.setBinding ( "stdin", "-" );
environment.setBinding ( "stdout", "-" );
for ( const std::pair < std::string, std::string > & param : params.getValue ( ) ) {
environment.setBinding ( param.first, param.second );
cli::Command::Result result = cli::Command::Result::OK;
if ( queries.getValue ( ).empty ( ) ) {
} else {
for ( const std::string & query : queries.getValue ( ) )
p.execute_line ( query );
result = cli::Command::Result::QUIT;
}
common::Streams::measure << measurements::results ( ) << std::endl;
if ( result == cli::Command::Result::QUIT )
return 0;
else
return 4;
} catch ( const exception::CommonException & exception ) {
alib::XmlDataFactory::toStdout ( exception );
return 1;
} catch ( const TCLAP::ArgException & exception ) {
std::cout << exception.error ( ) << std::endl;
return 2;
} catch ( const std::exception & exception ) {
std::cerr << "Exception caught: " << exception.what ( ) << std::endl;
return 3;
} catch ( ... ) {
std::cerr << "Unknown exception caught." << std::endl;
return 127;
}
}