mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Add simulators
This commit is contained in:
@@ -2,6 +2,7 @@ add_executable(simulators)
|
|||||||
target_sources(simulators PRIVATE
|
target_sources(simulators PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/simulator_base.cpp
|
${CMAKE_CURRENT_LIST_DIR}/simulator_base.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/simulators.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(simulators PRIVATE $<$<CONFIG:Debug>:
|
target_compile_options(simulators PRIVATE $<$<CONFIG:Debug>:
|
||||||
@@ -17,4 +18,5 @@ target_include_directories(simulators
|
|||||||
|
|
||||||
target_link_libraries(simulators PRIVATE
|
target_link_libraries(simulators PRIVATE
|
||||||
UI
|
UI
|
||||||
|
Timer
|
||||||
)
|
)
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "simulator_base.hpp"
|
||||||
|
|
||||||
|
#define INSERT_SIMULATOR(type) p_simulators.insert(std::make_pair(type().name(), std::make_unique<type>()));
|
||||||
|
|
||||||
|
class Simulators {
|
||||||
|
public:
|
||||||
|
Simulators();
|
||||||
|
void run();
|
||||||
|
void stop();
|
||||||
|
void switch_simulator(std::string name);
|
||||||
|
Simulator_base* invoke_active_simulator() const;
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::unique_ptr<Simulator_base>> p_simulators;
|
||||||
|
std::string p_current_simulator;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user