diff --git a/src/loaders/JSON_Loader.cpp b/src/loaders/JSON_Loader.cpp index 65aebe1..5a4f26a 100644 --- a/src/loaders/JSON_Loader.cpp +++ b/src/loaders/JSON_Loader.cpp @@ -97,12 +97,12 @@ void JSON_Loader::load_json_string( std::string input, bool verbose ) // returns the serialized representation of json_root -Json::Value JSON_Loader::as_serialized() -{ - if ( ! this->populated ) { throw JSON_Loader_NotReady(); } - - return this->json_root; -} +//Json::Value JSON_Loader::as_serialized() +//{ +// if ( ! this->populated ) { throw JSON_Loader_NotReady(); } +// +// return this->json_root; +//} // returns the string representation of json_root std::string JSON_Loader::as_string() diff --git a/src/loaders/Suite.cpp b/src/loaders/Suite.cpp index 82a6992..62401ba 100644 --- a/src/loaders/Suite.cpp +++ b/src/loaders/Suite.cpp @@ -22,7 +22,7 @@ void Suite::load_units_file( std::string filename, bool verbose ) } -int Suite::load_file(std::string filename): JSON_Loader( filename ) +int Suite::load_file(std::string filename, true): JSON_Loader( filename ) { Json::Value raw_units = this->get_serialized("") for ( int index = 0; index < raw_units.size(); index++ ) diff --git a/src/loaders/Unit.cpp b/src/loaders/Unit.cpp index 95c7df9..1e6872d 100644 --- a/src/loaders/Unit.cpp +++ b/src/loaders/Unit.cpp @@ -2,6 +2,13 @@ #include #include #include +#include + +class Unit_NotPopulated: public std::runtime_error +{ +public: + Unit_NotPopulated(): std::runtime_error("Unit: Attempted to access a member before loading values.") {} +}; Unit::Unit() {} @@ -9,19 +16,19 @@ Unit::Unit() {} int Unit::load_root(Json::Value loader_root) { - this->name = loader_root.get("name", "?").asString(); + this->name = loader_root.get("name", "").asString(); - this->target = loader_root.get("target", "?").asString(); + this->target = loader_root.get("target", "").asString(); - this->output = loader_root.get("output", "?").asString(); + this->output = loader_root.get("output", "").asString(); - this->rectifier = loader_root.get("rectifier", "?").asString(); + this->rectifier = loader_root.get("rectifier", "").asString(); - this->active = loader_root.get("active", "?").asString(); + this->active = loader_root.get("active", "").asString(); - this->required = loader_root.get("required", "?").asString(); + this->required = loader_root.get("required", "").asString(); - this->rectify = loader_root.get("rectify", "?").asString(); + this->rectify = loader_root.get("rectify", "").asString(); this->populated = true; @@ -37,44 +44,48 @@ int Unit::load_string(std::string json_val) // deserialize this->load_root( this->json_root ); - // exit successfully - this->populated = true; - return 0; } // getters for Unit type. std::string Unit::get_name() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->name; } std::string Unit::get_target() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->target; } std::string Unit::get_output() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->output; } std::string Unit::get_rectifier() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->rectifier; } std::string Unit::get_active() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->active; } std::string Unit::get_required() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->required; } std::string Unit::get_rectify() { + if ( ! this->populated ) { throw Unit_NotPopulated(); } return this->rectify; } \ No newline at end of file