/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include "Options.h"
#include <iostream>
#include <boost/program_options.hpp>

namespace evaluator
{
	Options::Options(int argc, char **argv)
	{
		ParseOptions(argc, argv);
	}

	Params & Options::GetParams()
	{
		return params;
	}

	void Options::ParseOptions(int argc, char**argv)
	{
		using namespace boost::program_options;

		options_description desc;

		desc.add_options()
				("help", "Print this text")
				("cluto-file", value<std::string>(& params.cluto_file), "Path to cluto file")
				("class-file", value<std::string>(& params.class_file), "Path to class labels file")
				("method", value<std::string>(& params.method), "Method of evaluation")
				("silent", value<bool>(& params.silent)->zero_tokens(), "Silent mode")
				("matrix-dir", value<std::string>(& params.matrix_dir), "Path to SuperMatrix")
				("matrix-name", value<std::string>(& params.matrix_name), "SuperMatrix name")
				("sim-function", value<std::string>(& params.sim_function), "Similarity function in FunctionFactory format")
				("sim-matrix-dir", value<std::string>(& params.sim_matrix_dir), "Path to similarity matrix")
				("sim-matrix-name", value<std::string>(& params.sim_matrix_name), "Similarity matrix name")
				;

		variables_map vm;
		positional_options_description p;
		p.add("cluto-file", 1);
		p.add("class-file", 1);

		store(command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
		notify(vm);

		if(vm.count("help") || argc == 1)
		{
			std::cout << "Clustering evaluator application\n" << desc << std::endl;
			exit(0);
		}

		if(!vm.count("cluto-file"))
			throw std::runtime_error("parameter cluto-file must be defined");
	}
}
