2017-04-22 12:07:11 +00:00
|
|
|
#include "Plan.h"
|
2017-04-29 21:35:03 +00:00
|
|
|
|
|
|
|
int Plan::num_tasks()
|
2017-04-30 00:32:09 +00:00
|
|
|
// returns the number of tasks in a Plan
|
2017-04-29 21:35:03 +00:00
|
|
|
{
|
|
|
|
return (int)this->tasks.size();
|
|
|
|
}
|
|
|
|
|
2017-04-30 05:39:03 +00:00
|
|
|
Task Plan::get_task(int index)
|
2017-04-30 00:32:09 +00:00
|
|
|
// returns a task from its parent Plan by index
|
|
|
|
{
|
2017-04-29 21:35:03 +00:00
|
|
|
return this->tasks[index];
|
|
|
|
}
|
|
|
|
|
2017-04-30 05:39:03 +00:00
|
|
|
Task Plan::get_task(std::string provided_name)
|
2017-04-29 21:35:03 +00:00
|
|
|
/*
|
|
|
|
* returns a task from a Plan object by name
|
|
|
|
* this will need reworked. maybe should return int, populate a pointer.
|
|
|
|
* error handling is the concern here.
|
|
|
|
*/
|
2017-04-30 00:32:09 +00:00
|
|
|
{
|
2017-04-29 21:35:03 +00:00
|
|
|
Task * returnable;
|
|
|
|
bool foundMatch = false;
|
|
|
|
|
|
|
|
for ( int i = 0; i < this->tasks.size(); i++ )
|
|
|
|
{
|
|
|
|
std::string task_name = this->tasks[i].get_name();
|
|
|
|
if ( task_name == provided_name )
|
|
|
|
{
|
|
|
|
returnable = & this->tasks[i];
|
|
|
|
foundMatch = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! foundMatch )
|
|
|
|
{
|
|
|
|
std::cerr << "Task name \"" << provided_name << "\" was referenced but not defined!" << std::endl;
|
|
|
|
std::exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return * returnable;
|
|
|
|
}
|
|
|
|
|
2017-04-22 12:07:11 +00:00
|
|
|
Plan::Plan( std::string filename ): JLoader( filename )
|
|
|
|
/* Plan loads a file and deserializes the Unit JSON object to Task types as a vector member
|
|
|
|
* Plan { vector<Task> }
|
|
|
|
*/
|
2017-04-30 00:32:09 +00:00
|
|
|
{
|
2017-04-22 12:07:11 +00:00
|
|
|
Json::Value raw_tasks = this->get_root()["plan"];
|
|
|
|
|
|
|
|
for ( int index = 0; index < raw_tasks.size(); index++ )
|
|
|
|
{
|
|
|
|
this->tasks.push_back( Task( raw_tasks[index] ) );
|
|
|
|
}
|
2017-04-29 21:35:03 +00:00
|
|
|
};
|