polished unit

master
Chris Punches 2017-06-21 00:01:00 -04:00
parent f5c8894670
commit 848308a4a5
3 changed files with 28 additions and 17 deletions

View File

@ -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()

View File

@ -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++ )

View File

@ -2,6 +2,13 @@
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdexcept>
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;
}