Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Maintenance - Mise à jour mensuelle Lundi 6 Février entre 7h00 et 9h00
Open sidebar
Gauthier Quesnel
irritator
Commits
3cd37d83
Commit
3cd37d83
authored
Dec 06, 2020
by
Gauthier Quesnel
Browse files
core: use the newest dispatch function
parent
9955be8c
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/gui/node-editor.cpp
View file @
3cd37d83
...
...
@@ -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
(
auto
ret
=
sim
.
dispatch
_2
(
mdl
->
type
,
[
this
,
&
sim
,
mdl
,
&
mdl_id_dst
]
<
typename
DynamicsM
>
(
DynamicsM
&
dynamics_models
)
->
status
{
...
...
@@ -2036,24 +2036,22 @@ editor::show_model_dynamics(model& mdl) noexcept
ImGui
::
PopItemWidth
();
if
(
simulation_show_value
&&
st
!=
editor_status
::
editing
)
{
sim
.
dispatch
(
mdl
.
type
,
[
&
](
const
auto
&
d_array
)
{
sim
.
dispatch
_2
(
mdl
.
type
,
[
&
](
const
auto
&
d_array
)
{
const
auto
&
dyn
=
d_array
.
get
(
mdl
.
id
);
add_input_attribute
(
*
this
,
dyn
);
ImGui
::
PushItemWidth
(
120.0
f
);
show_dynamics_values
(
dyn
);
ImGui
::
PopItemWidth
();
add_output_attribute
(
*
this
,
dyn
);
return
status
::
success
;
});
}
else
{
sim
.
dispatch
(
mdl
.
type
,
[
&
](
auto
&
d_array
)
{
sim
.
dispatch
_2
(
mdl
.
type
,
[
&
](
auto
&
d_array
)
{
auto
&
dyn
=
d_array
.
get
(
mdl
.
id
);
add_input_attribute
(
*
this
,
dyn
);
ImGui
::
PushItemWidth
(
120.0
f
);
show_dynamics_inputs
(
dyn
);
ImGui
::
PopItemWidth
();
add_output_attribute
(
*
this
,
dyn
);
return
status
::
success
;
});
}
}
...
...
@@ -2109,12 +2107,13 @@ show_tooltip(editor& ed, const model& mdl, const model_id id)
mdl
.
tl
,
mdl
.
tn
);
auto
ret
=
ed
.
sim
.
dispatch
(
auto
ret
=
ed
.
sim
.
dispatch
_2
(
mdl
.
type
,
[
&
]
<
typename
DynamicsModels
>
(
DynamicsModels
&
dyn_models
)
{
using
Dynamics
=
typename
DynamicsModels
::
value_type
;
if
constexpr
(
is_detected_v
<
has_input_port_t
,
Dynamics
>
)
return
make_input_tooltip
(
ed
,
dyn_models
.
get
(
mdl
.
id
),
ed
.
tooltip
);
return
status
::
success
;
});
...
...
@@ -2231,7 +2230,7 @@ editor::show_top() noexcept
status
add_popup_menuitem
(
editor
&
ed
,
dynamics_type
type
,
model_id
*
new_model
)
{
return
ed
.
sim
.
dispatch
(
type
,
[
&
](
auto
&
d_array
)
{
return
ed
.
sim
.
dispatch
_2
(
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
;
...
...
lib/include/irritator/core.hpp
View file @
3cd37d83
...
...
@@ -5391,7 +5391,7 @@ struct simulation
constexpr
sz
e
=
dynamics_type_size
();
for
(;
i
!=
e
;
++
i
)
if
(
auto
ret
=
dispatch
(
static_cast
<
dynamics_type
>
(
i
),
f
);
if
(
auto
ret
=
dispatch
_2
(
static_cast
<
dynamics_type
>
(
i
),
f
);
is_bad
(
ret
))
return
ret
;
...
...
@@ -5993,7 +5993,7 @@ struct simulation
template
<
typename
Function
>
void
for_all_input_port
(
const
model
&
mdl
,
Function
f
)
{
dispatch
(
dispatch
_2
(
mdl
.
type
,
[
this
,
&
f
,
dyn_id
=
mdl
.
id
]
<
typename
T
>
(
T
&
dyn_models
)
{
using
TT
=
T
;
using
Dynamics
=
typename
TT
::
value_type
;
...
...
@@ -6005,14 +6005,13 @@ struct simulation
port
)
f
(
*
port
,
dyn
->
x
[
i
]);
}
return
status
::
success
;
});
}
template
<
typename
Function
>
void
for_all_output_port
(
const
model
&
mdl
,
Function
f
)
{
dispatch
(
dispatch
_2
(
mdl
.
type
,
[
this
,
&
f
,
dyn_id
=
mdl
.
id
]
<
typename
T
>
(
T
&
dyn_models
)
{
using
TT
=
T
;
using
Dynamics
=
typename
TT
::
value_type
;
...
...
@@ -6024,8 +6023,6 @@ struct simulation
port
)
f
(
*
port
,
dyn
->
y
[
i
]);
}
return
status
::
success
;
});
}
...
...
@@ -6033,7 +6030,7 @@ struct simulation
const
input_port_id
port
,
int
*
index
)
const
noexcept
{
return
dispatch
(
return
dispatch
_2
(
mdl
.
type
,
[
dyn_id
=
mdl
.
id
,
port
,
index
]
<
typename
T
>
(
T
&
dyn_models
)
->
status
{
using
TT
=
T
;
...
...
@@ -6059,7 +6056,7 @@ struct simulation
int
index
,
output_port_id
*
port
)
const
noexcept
{
return
dispatch
(
return
dispatch
_2
(
mdl
.
type
,
[
dyn_id
=
mdl
.
id
,
index
,
port
]
<
typename
T
>
(
T
&
dyn_models
)
->
status
{
using
TT
=
T
;
...
...
@@ -6085,7 +6082,7 @@ struct simulation
int
index
,
input_port_id
*
port
)
const
noexcept
{
return
dispatch
(
return
dispatch
_2
(
mdl
.
type
,
[
dyn_id
=
mdl
.
id
,
index
,
port
]
<
typename
T
>
(
T
&
dyn_models
)
->
status
{
using
TT
=
T
;
...
...
@@ -6352,8 +6349,7 @@ public:
status
deallocate
(
model_id
id
)
{
auto
*
mdl
=
models
.
try_to_get
(
id
);
if
(
!
mdl
)
return
status
::
success
;
irt_return_if_fail
(
mdl
,
status
::
unknown_dynamics
);
if
(
auto
*
obs
=
observers
.
try_to_get
(
mdl
->
obs_id
);
obs
)
{
obs
->
model
=
static_cast
<
model_id
>
(
0
);
...
...
@@ -6361,16 +6357,15 @@ public:
observers
.
free
(
*
obs
);
}
auto
ret
=
dispatch
(
mdl
->
type
,
[
&
](
auto
&
d_array
)
{
dispatch
_2
(
mdl
->
type
,
[
&
](
auto
&
d_array
)
{
do_deallocate
(
d_array
.
get
(
mdl
->
id
));
d_array
.
free
(
mdl
->
id
);
return
status
::
success
;
});
sched
.
erase
(
*
mdl
);
models
.
free
(
*
mdl
);
return
ret
;
return
status
::
success
;
}
template
<
typename
Dynamics
>
...
...
@@ -6650,7 +6645,7 @@ public:
status
make_initialize
(
model
&
mdl
,
time
t
)
noexcept
{
return
dispatch
(
return
dispatch
_2
(
mdl
.
type
,
[
this
,
&
mdl
,
t
]
<
typename
DynamicsModels
>
(
DynamicsModels
&
dyn_models
)
{
return
this
->
make_initialize
(
mdl
,
dyn_models
.
get
(
mdl
.
id
),
t
);
...
...
@@ -6721,12 +6716,12 @@ public:
time
t
,
flat_list
<
output_port_id
>&
o
)
noexcept
{
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
);
});
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
);
});
}
};
...
...
lib/include/irritator/io.hpp
View file @
3cd37d83
...
...
@@ -693,7 +693,7 @@ private:
status
::
io_file_format_dynamics_unknown
);
model_id
mdl_id
=
static_cast
<
model_id
>
(
0
);
auto
ret
=
sim
.
dispatch
(
type
,
[
this
,
&
sim
,
&
mdl_id
](
auto
&
dyn_models
)
{
auto
ret
=
sim
.
dispatch
_2
(
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,9 +1076,8 @@ struct writer
os
<<
id
<<
' '
;
map
[
id
]
=
mdl_id
;
sim
.
dispatch
(
mdl
->
type
,
[
this
,
mdl
](
auto
&
dyn_models
)
{
sim
.
dispatch
_2
(
mdl
->
type
,
[
this
,
mdl
](
auto
&
dyn_models
)
{
write
(
dyn_models
.
get
(
mdl
->
id
));
return
status
::
success
;
});
++
id
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment