Commit 1805243f authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: rename new dispatch function

parent 462990a9
......@@ -559,7 +559,7 @@ struct copier
auto* mdl = sim.models.try_to_get(c_models[i].src);
auto* mdl_id_dst = &c_models[i].dst;
auto ret = sim.dispatch_2(
auto ret = sim.dispatch(
mdl->type,
[this, &sim, mdl, &mdl_id_dst]<typename DynamicsM>(
DynamicsM& dynamics_models) -> status {
......@@ -2036,7 +2036,7 @@ editor::show_model_dynamics(model& mdl) noexcept
ImGui::PopItemWidth();
if (simulation_show_value && st != editor_status::editing) {
sim.dispatch_2(mdl.type, [&](const auto& d_array) {
sim.dispatch(mdl.type, [&](const auto& d_array) {
const auto& dyn = d_array.get(mdl.id);
add_input_attribute(*this, dyn);
ImGui::PushItemWidth(120.0f);
......@@ -2045,7 +2045,7 @@ editor::show_model_dynamics(model& mdl) noexcept
add_output_attribute(*this, dyn);
});
} else {
sim.dispatch_2(mdl.type, [&](auto& d_array) {
sim.dispatch(mdl.type, [&](auto& d_array) {
auto& dyn = d_array.get(mdl.id);
add_input_attribute(*this, dyn);
ImGui::PushItemWidth(120.0f);
......@@ -2107,7 +2107,7 @@ show_tooltip(editor& ed, const model& mdl, const model_id id)
mdl.tl,
mdl.tn);
auto ret = ed.sim.dispatch_2(
auto ret = ed.sim.dispatch(
mdl.type, [&]<typename DynamicsModels>(DynamicsModels& dyn_models) {
using Dynamics = typename DynamicsModels::value_type;
if constexpr (is_detected_v<has_input_port_t, Dynamics>)
......@@ -2230,7 +2230,7 @@ editor::show_top() noexcept
status
add_popup_menuitem(editor& ed, dynamics_type type, model_id* new_model)
{
return ed.sim.dispatch_2(type, [&](auto& d_array) {
return ed.sim.dispatch(type, [&](auto& d_array) {
if (ImGui::MenuItem(dynamics_type_names[static_cast<i8>(type)])) {
if (!ed.sim.models.can_alloc(1) || !d_array.can_alloc(1))
return status::data_array_not_enough_memory;
......
......@@ -5391,7 +5391,7 @@ struct simulation
constexpr sz e = dynamics_type_size();
for (; i != e; ++i)
if (auto ret = dispatch_2(static_cast<dynamics_type>(i), f);
if (auto ret = dispatch(static_cast<dynamics_type>(i), f);
is_bad(ret))
return ret;
......@@ -5515,9 +5515,9 @@ struct simulation
}
template<typename Function, typename... Args>
constexpr auto dispatch_2(const dynamics_type type,
Function&& f,
Args... args) noexcept
constexpr auto dispatch(const dynamics_type type,
Function&& f,
Args... args) noexcept
{
switch (type) {
case dynamics_type::none:
......@@ -5628,9 +5628,9 @@ struct simulation
}
template<typename Function, typename... Args>
constexpr auto dispatch_2(const dynamics_type type,
Function&& f,
Args... args) const noexcept
constexpr auto dispatch(const dynamics_type type,
Function&& f,
Args... args) const noexcept
{
switch (type) {
case dynamics_type::none:
......@@ -5744,7 +5744,7 @@ struct simulation
const output_port_id port,
int* index) const noexcept
{
return dispatch_2(
return dispatch(
mdl.type,
[dyn_id = mdl.id, port, index]<typename DynamicsM>(
DynamicsM& dyn_models) -> status {
......@@ -5769,7 +5769,7 @@ struct simulation
template<typename Function>
void for_all_input_port(const model& mdl, Function f)
{
dispatch_2(
dispatch(
mdl.type, [this, &f, dyn_id = mdl.id]<typename T>(T& dyn_models) {
using TT = T;
using Dynamics = typename TT::value_type;
......@@ -5787,7 +5787,7 @@ struct simulation
template<typename Function>
void for_all_output_port(const model& mdl, Function f)
{
dispatch_2(
dispatch(
mdl.type, [this, &f, dyn_id = mdl.id]<typename T>(T& dyn_models) {
using TT = T;
using Dynamics = typename TT::value_type;
......@@ -5806,7 +5806,7 @@ struct simulation
const input_port_id port,
int* index) const noexcept
{
return dispatch_2(
return dispatch(
mdl.type,
[dyn_id = mdl.id, port, index]<typename T>(T& dyn_models) -> status {
using TT = T;
......@@ -5832,7 +5832,7 @@ struct simulation
int index,
output_port_id* port) const noexcept
{
return dispatch_2(
return dispatch(
mdl.type,
[dyn_id = mdl.id, index, port]<typename T>(T& dyn_models) -> status {
using TT = T;
......@@ -5858,7 +5858,7 @@ struct simulation
int index,
input_port_id* port) const noexcept
{
return dispatch_2(
return dispatch(
mdl.type,
[dyn_id = mdl.id, index, port]<typename T>(T& dyn_models) -> status {
using TT = T;
......@@ -6133,7 +6133,7 @@ public:
observers.free(*obs);
}
dispatch_2(mdl->type, [&](auto& d_array) {
dispatch(mdl->type, [&](auto& d_array) {
do_deallocate(d_array.get(mdl->id));
d_array.free(mdl->id);
});
......@@ -6421,7 +6421,7 @@ public:
status make_initialize(model& mdl, time t) noexcept
{
return dispatch_2(
return dispatch(
mdl.type,
[this, &mdl, t]<typename DynamicsModels>(DynamicsModels& dyn_models) {
return this->make_initialize(mdl, dyn_models.get(mdl.id), t);
......@@ -6492,12 +6492,12 @@ public:
time t,
flat_list<output_port_id>& o) noexcept
{
return dispatch_2(mdl.type,
[this, &mdl, t, &o]<typename DynamicsModels>(
DynamicsModels& dyn_models) {
return this->make_transition(
mdl, dyn_models.get(mdl.id), t, o);
});
return dispatch(mdl.type,
[this, &mdl, t, &o]<typename DynamicsModels>(
DynamicsModels& dyn_models) {
return this->make_transition(
mdl, dyn_models.get(mdl.id), t, o);
});
}
};
......
......@@ -693,7 +693,7 @@ private:
status::io_file_format_dynamics_unknown);
model_id mdl_id = static_cast<model_id>(0);
auto ret = sim.dispatch_2(type, [this, &sim, &mdl_id](auto& dyn_models) {
auto ret = sim.dispatch(type, [this, &sim, &mdl_id](auto& dyn_models) {
irt_return_if_fail(dyn_models.can_alloc(1),
status::io_file_format_dynamics_limit_reach);
auto& dyn = dyn_models.alloc();
......@@ -1076,7 +1076,7 @@ struct writer
os << id << ' ';
map[id] = mdl_id;
sim.dispatch_2(mdl->type, [this, mdl](auto& dyn_models) {
sim.dispatch(mdl->type, [this, mdl](auto& dyn_models) {
write(dyn_models.get(mdl->id));
});
......
......@@ -594,16 +594,16 @@ main()
auto& mdl = sim.models.get(dyn1.id);
sim.dispatch_2(mdl.type, [](const auto& dyns) { std::cout << "ok"; });
sim.dispatch(mdl.type, [](const auto& dyns) { std::cout << "ok"; });
auto ret = sim.dispatch_2(mdl.type, [](const auto& dyns) {
auto ret = sim.dispatch(mdl.type, [](const auto& dyns) {
std::cout << "ok";
return 1;
});
expect(ret == 1);
auto ret_2 = sim.dispatch_2(
auto ret_2 = sim.dispatch(
mdl.type,
[](const auto& dyns, int v1, double v2) {
std::cout << "ok" << v1 << ' ' << v2;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment