cleaned up what should be private member access

This commit is contained in:
Chris Punches
2017-04-29 17:35:03 -04:00
parent 69539ae019
commit d62df8b076
12 changed files with 479 additions and 240 deletions

View File

@@ -1,16 +1,71 @@
//
// Created by phanes on 4/22/17.
//
#include "Plan.h"
Task::Task( Json::Value loader_root )
{
this->name = loader_root.get("name", "?").asString();
this->dependencies = loader_root.get("depends on", "");
this->has_succeeded = false;
}
std::string Task::get_name() { return this->name; }
std::string Task::get_name() { return this->name; }
bool Task::isDone() { return this->has_succeeded; }
void Task::finish() { this->has_succeeded = true; }
// returns Json::Value for dependencies
Json::Value Task::get_dependencies() { return this->dependencies;}
Json::Value Task::set_dependencies()
{
}
int Plan::num_tasks()
{
return (int)this->tasks.size();
}
Task Plan::select_task_index(int index) {
return this->tasks[index];
}
Task Plan::select_task( std::string provided_name )
{
/*
* 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.
*/
{
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;
}
}
Plan::Plan( std::string filename ): JLoader( filename )
{
/* Plan loads a file and deserializes the Unit JSON object to Task types as a vector member
@@ -22,4 +77,4 @@ Plan::Plan( std::string filename ): JLoader( filename )
{
this->tasks.push_back( Task( raw_tasks[index] ) );
}
};
};

View File

@@ -10,24 +10,30 @@
class Task
{
private:
std::string name;
Json::Value dependencies;
private:
std::string name;
Json::Value dependencies;
bool has_succeeded;
public:
Task( Json::Value loader_root );
std::string get_name();
Json::Value get_dependencies();
public:
Task( Json::Value loader_root );
std::string get_name();
Json::Value get_dependencies();
Json::Value set_dependencies();
bool isDone();
void finish();
};
class Plan: public JLoader
{
public:
using JLoader::JLoader;
std::vector<Task> tasks;
Plan( std::string filename );
private:
std::vector<Task> tasks;
public:
Plan( std::string filename );
Task select_task( std::string provided_name );
Task select_task_index( int index );
int num_tasks();
};
#endif //FTESTS_PLAN_H

View File

@@ -3,7 +3,11 @@
//
#include "Units.h"
Unit::Unit( Json::Value loader_root )
/*
* Constructor for Unit type. Receives a UnitHolder loader_root.
*/
{
this->name = loader_root.get("name", "?").asString();
this->target = loader_root.get("target", "?").asString();
@@ -14,7 +18,9 @@ Unit::Unit( Json::Value loader_root )
this->rectify = loader_root.get("rectify", "?").asString();
}
/*
* getters for Unit type.
*/
std::string Unit::get_name() { return this->name; }
std::string Unit::get_target() { return this->target; }
std::string Unit::get_output() { return this->output; }
@@ -23,20 +29,25 @@ std::string Unit::get_active() { return this->active; }
std::string Unit::get_required() { return this->required; }
std::string Unit::get_rectify() { return this->rectify; }
UnitHolder::UnitHolder( std::string filename ): JLoader( filename )
{
/* UnitHolder loads a file and deserializes the Unit JSON object to Unit types as a vector member
* UnitHolder { vector<Unit> }
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> }
*/
{
Json::Value raw_units = this->get_root()["units"];
for ( int index = 0; index < raw_units.size(); index++ )
{
this->units.push_back(Unit( raw_units[index] ));
this->units.push_back( Unit( raw_units[ index ] ) );
}
};
Unit UnitHolder::select_unit(std::string provided_name)
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.
*/
{
Unit * returnable;
bool foundMatch = false;
@@ -53,7 +64,7 @@ Unit UnitHolder::select_unit(std::string provided_name)
}
if (! foundMatch )
{
std::cerr << "Unit name \"" << provided_name << "\" was referenced in a plan task but not defined!" << std::endl;
std::cerr << "Unit name \"" << provided_name << "\" was referenced but not defined!" << std::endl;
std::exit(1);
}

View File

@@ -11,33 +11,37 @@
class Unit
{
private:
std::string name;
std::string target;
std::string output;
std::string rectifier;
std::string active;
std::string required;
std::string rectify;
private:
std::string name;
std::string target;
std::string output;
std::string rectifier;
std::string active;
std::string required;
std::string rectify;
public:
Unit( Json::Value loader_root );
std::string get_name();
std::string get_target();
std::string get_output();
std::string get_rectifier();
std::string get_active();
std::string get_required();
std::string get_rectify();
public:
Unit( Json::Value loader_root );
std::string get_name();
std::string get_target();
std::string get_output();
std::string get_rectifier();
std::string get_active();
std::string get_required();
std::string get_rectify();
};
class UnitHolder: public JLoader
class Suite: public JLoader
{
public:
using JLoader::JLoader;
std::vector<Unit> units;
UnitHolder( std::string filename );
Unit select_unit( std::string provided_name );
private:
std::vector<Unit> units;
public:
// constructor
Suite( std::string filename );
// returns the unit type identified by name or null
Unit select_unit( std::string provided_name );
};