Skip to content
Snippets Groups Projects
aql.cpp 1.64 KiB
Newer Older
Jan Trávníček's avatar
Jan Trávníček committed
/*
 * aql.cpp
 *
 *  Created on: 26. 3. 2014
 *	  Author: Jan Travnicek
 */

#include <measure>

#include <tclap/CmdLine.h>
#include <global/GlobalData.h>

#include <lexer/Lexer.h>
#include <parser/Parser.h>

int main ( int argc, char * argv[] ) {

	//TODO interfacing to stdin / unnamed pipes and stdout

	try {
		common::GlobalData::argc = argc;
		common::GlobalData::argv = argv;

		TCLAP::CmdLine cmd ( "Algorithms query language binary", ' ', "0.01" );

		TCLAP::ValueArg < std::string > query ( "q", "query", "Query index", true, "", "query");
		cmd.add ( query );

		TCLAP::SwitchArg measure ( "m", "measure", "Measure times", false );
		cmd.add ( measure );

		TCLAP::SwitchArg verbose ( "v", "verbose", "Be verbose", false );
		cmd.add ( verbose );

		cmd.parse ( argc, argv );

		if(verbose.isSet())
			common::GlobalData::verbose = true;
		if(measure.isSet())
			common::GlobalData::measure = true;

		measurements::start ( "Overal", measurements::Type::OVERALL );

		cli::Parser parser ( cli::Lexer ( query.getValue ( ) ) );
		parser.execute ( )->translateAndEval ( nullptr );

		measurements::end ( );

		if ( measure.getValue ( ) )
			std::cmeasure << measurements::results ( ) << std::endl;

		return 0;
	} 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;
	}
}