data structure seems to be fully implemented

This commit is contained in:
Chris Punches
2017-04-19 22:49:39 -04:00
parent e60b959f3b
commit dd49cfe739
7 changed files with 51 additions and 42 deletions

View File

@@ -47,6 +47,7 @@ Unit::Unit( Json::Value loader_root )
this->rectify = loader_root.get("rectify", "?").asString();
}
std::string Unit::get_name() { return this->name; }
std::string Unit::get_target() { return this->target; }
std::string Unit::get_output() { return this->output; }
@@ -68,21 +69,22 @@ UnitHolder::UnitHolder( std::string filename ): JLoader( filename )
}
};
Unit UnitHolder::select_unit(std::string name)
Unit UnitHolder::select_unit(std::string provided_name)
{
/*
* TODO: Implement fetch unit by name method.
*/
for ( int i = 0; i < this->units.size(); ++i )
Unit * returnable;
for ( int i = 0; i < this->units.size(); i++ )
{
if ( this->units[i].get_name() == name )
{
return this->units[i];
} else {
std::cerr << "Logic error in UnitHolder::select_unit. This is a bug. Please report it." << std::endl;
exit(1);
std::string unit_name = this->units[i].get_name();
if ( unit_name == provided_name ) {
returnable = & this->units[i];
}
}
return * returnable;
}

View File

@@ -50,7 +50,7 @@ class UnitHolder: public JLoader
using JLoader::JLoader;
std::vector<Unit> units;
UnitHolder( std::string filename );
Unit select_unit( std::string name );
Unit select_unit( std::string provided_name );
};
class Task