broke classes down into own files, preparing to change model to pass by reference with int return type for almost everything
This commit is contained in:
@@ -1,43 +1,18 @@
|
||||
//
|
||||
// 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; }
|
||||
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()
|
||||
// returns the number of tasks in a Plan
|
||||
{
|
||||
return (int)this->tasks.size();
|
||||
}
|
||||
|
||||
Task Plan::select_task_index(int index)
|
||||
Task Plan::get_task(int index)
|
||||
// returns a task from its parent Plan by index
|
||||
{
|
||||
return this->tasks[index];
|
||||
}
|
||||
|
||||
Task Plan::select_task( std::string provided_name )
|
||||
Task Plan::get_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.
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
//
|
||||
// Created by phanes on 4/22/17.
|
||||
//
|
||||
|
||||
#ifndef FTESTS_PLAN_H
|
||||
#define FTESTS_PLAN_H
|
||||
|
||||
#include <string>
|
||||
#include "../json/json.h"
|
||||
#include "JLoader.h"
|
||||
#include "Task.h"
|
||||
|
||||
class Task
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
Json::Value dependencies;
|
||||
bool has_succeeded;
|
||||
|
||||
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
|
||||
{
|
||||
@@ -31,8 +14,8 @@ class Plan: public JLoader
|
||||
|
||||
public:
|
||||
Plan( std::string filename );
|
||||
Task select_task( std::string provided_name );
|
||||
Task select_task_index( int index );
|
||||
Task get_task(std::string provided_name);
|
||||
Task get_task(int index);
|
||||
int num_tasks();
|
||||
};
|
||||
|
||||
|
||||
43
src/loaders/Suite.cpp
Normal file
43
src/loaders/Suite.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "Suite.h"
|
||||
|
||||
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 ] ) );
|
||||
}
|
||||
};
|
||||
|
||||
Unit Suite::get_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;
|
||||
|
||||
for ( int i = 0; i < this->units.size(); i++ )
|
||||
{
|
||||
std::string unit_name = this->units[i].get_name();
|
||||
if ( unit_name == provided_name )
|
||||
{
|
||||
returnable = & this->units[i];
|
||||
foundMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! foundMatch )
|
||||
{
|
||||
std::cerr << "Unit name \"" << provided_name << "\" was referenced but not defined!" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
return * returnable;
|
||||
}
|
||||
29
src/loaders/Suite.h
Normal file
29
src/loaders/Suite.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by phanes on 4/22/17.
|
||||
//
|
||||
|
||||
#ifndef FTESTS_UNITS_H
|
||||
#define FTESTS_UNITS_H
|
||||
|
||||
#include <vector>
|
||||
#include "../json/json.h"
|
||||
#include "JLoader.h"
|
||||
#include "Unit.h"
|
||||
|
||||
|
||||
class Suite: public JLoader
|
||||
{
|
||||
private:
|
||||
std::vector<Unit> units;
|
||||
|
||||
public:
|
||||
// constructor
|
||||
Suite( std::string filename );
|
||||
|
||||
// returns the unit type identified by name or null
|
||||
Unit get_unit(std::string provided_name);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //FTESTS_UNITS_H
|
||||
22
src/loaders/Task.cpp
Normal file
22
src/loaders/Task.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "Task.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; }
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
26
src/loaders/Task.h
Normal file
26
src/loaders/Task.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by phanes on 4/30/17.
|
||||
//
|
||||
|
||||
#ifndef FTESTS_TASK_H
|
||||
#define FTESTS_TASK_H
|
||||
#include <string>
|
||||
#include "../json/json.h"
|
||||
|
||||
class Task
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
Json::Value dependencies;
|
||||
bool has_succeeded;
|
||||
|
||||
public:
|
||||
Task( Json::Value loader_root );
|
||||
std::string get_name();
|
||||
Json::Value get_dependencies();
|
||||
Json::Value set_dependencies();
|
||||
bool isDone();
|
||||
void finish();
|
||||
};
|
||||
|
||||
#endif //FTESTS_TASK_H
|
||||
53
src/loaders/Unit.cpp
Normal file
53
src/loaders/Unit.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "Unit.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();
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
32
src/loaders/Unit.h
Normal file
32
src/loaders/Unit.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by phanes on 4/29/17.
|
||||
//
|
||||
|
||||
#ifndef FTESTS_UNIT_H
|
||||
#define FTESTS_UNIT_H
|
||||
#include <string>
|
||||
#include "../json/json.h"
|
||||
|
||||
class Unit
|
||||
{
|
||||
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();
|
||||
};
|
||||
|
||||
#endif //FTESTS_UNIT_H
|
||||
@@ -1,72 +0,0 @@
|
||||
//
|
||||
// Created by phanes on 4/22/17.
|
||||
//
|
||||
|
||||
#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();
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
* 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; }
|
||||
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; }
|
||||
|
||||
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 ] ) );
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
for ( int i = 0; i < this->units.size(); i++ )
|
||||
{
|
||||
std::string unit_name = this->units[i].get_name();
|
||||
if ( unit_name == provided_name )
|
||||
{
|
||||
returnable = & this->units[i];
|
||||
foundMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! foundMatch )
|
||||
{
|
||||
std::cerr << "Unit name \"" << provided_name << "\" was referenced but not defined!" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
return * returnable;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// Created by phanes on 4/22/17.
|
||||
//
|
||||
|
||||
#ifndef FTESTS_UNITS_H
|
||||
#define FTESTS_UNITS_H
|
||||
|
||||
#include <vector>
|
||||
#include "../json/json.h"
|
||||
#include "JLoader.h"
|
||||
|
||||
class Unit
|
||||
{
|
||||
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();
|
||||
};
|
||||
|
||||
class Suite: public JLoader
|
||||
{
|
||||
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 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //FTESTS_UNITS_H
|
||||
@@ -5,7 +5,7 @@
|
||||
#define FTESTS_LOADERS_H
|
||||
|
||||
#include "JLoader.h"
|
||||
#include "Units.h"
|
||||
#include "Suite.h"
|
||||
#include "Plan.h"
|
||||
#include "Conf.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user