Commit c722a5f2 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: update coding style

parent 69e02c7f
......@@ -14,7 +14,6 @@
#include <cstdint>
#include <cstring>
namespace irt {
using i8 = int8_t;
......@@ -1636,8 +1635,8 @@ public:
std::free(items);
}
items = static_cast<value_type*>(std::malloc(
new_capacity * sizeof(value_type)));
items = static_cast<value_type*>(
std::malloc(new_capacity * sizeof(value_type)));
for (u32 i = 0; i != capacity; ++i)
new (&items[i]) T();
......@@ -1682,6 +1681,11 @@ public:
{
return items + capacity;
}
size_t size() const noexcept
{
return capacity;
}
};
/*****************************************************************************
......@@ -2044,6 +2048,14 @@ public:
return nullptr;
}
T* try_to_get(u32 index) const noexcept
{
if (is_valid(m_items[index].id))
return &m_items[index].item;
return nullptr;
}
/**
* @brief Return next valid item.
* @code
......@@ -2554,8 +2566,7 @@ struct helper
} // namespace detail
template<template<class...> class Operation, typename... Arguments>
using is_detected =
detail::is_detected<std::void_t<>, Operation, Arguments...>;
using is_detected = detail::is_detected<std::void_t<>, Operation, Arguments...>;
template<template<class...> class Operation, typename... Arguments>
constexpr bool is_detected_v =
......@@ -2610,9 +2621,7 @@ struct adder
PortNumber,
1.0 / static_cast<double>(PortNumber));
std::fill_n(std::begin(default_input_coeffs),
PortNumber,
0.0);
std::fill_n(std::begin(default_input_coeffs), PortNumber, 0.0);
}
status initialize(data_array<message, message_id>& /*init*/) noexcept
......@@ -2698,8 +2707,7 @@ struct mult
status initialize(data_array<message, message_id>& /*init*/) noexcept
{
std::copy_n(
std::begin(default_values), PortNumber, std::begin(values));
std::copy_n(std::begin(default_values), PortNumber, std::begin(values));
std::copy_n(std::begin(default_input_coeffs),
PortNumber,
......@@ -2734,11 +2742,9 @@ struct mult
for (size_t i = 0; i != PortNumber; ++i) {
if (auto* port = input_ports.try_to_get(x[i]); port) {
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);
irt_return_if_fail(
msg.size() == 1,
irt_return_if_fail(msg.size() == 1,
status::model_mult_bad_external_message);
values[i] = msg.to_real_64(0);
......@@ -2869,7 +2875,7 @@ struct time_func
output_port_id y[1];
time sigma;
double(*default_f)(double);
double (*default_f)(double);
double value;
double (*f)(double) = nullptr;
......@@ -2888,7 +2894,7 @@ struct time_func
time /*r*/) noexcept
{
sigma = (*f)(t) ;
sigma = (*f)(t);
value = sigma;
return status::success;
......@@ -2947,14 +2953,12 @@ struct cross
if (auto* port = input_ports.try_to_get(x[port_value]); port) {
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);
irt_return_if_fail(
msg.size() == 1,
irt_return_if_fail(msg.size() == 1,
status::model_cross_bad_external_message);
value = msg.to_real_64(0) ;
value = msg.to_real_64(0);
have_message = true;
}
......@@ -2963,11 +2967,9 @@ struct cross
if (auto* port = input_ports.try_to_get(x[port_if_value]); port) {
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);
irt_return_if_fail(
msg.size() == 1,
irt_return_if_fail(msg.size() == 1,
status::model_cross_bad_external_message);
if_value = msg.to_real_64(0);
......@@ -2977,11 +2979,9 @@ struct cross
if (auto* port = input_ports.try_to_get(x[port_else_value]); port) {
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);
irt_return_if_fail(
msg.size() == 1,
irt_return_if_fail(msg.size() == 1,
status::model_cross_bad_external_message);
else_value = msg.to_real_64(0);
......@@ -3147,7 +3147,8 @@ struct integrator
auto* port_2 = input_ports.try_to_get(x[port_x_dot]);
auto* port_3 = input_ports.try_to_get(x[port_reset]);
if (port_1->messages.empty() && port_2->messages.empty() && port_3->messages.empty()) {
if (port_1->messages.empty() && port_2->messages.empty() &&
port_3->messages.empty()) {
irt_return_if_bad(internal(t));
} else {
if (time_domain<time>::is_zero(r))
......@@ -3272,7 +3273,6 @@ struct quantifier
down
};
double default_step_size = 0.0;
int default_past_length = 3;
adapt_state default_adapt_state = adapt_state::possible;
......@@ -3302,9 +3302,11 @@ struct quantifier
archive.clear();
m_state = state::init;
irt_return_if_fail(m_step_size > 0, status::model_quantifier_bad_quantum_parameter);
irt_return_if_fail(m_step_size > 0,
status::model_quantifier_bad_quantum_parameter);
irt_return_if_fail(m_past_length > 2,
irt_return_if_fail(
m_past_length > 2,
status::model_quantifier_bad_archive_length_parameter);
sigma = time_domain<time>::infinity;
......@@ -3351,8 +3353,7 @@ struct quantifier
shifting_factor = shift_quanta();
irt_return_if_fail(
shifting_factor >= 0,
irt_return_if_fail(shifting_factor >= 0,
status::model_quantifier_shifting_value_neg);
irt_return_if_fail(
shifting_factor <= 1,
......@@ -3435,8 +3436,7 @@ private:
{
const auto step_number = static_cast<double>(m_step_number);
m_upthreshold =
m_offset + m_step_size * (step_number + (1.0 - factor));
m_upthreshold = m_offset + m_step_size * (step_number + (1.0 - factor));
m_downthreshold =
m_offset + m_step_size * (step_number - (1.0 - factor));
}
......@@ -3463,8 +3463,7 @@ private:
if (m_zero_init_offset) {
m_offset = 0.0;
} else {
m_offset =
value - static_cast<double>(m_step_number) * m_step_size;
m_offset = value - static_cast<double>(m_step_number) * m_step_size;
}
}
......@@ -3488,8 +3487,8 @@ private:
local_estim = 1 - (it_1->date - it_0->date) /
(it_2->date - it_0->date);
} else {
local_estim = (it_1->date - it_0->date) /
(it_2->date - it_0->date);
local_estim =
(it_1->date - it_0->date) / (it_2->date - it_0->date);
}
acc += local_estim;
......@@ -3742,8 +3741,7 @@ struct simulation
dynamics_id id,
const char* name = nullptr) noexcept
{
irt_return_if_fail(!models.full(),
status::simulation_not_enough_model);
irt_return_if_fail(!models.full(), status::simulation_not_enough_model);
model& mdl = models.alloc();
model_id mdl_id = models.get_id(mdl);
......@@ -3893,10 +3891,7 @@ struct simulation
}
template<typename Dynamics>
status make_initialize(
model& mdl,
Dynamics& dyn,
time t) noexcept
status make_initialize(model& mdl, Dynamics& dyn, time t) noexcept
{
if constexpr (is_detected_v<initialize_function_t, Dynamics>)
irt_return_if_bad(dyn.initialize(messages));
......
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