Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
irritator
Commits
1538ba73
Commit
1538ba73
authored
May 12, 2020
by
Gauthier Quesnel
Browse files
core: remove in/out port checks
parent
8974a097
Pipeline
#12173
passed with stage
in 1 minute and 4 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
lib/include/irritator/core.hpp
View file @
1538ba73
...
@@ -129,7 +129,7 @@ is_status_equal(status s, Args... args) noexcept
...
@@ -129,7 +129,7 @@ is_status_equal(status s, Args... args) noexcept
template
<
typename
T
,
typename
...
Args
>
template
<
typename
T
,
typename
...
Args
>
constexpr
bool
constexpr
bool
match
(
const
T
&
s
,
Args
...
args
)
noexcept
match
(
const
T
&
s
,
Args
...
args
)
noexcept
{
{
return
((
s
==
args
)
||
...
||
false
);
return
((
s
==
args
)
||
...
||
false
);
}
}
...
@@ -3188,18 +3188,18 @@ struct integrator
...
@@ -3188,18 +3188,18 @@ struct integrator
time
/*e*/
,
time
/*e*/
,
time
r
)
noexcept
time
r
)
noexcept
{
{
auto
*
port_1
=
input_ports
.
try_to_
get
(
x
[
port_quanta
]);
auto
&
port_1
=
input_ports
.
get
(
x
[
port_quanta
]);
auto
*
port_2
=
input_ports
.
try_to_
get
(
x
[
port_x_dot
]);
auto
&
port_2
=
input_ports
.
get
(
x
[
port_x_dot
]);
auto
*
port_3
=
input_ports
.
try_to_
get
(
x
[
port_reset
]);
auto
&
port_3
=
input_ports
.
get
(
x
[
port_reset
]);
if
(
port_1
->
messages
.
empty
()
&&
port_2
->
messages
.
empty
()
&&
if
(
port_1
.
messages
.
empty
()
&&
port_2
.
messages
.
empty
()
&&
port_3
->
messages
.
empty
())
{
port_3
.
messages
.
empty
())
{
irt_return_if_bad
(
internal
(
t
));
irt_return_if_bad
(
internal
(
t
));
}
else
{
}
else
{
if
(
time_domain
<
time
>::
is_zero
(
r
))
if
(
time_domain
<
time
>::
is_zero
(
r
))
irt_return_if_bad
(
internal
(
t
));
irt_return_if_bad
(
internal
(
t
));
irt_return_if_bad
(
external
(
*
port_1
,
*
port_2
,
*
port_3
,
t
));
irt_return_if_bad
(
external
(
port_1
,
port_2
,
port_3
,
t
));
}
}
return
ta
();
return
ta
();
...
@@ -3208,18 +3208,17 @@ struct integrator
...
@@ -3208,18 +3208,17 @@ struct integrator
status
lambda
(
status
lambda
(
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
{
{
if
(
auto
*
port
=
output_ports
.
try_to_
get
(
y
[
0
]);
port
)
{
auto
&
port
=
output_ports
.
get
(
y
[
0
]);
switch
(
st
)
{
switch
(
st
)
{
case
state
::
running
:
case
state
::
running
:
port
->
messages
.
emplace_front
(
expected_value
);
port
.
messages
.
emplace_front
(
expected_value
);
return
status
::
success
;
return
status
::
success
;
case
state
::
init
:
case
state
::
init
:
port
->
messages
.
emplace_front
(
current_value
);
port
.
messages
.
emplace_front
(
current_value
);
return
status
::
success
;
return
status
::
success
;
default:
default:
return
status
::
model_integrator_output_error
;
return
status
::
model_integrator_output_error
;
}
}
}
return
status
::
success
;
return
status
::
success
;
}
}
...
@@ -3462,14 +3461,15 @@ struct quantifier
...
@@ -3462,14 +3461,15 @@ struct quantifier
time
/*e*/
,
time
/*e*/
,
time
r
)
noexcept
time
r
)
noexcept
{
{
auto
*
port
=
input_ports
.
try_to_get
(
x
[
0
]);
auto
&
port
=
input_ports
.
get
(
x
[
0
]);
if
(
port
&&
port
->
messages
.
empty
())
{
if
(
port
.
messages
.
empty
())
{
irt_return_if_bad
(
internal
());
irt_return_if_bad
(
internal
());
}
else
{
}
else
{
if
(
time_domain
<
time
>::
is_zero
(
r
))
if
(
time_domain
<
time
>::
is_zero
(
r
))
irt_return_if_bad
(
internal
());
irt_return_if_bad
(
internal
());
irt_return_if_bad
(
external
(
*
port
,
t
));
irt_return_if_bad
(
external
(
port
,
t
));
}
}
return
ta
();
return
ta
();
...
@@ -3661,12 +3661,10 @@ struct adder
...
@@ -3661,12 +3661,10 @@ struct adder
{
{
double
to_send
=
0.0
;
double
to_send
=
0.0
;
if
(
auto
*
port
=
output_ports
.
try_to_get
(
y
[
0
]);
port
)
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
to_send
+=
input_coeffs
[
i
]
*
values
[
i
];
to_send
+=
input_coeffs
[
i
]
*
values
[
i
];
port
->
messages
.
emplace_front
(
to_send
);
output_ports
.
get
(
y
[
0
]).
messages
.
emplace_front
(
to_send
);
}
return
status
::
success
;
return
status
::
success
;
}
}
...
@@ -3679,13 +3677,10 @@ struct adder
...
@@ -3679,13 +3677,10 @@ struct adder
bool
have_message
=
false
;
bool
have_message
=
false
;
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
if
(
auto
*
port
=
input_ports
.
try_to_get
(
x
[
i
]);
port
)
{
for
(
const
auto
&
msg
:
input_ports
.
get
(
x
[
i
]).
messages
)
{
for
(
const
auto
&
msg
:
port
->
messages
)
{
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
status
::
model_adder_bad_external_message
);
status
::
model_adder_bad_external_message
);
irt_return_if_fail
(
irt_return_if_fail
(
msg
.
size
()
==
1
,
msg
.
size
()
==
1
,
status
::
model_adder_bad_external_message
);
status
::
model_adder_bad_external_message
);
values
[
i
]
=
msg
.
to_real_64
(
0
);
values
[
i
]
=
msg
.
to_real_64
(
0
);
...
@@ -3693,7 +3688,6 @@ struct adder
...
@@ -3693,7 +3688,6 @@ struct adder
have_message
=
true
;
have_message
=
true
;
}
}
}
}
}
sigma
=
sigma
=
have_message
?
time_domain
<
time
>::
zero
:
time_domain
<
time
>::
infinity
;
have_message
?
time_domain
<
time
>::
zero
:
time_domain
<
time
>::
infinity
;
...
@@ -3752,12 +3746,10 @@ struct mult
...
@@ -3752,12 +3746,10 @@ struct mult
{
{
double
to_send
=
1.0
;
double
to_send
=
1.0
;
if
(
auto
*
port
=
output_ports
.
try_to_get
(
y
[
0
]);
port
)
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
to_send
*=
std
::
pow
(
values
[
i
],
input_coeffs
[
i
]);
to_send
*=
std
::
pow
(
values
[
i
],
input_coeffs
[
i
]);
port
->
messages
.
emplace_front
(
to_send
);
output_ports
.
get
(
y
[
0
]).
messages
.
emplace_front
(
to_send
);
}
return
status
::
success
;
return
status
::
success
;
}
}
...
@@ -3769,8 +3761,7 @@ struct mult
...
@@ -3769,8 +3761,7 @@ struct mult
{
{
bool
have_message
=
false
;
bool
have_message
=
false
;
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
if
(
auto
*
port
=
input_ports
.
try_to_get
(
x
[
i
]);
port
)
{
for
(
const
auto
&
msg
:
input_ports
.
get
(
x
[
i
]).
messages
)
{
for
(
const
auto
&
msg
:
port
->
messages
)
{
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
status
::
model_mult_bad_external_message
);
status
::
model_mult_bad_external_message
);
irt_return_if_fail
(
msg
.
size
()
==
1
,
irt_return_if_fail
(
msg
.
size
()
==
1
,
...
@@ -3780,7 +3771,6 @@ struct mult
...
@@ -3780,7 +3771,6 @@ struct mult
have_message
=
true
;
have_message
=
true
;
}
}
}
}
}
sigma
=
sigma
=
have_message
?
time_domain
<
time
>::
zero
:
time_domain
<
time
>::
infinity
;
have_message
?
time_domain
<
time
>::
zero
:
time_domain
<
time
>::
infinity
;
...
@@ -3820,10 +3810,10 @@ struct counter
...
@@ -3820,10 +3810,10 @@ struct counter
time
/*e*/
,
time
/*e*/
,
time
/*r*/
)
noexcept
time
/*r*/
)
noexcept
{
{
std
::
ptrdiff_t
diff
{
0
}
;
auto
&
port
=
input_ports
.
get
(
x
[
0
])
;
if
(
auto
*
port
=
input_ports
.
try_to_get
(
x
[
0
]);
port
)
diff
+=
std
::
distance
(
std
::
begin
(
port
->
messages
),
const
auto
diff
=
std
::
end
(
port
->
messages
));
std
::
distance
(
std
::
begin
(
port
.
messages
),
std
::
end
(
port
.
messages
));
number
+=
static_cast
<
i64
>
(
diff
);
number
+=
static_cast
<
i64
>
(
diff
);
...
@@ -3914,9 +3904,7 @@ struct constant
...
@@ -3914,9 +3904,7 @@ struct constant
status
lambda
(
status
lambda
(
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
{
{
auto
&
port
=
output_ports
.
get
(
y
[
0
]);
output_ports
.
get
(
y
[
0
]).
messages
.
emplace_front
(
value
);
port
.
messages
.
emplace_front
(
value
);
return
status
::
success
;
return
status
::
success
;
}
}
...
@@ -3954,22 +3942,22 @@ struct accumulator
...
@@ -3954,22 +3942,22 @@ struct accumulator
{
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
if
(
auto
*
port
=
input_ports
.
try_to_
get
(
x
[
i
+
PortNumber
]);
port
)
{
auto
&
port
=
input_ports
.
get
(
x
[
i
+
PortNumber
]);
for
(
const
auto
&
msg
:
port
->
messages
)
{
for
(
const
auto
&
msg
:
port
.
messages
)
{
irt_return_if_fail
(
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
msg
.
type
==
value_type
::
real_64
,
status
::
model_accumulator_bad_external_message
);
status
::
model_accumulator_bad_external_message
);
irt_return_if_fail
(
irt_return_if_fail
(
msg
.
size
()
==
1
,
msg
.
size
()
==
1
,
status
::
model_accumulator_bad_external_message
);
status
::
model_accumulator_bad_external_message
);
numbers
[
i
]
=
msg
.
to_real_64
(
0
);
numbers
[
i
]
=
msg
.
to_real_64
(
0
);
}
}
}
}
}
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
PortNumber
;
++
i
)
{
if
(
auto
*
port
=
input_ports
.
try_to_
get
(
x
[
i
]);
port
)
{
auto
&
port
=
input_ports
.
get
(
x
[
i
]);
for
(
const
auto
&
msg
:
port
->
messages
)
{
for
(
const
auto
&
msg
:
port
.
messages
)
{
irt_return_if_fail
(
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
msg
.
type
==
value_type
::
real_64
,
status
::
model_accumulator_bad_external_message
);
status
::
model_accumulator_bad_external_message
);
...
@@ -3977,12 +3965,10 @@ struct accumulator
...
@@ -3977,12 +3965,10 @@ struct accumulator
msg
.
size
()
==
1
,
msg
.
size
()
==
1
,
status
::
model_accumulator_bad_external_message
);
status
::
model_accumulator_bad_external_message
);
if
(
msg
.
to_real_64
(
0
)
!=
0.0
)
{
if
(
msg
.
to_real_64
(
0
)
!=
0.0
)
number
+=
numbers
[
i
];
number
+=
numbers
[
i
];
}
}
}
}
}
}
return
status
::
success
;
return
status
::
success
;
}
}
...
@@ -4033,9 +4019,7 @@ struct cross
...
@@ -4033,9 +4019,7 @@ struct cross
bool
have_message
=
false
;
bool
have_message
=
false
;
bool
have_message_value
=
false
;
bool
have_message_value
=
false
;
if
(
auto
*
port
=
input_ports
.
try_to_get
(
x
[
port_value
]);
port
)
{
for
(
const
auto
&
msg
:
input_ports
.
get
(
x
[
port_value
]).
messages
)
{
for
(
const
auto
&
msg
:
port
->
messages
)
{
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
status
::
model_cross_bad_external_message
);
status
::
model_cross_bad_external_message
);
irt_return_if_fail
(
msg
.
size
()
==
1
,
irt_return_if_fail
(
msg
.
size
()
==
1
,
...
@@ -4043,28 +4027,20 @@ struct cross
...
@@ -4043,28 +4027,20 @@ struct cross
value
=
msg
.
to_real_64
(
0
);
value
=
msg
.
to_real_64
(
0
);
have_message_value
=
true
;
have_message_value
=
true
;
have_message
=
true
;
have_message
=
true
;
}
}
}
if
(
auto
*
port
=
input_ports
.
try_to_get
(
x
[
port_if_value
]);
port
)
{
for
(
const
auto
&
msg
:
port
->
messages
)
{
for
(
const
auto
&
msg
:
input_ports
.
get
(
x
[
port_if_value
]).
messages
)
{
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
status
::
model_cross_bad_external_message
);
status
::
model_cross_bad_external_message
);
irt_return_if_fail
(
msg
.
size
()
==
1
,
irt_return_if_fail
(
msg
.
size
()
==
1
,
status
::
model_cross_bad_external_message
);
status
::
model_cross_bad_external_message
);
if_value
=
msg
.
to_real_64
(
0
);
if_value
=
msg
.
to_real_64
(
0
);
have_message
=
true
;
have_message
=
true
;
}
}
}
if
(
auto
*
port
=
input_ports
.
try_to_get
(
x
[
port_else_value
]);
port
)
{
for
(
const
auto
&
msg
:
port
->
messages
)
{
for
(
const
auto
&
msg
:
input_ports
.
get
(
x
[
port_else_value
]).
messages
)
{
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
irt_return_if_fail
(
msg
.
type
==
value_type
::
real_64
,
status
::
model_cross_bad_external_message
);
status
::
model_cross_bad_external_message
);
irt_return_if_fail
(
msg
.
size
()
==
1
,
irt_return_if_fail
(
msg
.
size
()
==
1
,
...
@@ -4073,27 +4049,29 @@ struct cross
...
@@ -4073,27 +4049,29 @@ struct cross
else_value
=
msg
.
to_real_64
(
0
);
else_value
=
msg
.
to_real_64
(
0
);
have_message
=
true
;
have_message
=
true
;
}
}
}
if
(
have_message_value
)
{
if
(
have_message_value
)
{
else_value
=
value
>=
threshold
?
if_value
:
else_value
;
if
(
value
>=
threshold
)
{
event
=
value
>=
threshold
?
1.0
:
0.0
;
else_value
=
if_value
;
event
=
1.0
;
}
else
{
event
=
0.0
;
}
}
}
result
=
else_value
;
result
=
else_value
;
sigma
=
sigma
=
have_message
?
time_domain
<
time
>::
zero
:
time_domain
<
time
>::
infinity
;
have_message
?
time_domain
<
time
>::
zero
:
time_domain
<
time
>::
infinity
;
return
status
::
success
;
return
status
::
success
;
}
}
status
lambda
(
status
lambda
(
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
{
{
if
(
auto
*
port
=
output_ports
.
try_to_get
(
y
[
0
]);
port
)
output_ports
.
get
(
y
[
0
]).
messages
.
emplace_front
(
result
);
port
->
messages
.
emplace_front
(
result
);
output_ports
.
get
(
y
[
1
]).
messages
.
emplace_front
(
event
);
if
(
auto
*
port
=
output_ports
.
try_to_get
(
y
[
1
]);
port
)
port
->
messages
.
emplace_front
(
event
);
return
status
::
success
;
return
status
::
success
;
}
}
...
@@ -4150,8 +4128,7 @@ struct time_func
...
@@ -4150,8 +4128,7 @@ struct time_func
status
lambda
(
status
lambda
(
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
data_array
<
output_port
,
output_port_id
>&
output_ports
)
noexcept
{
{
auto
&
port
=
output_ports
.
get
(
y
[
0
]);
output_ports
.
get
(
y
[
0
]).
messages
.
emplace_front
(
value
);
port
.
messages
.
emplace_front
(
value
);
return
status
::
success
;
return
status
::
success
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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