mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
simulators
change prefix p to m add list_simulators
This commit is contained in:
+24
-14
@@ -8,57 +8,67 @@ Simulators::Simulators()
|
|||||||
|
|
||||||
void Simulators::run()
|
void Simulators::run()
|
||||||
{
|
{
|
||||||
if (this->p_simulators.empty())
|
if (this->m_simulators.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this->p_current_simulator.empty())
|
if (this->m_current_simulator.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->p_simulators.at(p_current_simulator)->run();
|
this->m_simulators.at(m_current_simulator)->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulators::stop()
|
void Simulators::stop()
|
||||||
{
|
{
|
||||||
if (this->p_simulators.empty())
|
if (this->m_simulators.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this->p_current_simulator.empty())
|
if (this->m_current_simulator.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->p_simulators.at(p_current_simulator)->stop();
|
this->m_simulators.at(m_current_simulator)->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulators::switch_simulator(std::string name)
|
void Simulators::switch_simulator(std::string name)
|
||||||
{
|
{
|
||||||
if (this->p_simulators.empty())
|
if (this->m_simulators.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this->p_current_simulator.empty())
|
if (!this->m_current_simulator.empty())
|
||||||
{
|
{
|
||||||
this->p_simulators.at(p_current_simulator)->stop();
|
this->m_simulators.at(m_current_simulator)->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->p_current_simulator = name;
|
this->m_current_simulator = name;
|
||||||
this->p_simulators.at(p_current_simulator)->run();
|
this->m_simulators.at(m_current_simulator)->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Simulators::list_simulators() const
|
||||||
|
{
|
||||||
|
std::vector<std::string> names;
|
||||||
|
for (const auto& simulator : this->m_simulators)
|
||||||
|
{
|
||||||
|
names.push_back(simulator.first);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
Simulator_base* Simulators::invoke_active_simulator() const
|
Simulator_base* Simulators::invoke_active_simulator() const
|
||||||
{
|
{
|
||||||
if (this->p_simulators.empty())
|
if (this->m_simulators.empty())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (this->p_current_simulator.empty())
|
if (this->m_current_simulator.empty())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->p_simulators.at(p_current_simulator).get();
|
return this->m_simulators.at(m_current_simulator).get();
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
|
|
||||||
#define INSERT_SIMULATOR(type) p_simulators.insert(std::make_pair(type().name(), std::make_unique<type>()));
|
#define INSERT_SIMULATOR(type) m_simulators.insert(std::make_pair(type().name(), std::make_unique<type>()));
|
||||||
|
|
||||||
class Simulators {
|
class Simulators {
|
||||||
public:
|
public:
|
||||||
@@ -12,8 +12,9 @@ class Simulators {
|
|||||||
void run();
|
void run();
|
||||||
void stop();
|
void stop();
|
||||||
void switch_simulator(std::string name);
|
void switch_simulator(std::string name);
|
||||||
|
std::vector<std::string> list_simulators() const;
|
||||||
Simulator_base* invoke_active_simulator() const;
|
Simulator_base* invoke_active_simulator() const;
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::unique_ptr<Simulator_base>> p_simulators;
|
std::map<std::string, std::unique_ptr<Simulator_base>> m_simulators;
|
||||||
std::string p_current_simulator;
|
std::string m_current_simulator;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user