#include "ConfigFile.hpp"

#include <boost/algorithm/string.hpp>
#include <fstream>
#include <vector>

using namespace std;
using namespace boost;

ConfigFile::ConfigFile(string ConfigFileName)
{
	ifstream File(ConfigFileName.c_str());
	string Line;
	if(!File.is_open())
	{
		THROW(Exception() << ex_message("ConfigFile not found") << ex_file(ConfigFileName));
	}

	while(!File.eof())
	{
		getline(File, Line);

		trim_if(Line, is_any_of(" \n\r"));//remove whitespaces
		erase_all(Line, " ");

		if(Line.empty())
			continue;
		if('#'==Line[0])
			continue;

		vector<string> SplitedLine;
		boost::split(SplitedLine, Line, is_any_of("="));

		if(SplitedLine.size()!=2)
			THROW(Exception() << ex_message("Could not parse ConfigFile Line") << ex_detail(Line) << ex_file(ConfigFileName));

		m_Values[SplitedLine[0]]=SplitedLine[1];
	}
}