2017-04-30 05:39:03 +00:00
|
|
|
#include "Unit.h"
|
2017-06-20 06:06:33 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <cstdlib>
|
2017-06-21 04:01:00 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
class Unit_NotPopulated: public std::runtime_error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Unit_NotPopulated(): std::runtime_error("Unit: Attempted to access a member before loading values.") {}
|
|
|
|
};
|
2017-06-09 03:49:13 +00:00
|
|
|
|
|
|
|
Unit::Unit() {}
|
|
|
|
|
2017-06-21 02:53:47 +00:00
|
|
|
// where the serialized json is broken down into object members
|
2017-06-09 03:49:13 +00:00
|
|
|
int Unit::load_root(Json::Value loader_root)
|
2017-04-30 05:39:03 +00:00
|
|
|
{
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->name = loader_root.get("name", "").asString();
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->target = loader_root.get("target", "").asString();
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->output = loader_root.get("output", "").asString();
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->rectifier = loader_root.get("rectifier", "").asString();
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->active = loader_root.get("active", "").asString();
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->required = loader_root.get("required", "").asString();
|
2017-06-21 02:53:47 +00:00
|
|
|
|
2017-06-21 04:01:00 +00:00
|
|
|
this->rectify = loader_root.get("rectify", "").asString();
|
2017-04-30 05:39:03 +00:00
|
|
|
|
2017-06-21 02:53:47 +00:00
|
|
|
this->populated = true;
|
|
|
|
|
|
|
|
return 0;
|
2017-06-09 03:49:13 +00:00
|
|
|
}
|
2017-06-20 06:06:33 +00:00
|
|
|
|
2017-06-21 02:53:47 +00:00
|
|
|
// populates from a string json object
|
2017-06-20 06:06:33 +00:00
|
|
|
int Unit::load_string(std::string json_val)
|
|
|
|
{
|
2017-06-21 02:53:47 +00:00
|
|
|
// serialize
|
|
|
|
this->load_json_string( json_val, true );
|
|
|
|
|
|
|
|
// deserialize
|
|
|
|
this->load_root( this->json_root );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-20 06:06:33 +00:00
|
|
|
|
|
|
|
// getters for Unit type.
|
2017-04-30 05:39:03 +00:00
|
|
|
std::string Unit::get_name()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Unit::get_target()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Unit::get_output()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->output;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Unit::get_rectifier()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->rectifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Unit::get_active()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Unit::get_required()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->required;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Unit::get_rectify()
|
|
|
|
{
|
2017-06-21 04:01:00 +00:00
|
|
|
if ( ! this->populated ) { throw Unit_NotPopulated(); }
|
2017-04-30 05:39:03 +00:00
|
|
|
return this->rectify;
|
|
|
|
}
|