diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 824c5ae..40f549a 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,6 +2,7 @@ add_executable(simulators) target_sources(simulators PRIVATE ${CMAKE_CURRENT_LIST_DIR}/main.cpp ${CMAKE_CURRENT_LIST_DIR}/simulator_base.cpp + ${CMAKE_CURRENT_LIST_DIR}/simulators.cpp ) target_compile_options(simulators PRIVATE $<$: @@ -17,4 +18,5 @@ target_include_directories(simulators target_link_libraries(simulators PRIVATE UI + Timer ) \ No newline at end of file diff --git a/tools/simulators.cpp b/tools/simulators.cpp new file mode 100644 index 0000000..b187de7 --- /dev/null +++ b/tools/simulators.cpp @@ -0,0 +1,64 @@ +#include "simulators.hpp" +#include "test_sim.hpp" + +Simulators::Simulators() +{ + +} + +void Simulators::run() +{ + if (this->p_simulators.empty()) + { + return; + } + if (this->p_current_simulator.empty()) + { + return; + } + + this->p_simulators.at(p_current_simulator)->run(); +} + +void Simulators::stop() +{ + if (this->p_simulators.empty()) + { + return; + } + if (this->p_current_simulator.empty()) + { + return; + } + + this->p_simulators.at(p_current_simulator)->stop(); +} + +void Simulators::switch_simulator(std::string name) +{ + if (this->p_simulators.empty()) + { + return; + } + if (!this->p_current_simulator.empty()) + { + this->p_simulators.at(p_current_simulator)->stop(); + } + + this->p_current_simulator = name; + this->p_simulators.at(p_current_simulator)->run(); +} + +Simulator_base* Simulators::invoke_active_simulator() const +{ + if (this->p_simulators.empty()) + { + return nullptr; + } + if (this->p_current_simulator.empty()) + { + return nullptr; + } + + return this->p_simulators.at(p_current_simulator).get(); +} \ No newline at end of file diff --git a/tools/simulators.hpp b/tools/simulators.hpp new file mode 100644 index 0000000..6e78c8e --- /dev/null +++ b/tools/simulators.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include + +#include "simulator_base.hpp" + +#define INSERT_SIMULATOR(type) p_simulators.insert(std::make_pair(type().name(), std::make_unique())); + +class Simulators { + public: + Simulators(); + void run(); + void stop(); + void switch_simulator(std::string name); + Simulator_base* invoke_active_simulator() const; + private: + std::map> p_simulators; + std::string p_current_simulator; +}; \ No newline at end of file