readded confs, some basic exception handling, and reworking conf now

This commit is contained in:
Chris Punches
2017-06-11 15:14:45 -04:00
parent 82d768e3c1
commit b36e6acabd
11 changed files with 142 additions and 74 deletions

View File

@@ -1,15 +1,28 @@
#include "Conf.h"
class CONF_PLANPATH_INVALID: public std::runtime_error
{
public:
CONF_PLANPATH_INVALID(): std::runtime_error("conf: The supplied path for the plan definition file is invalid.") {}
};
class CONF_UNITSPATH_INVALID: public std::runtime_error
{
public:
CONF_UNITSPATH_INVALID(): std::runtime_error("conf: The supplied path for the unit definition file is invalid.") {}
};
Conf::Conf( std::string filename ): JSON_Loader()
{
// Conf is always loaded from file.
// load the conf file.
this->load_json_file( filename, true );
// always load plan_path, it is required to function.
this->get_key( this->plan_path, "plan_path", true, false );
// find the path to the plan file
if (! this->get_key( this->plan_path, "plan_path", true) ) { throw CONF_PLANPATH_INVALID(); }
// always load units_path, it is required to function.
this->get_key( this->units_path, "units_path", true, false );
// find the path to the unit definitions file
if (! this->get_key( this->units_path, "units_path", true) ) { throw CONF_UNITSPATH_INVALID(); }
};
std::string Conf::get_plan_path()