diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a316d56..09b113a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -33,8 +33,8 @@ - - + + @@ -69,12 +69,12 @@ - - + + - - - + + + @@ -126,8 +126,8 @@ - - + + @@ -477,12 +477,12 @@ 1491540343823 - + - @@ -502,7 +502,7 @@ - + @@ -657,21 +657,33 @@ + + + + + + + + - - + + - + - - - + + + + + + + @@ -683,22 +695,10 @@ - - - - - - - - - - - - - - + + diff --git a/cmake-build-debug/CMakeFiles/ftests.dir/examplar.cpp.o b/cmake-build-debug/CMakeFiles/ftests.dir/examplar.cpp.o index e79880d..a80b71a 100644 Binary files a/cmake-build-debug/CMakeFiles/ftests.dir/examplar.cpp.o and b/cmake-build-debug/CMakeFiles/ftests.dir/examplar.cpp.o differ diff --git a/cmake-build-debug/CMakeFiles/ftests.dir/src/loaders.cpp.o b/cmake-build-debug/CMakeFiles/ftests.dir/src/loaders.cpp.o index f83c06d..78664fd 100644 Binary files a/cmake-build-debug/CMakeFiles/ftests.dir/src/loaders.cpp.o and b/cmake-build-debug/CMakeFiles/ftests.dir/src/loaders.cpp.o differ diff --git a/cmake-build-debug/ftests b/cmake-build-debug/ftests index 0becb8e..81a7509 100755 Binary files a/cmake-build-debug/ftests and b/cmake-build-debug/ftests differ diff --git a/examplar.cpp b/examplar.cpp index a2c0b25..1b32ec2 100644 --- a/examplar.cpp +++ b/examplar.cpp @@ -11,7 +11,14 @@ int main() for ( int i = 0; i < plan.tasks.size(); ++i ) { - std::cout << unitHolder.select_unit( plan.tasks[i].get_name() ).get_target() << std::endl; + std::string current_task_name = plan.tasks[i].get_name(); + std::cout << "Found task name:\t" << current_task_name << std::endl << std::endl; + + Unit current_unit = unitHolder.select_unit( current_task_name ); + + std::cout << "Associated Unit name:\t" << current_unit.get_name() << std::endl; + std::cout << "Associated Unit target:\t" << current_unit.get_target() << std::endl; + std::cout << "Associated Unit healer:\t" << current_unit.get_rectifier() << std::endl << std::endl; } diff --git a/src/loaders.cpp b/src/loaders.cpp index 95fb0ad..66425c0 100644 --- a/src/loaders.cpp +++ b/src/loaders.cpp @@ -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; } diff --git a/src/loaders.h b/src/loaders.h index 8686856..fea1ed0 100644 --- a/src/loaders.h +++ b/src/loaders.h @@ -50,7 +50,7 @@ class UnitHolder: public JLoader using JLoader::JLoader; std::vector units; UnitHolder( std::string filename ); - Unit select_unit( std::string name ); + Unit select_unit( std::string provided_name ); }; class Task