2017-04-22 12:07:11 +00:00
|
|
|
//
|
|
|
|
// Created by phanes on 4/22/17.
|
|
|
|
//
|
2017-04-19 05:50:34 +00:00
|
|
|
|
2017-04-22 12:07:11 +00:00
|
|
|
#include "Units.h"
|
2017-04-29 21:35:03 +00:00
|
|
|
|
2017-04-19 04:59:05 +00:00
|
|
|
Unit::Unit( Json::Value loader_root )
|
2017-04-29 21:35:03 +00:00
|
|
|
/*
|
|
|
|
* Constructor for Unit type. Receives a UnitHolder loader_root.
|
|
|
|
*/
|
2017-04-18 23:16:10 +00:00
|
|
|
{
|
2017-04-19 04:59:05 +00:00
|
|
|
this->name = loader_root.get("name", "?").asString();
|
|
|
|
this->target = loader_root.get("target", "?").asString();
|
|
|
|
this->output = loader_root.get("output", "?").asString();
|
|
|
|
this->rectifier = loader_root.get("rectifier", "?").asString();
|
|
|
|
this->active = loader_root.get("active", "?").asString();
|
|
|
|
this->required = loader_root.get("required", "?").asString();
|
|
|
|
this->rectify = loader_root.get("rectify", "?").asString();
|
|
|
|
}
|
2017-04-19 05:50:34 +00:00
|
|
|
|
2017-04-29 21:35:03 +00:00
|
|
|
/*
|
|
|
|
* getters for Unit type.
|
|
|
|
*/
|
2017-04-19 04:59:05 +00:00
|
|
|
std::string Unit::get_name() { return this->name; }
|
|
|
|
std::string Unit::get_target() { return this->target; }
|
|
|
|
std::string Unit::get_output() { return this->output; }
|
|
|
|
std::string Unit::get_rectifier() { return this->rectifier; }
|
|
|
|
std::string Unit::get_active() { return this->active; }
|
|
|
|
std::string Unit::get_required() { return this->required; }
|
|
|
|
std::string Unit::get_rectify() { return this->rectify; }
|
|
|
|
|
2017-04-29 21:35:03 +00:00
|
|
|
Suite::Suite( std::string filename ): JLoader( filename )
|
|
|
|
/* Suite loads a file and deserializes the Unit JSON object to Unit types as a vector member
|
|
|
|
* Suite { vector<Unit> }
|
2017-04-19 04:59:05 +00:00
|
|
|
*/
|
2017-04-29 21:35:03 +00:00
|
|
|
{
|
2017-04-19 04:59:05 +00:00
|
|
|
Json::Value raw_units = this->get_root()["units"];
|
2017-04-18 23:04:21 +00:00
|
|
|
|
2017-04-19 04:59:05 +00:00
|
|
|
for ( int index = 0; index < raw_units.size(); index++ )
|
|
|
|
{
|
2017-04-29 21:35:03 +00:00
|
|
|
this->units.push_back( Unit( raw_units[ index ] ) );
|
2017-04-19 04:59:05 +00:00
|
|
|
}
|
2017-04-18 23:16:10 +00:00
|
|
|
};
|
2017-04-18 23:04:21 +00:00
|
|
|
|
2017-04-29 21:35:03 +00:00
|
|
|
Unit Suite::select_unit( std::string provided_name )
|
|
|
|
/*
|
|
|
|
* returns a unit from a unitholder object by name
|
|
|
|
* this will need reworked. maybe should return int, populate a pointer.
|
|
|
|
* error handling is the concern here.
|
|
|
|
*/
|
2017-04-19 06:27:54 +00:00
|
|
|
{
|
2017-04-20 02:49:39 +00:00
|
|
|
Unit * returnable;
|
2017-04-21 06:04:15 +00:00
|
|
|
bool foundMatch = false;
|
|
|
|
|
2017-04-20 02:49:39 +00:00
|
|
|
for ( int i = 0; i < this->units.size(); i++ )
|
2017-04-19 06:27:54 +00:00
|
|
|
{
|
2017-04-20 02:49:39 +00:00
|
|
|
std::string unit_name = this->units[i].get_name();
|
2017-04-21 06:04:15 +00:00
|
|
|
if ( unit_name == provided_name )
|
|
|
|
{
|
2017-04-20 02:49:39 +00:00
|
|
|
returnable = & this->units[i];
|
2017-04-21 06:04:15 +00:00
|
|
|
foundMatch = true;
|
|
|
|
break;
|
2017-04-19 06:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-21 06:04:15 +00:00
|
|
|
if (! foundMatch )
|
|
|
|
{
|
2017-04-29 21:35:03 +00:00
|
|
|
std::cerr << "Unit name \"" << provided_name << "\" was referenced but not defined!" << std::endl;
|
2017-04-21 06:04:15 +00:00
|
|
|
std::exit(1);
|
|
|
|
}
|
2017-04-20 02:49:39 +00:00
|
|
|
|
|
|
|
return * returnable;
|
2017-04-19 06:27:54 +00:00
|
|
|
}
|