diff --git a/examplar.cpp b/examplar.cpp index 63658ad..d765017 100644 --- a/examplar.cpp +++ b/examplar.cpp @@ -12,12 +12,12 @@ int main( ) // load the configuration file which contains filepaths to definitions of a plan and definitions of units. std::string definitions_file = configuration.get_units_path(); std::string plan_file = configuration.get_plan_path(); - // std::cout << definitions_file << std::endl << plan_file << std::endl; Suite available_definitions; available_definitions.load_units_file( definitions_file, verbose ); Plan plan; + plan.load_plan_file( plan_file, verbose ); /* for ( int i = 0; i < plan.num_tasks(); ++i ) { diff --git a/src/loaders/Plan.cpp b/src/loaders/Plan.cpp index aea5b3b..8ffa620 100644 --- a/src/loaders/Plan.cpp +++ b/src/loaders/Plan.cpp @@ -1,5 +1,4 @@ #include "Plan.h" - /// Plan_InvalidTaskIndex - Exception thrown when a Plan tries to access a contained Task's value by index not present /// in the Unit. class Plan_InvalidTaskIndex: public std::runtime_error { public: @@ -12,7 +11,6 @@ class Plan_InvalidTaskName: public std::runtime_error { public: Plan_InvalidTaskName(): std::runtime_error("Plan: Attempted to access a Task using an invalid name.") {} }; - /// Plan::Plan() - Constructor for Plan class. A Plan is a managed container for a Task vector. These tasks reference /// Units that are defined in the Units files (Suite). If Units are definitions, Tasks are selections of those /// definitions to execute, and if Units together form a Suite, Tasks together form a Plan. diff --git a/src/loaders/Plan.h b/src/loaders/Plan.h index 6a6ab1b..60c995c 100644 --- a/src/loaders/Plan.h +++ b/src/loaders/Plan.h @@ -16,13 +16,20 @@ class Plan: public JSON_Loader public: Plan(); + // append this->tasks from JSON file void load_plan_file( std::string filename, bool verbose ); + // fetch a task from this->tasks void get_task( Task & result, std::string provided_name, bool verbose ); - void get_task( Task & result, int index. bool verbose ); + // fetch a task from this->tasks + void get_task( Task & result, int index, bool verbose ); - void get_unit_from_task(Unit & result, Task input, bool verbose ); + // load unit definitions from a provided suite and import them into individual tasks + // void load_definitions( Suite unit_definitions ); + + // fetch a corresponding Unit to a Task + // void get_definition_from_task(Unit & result, Task input, bool verbose ); }; #endif //FTESTS_PLAN_H diff --git a/src/loaders/Suite.h b/src/loaders/Suite.h index 1c1a24b..b02b81e 100644 --- a/src/loaders/Suite.h +++ b/src/loaders/Suite.h @@ -11,7 +11,7 @@ class Suite: public JSON_Loader { - private: + protected: // storage for the definitions we are amassing from the unit definition files std::vector units; diff --git a/src/loaders/Task.cpp b/src/loaders/Task.cpp index 47d98a9..65dd153 100644 --- a/src/loaders/Task.cpp +++ b/src/loaders/Task.cpp @@ -1,17 +1,27 @@ #include "Task.h" -Task::Task() {} +/// Task_InvalidDataStructure - Exception thrown when a Task is defined with invalid JSON. +class Task_InvalidDataStructure: public std::runtime_error { public: + Task_InvalidDataStructure(): std::runtime_error("Task: Attempted to access a member of a Task that is not set.") {} +}; -Task::Task( Json::Value loader_root ) -{ - this->load_root( loader_root ); -} +/// Task::Task() - Constructor for the Task class. The Task is the building block of a Plan indicating of which Unit to +/// execute, and its dependencies on other units to have already been completed successfully. +Task::Task() {} int Task::load_root(Json::Value loader_root) { - this->name = loader_root.get("name", "?").asString(); - this->dependencies = loader_root.get("depends on", ""); - this->has_succeeded = false; + if ( loader_root.isMember("name") ) + { + this->name = loader_root.get("name", "?").asString(); + } else { + throw Task_InvalidDataStructure(); + } + + + // this->dependencies = loader_root.get("depends on", ""); + //this->has_succeeded = false; + } std::string Task::get_name() @@ -19,23 +29,4 @@ 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() -{ - -} \ No newline at end of file diff --git a/src/loaders/Task.h b/src/loaders/Task.h index 8abd639..9cdd440 100644 --- a/src/loaders/Task.h +++ b/src/loaders/Task.h @@ -7,24 +7,38 @@ class Task { - private: + protected: + // the name of this task std::string name; - Json::Value dependencies; - bool has_succeeded; + + // names of tasks that must have successfully executed before this task can execute its own unit. + std::vector dependencies; + + // private member to store the definition of this task once found in a Suite by Plan. + // populated by load_definition + Unit definition; + + // the status of this task + bool complete; public: - Task( Json::Value loader_root ); + // constructor Task(); + // load a json::value into task members (second stage deserialization) int load_root( Json::Value loader_root ); - std::string get_name(); - Json::Value get_dependencies(); - Json::Value set_dependencies(); + // register a dependency + void add_dependency( std::string dependency_name ); - // appends associated_unit as child member - bool isDone(); - void finish(); + // appends definition unit as child member + void load_definition( Unit definition ); + + + bool is_complete(); + + // fetch the name of a task + std::string get_name(); }; #endif //FTESTS_TASK_H