Commit 525b6c07 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: cleanup error code

parent 40bf2a9e
......@@ -181,17 +181,15 @@ struct editor
bool show_simulation_box = true;
bool stop = false;
bool initialize() noexcept
status initialize() noexcept
{
if (!is_success(sim.init(1024u, 32768u)))
return false;
if (!is_success(observation_outputs.init(sim.models.capacity())))
return false;
if (is_bad(sim.init(1024u, 32768u)) ||
is_bad(observation_outputs.init(sim.models.capacity())))
return status::gui_not_enough_memory;
initialized = true;
return true;
return status::success;
}
status initialize_lotka_volterra() noexcept
......@@ -270,6 +268,15 @@ struct editor
status initialize_izhikevitch()
{
if (!sim.constant_models.can_alloc(3) ||
!sim.adder_2_models.can_alloc(3) ||
!sim.adder_4_models.can_alloc(1) ||
!sim.mult_2_models.can_alloc(1) ||
!sim.integrator_models.can_alloc(2) ||
!sim.quantifier_models.can_alloc(2) ||
!sim.cross_models.can_alloc(2) || !sim.models.can_alloc(14))
return status::simulation_not_enough_model;
auto& constant = sim.constant_models.alloc();
auto& constant2 = sim.constant_models.alloc();
auto& constant3 = sim.constant_models.alloc();
......@@ -329,9 +336,6 @@ struct editor
sum_d.default_input_coeffs[0] = 1.0;
sum_d.default_input_coeffs[1] = d;
irt_return_if_fail(sim.models.can_alloc(14),
status::gui_too_many_model);
irt_return_if_bad(
sim.alloc(constant3, sim.constant_models.get_id(constant3), "tfun"));
irt_return_if_bad(
......
......@@ -44,8 +44,6 @@ enum class status
head_allocator_bad_capacity,
head_allocator_not_enough_memory,
scheduller_not_enough_memory,
simulation_not_enough_model,
simulation_not_enough_memory_message_list_allocator,
simulation_not_enough_memory_input_port_list_allocator,
......@@ -65,8 +63,6 @@ enum class status
vector_init_capacity_too_big,
vector_init_not_enough_memory,
model_uninitialized_port_warning,
dynamics_unknown_id,
dynamics_unknown_port_id,
dynamics_not_enough_memory,
......@@ -87,37 +83,19 @@ enum class status
model_integrator_output_error,
model_integrator_running_without_x_dot,
model_integrator_ta_with_bad_x_dot,
model_integrator_empty_init_message,
model_integrator_bad_init_message,
model_integrator_bad_external_message,
model_quantifier_empty_init_allow_offsets,
model_quantifier_bad_init_allow_offsets,
model_quantifier_empty_init_zero_init_offset,
model_quantifier_bad_init_zero_init_offset,
model_quantifier_empty_init_quantum,
model_quantifier_bad_init_quantum,
model_quantifier_empty_init_archive_lenght,
model_quantifier_bad_init_archive_lenght,
model_quantifier_bad_quantum_parameter,
model_quantifier_bad_archive_length_parameter,
model_quantifier_shifting_value_neg,
model_quantifier_shifting_value_less_1,
model_quantifier_bad_external_message,
model_constant_empty_init_message,
model_constant_bad_init_message,
model_cross_empty_init_message,
model_cross_bad_init_message,
model_cross_bad_external_message,
model_time_func_empty_init_message,
model_time_func_bad_init_message,
gui_not_enough_memory,
gui_too_many_model,
gui_too_many_connection,
io_file_format_error,
io_file_format_model_error,
......@@ -147,20 +125,6 @@ is_status_equal(status s, Args... args) noexcept
return ((s == args) || ... || false);
}
constexpr bool
is_not_enough_memory(status s) noexcept
{
return is_status_equal(
s,
status::block_allocator_not_enough_memory,
status::head_allocator_not_enough_memory,
status::scheduller_not_enough_memory,
status::simulation_not_enough_memory_message_list_allocator,
status::simulation_not_enough_memory_input_port_list_allocator,
status::simulation_not_enough_memory_output_port_list_allocator,
status::data_array_not_enough_memory);
}
#ifndef NDEBUG
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__) && \
__GNUC__ >= 2
......@@ -4042,11 +4006,8 @@ public:
status init(size_t capacity) noexcept
{
if (auto ret = m_heap.init(capacity); is_bad(ret))
return ret;
if (auto ret = m_list_allocator.init(capacity); is_bad(ret))
return ret;
irt_return_if_bad(m_heap.init(capacity));
irt_return_if_bad(m_list_allocator.init(capacity));
m_list.set_allocator(&m_list_allocator);
......
......@@ -166,12 +166,10 @@ main()
irt::status s1 = irt::status::success;
expect(irt::is_success(s1) == true);
expect(irt::is_bad(s1) == false);
expect(irt::is_not_enough_memory(s1) == false);
irt::status s2 = irt::status::block_allocator_not_enough_memory;
expect(irt::is_success(s2) == false);
expect(irt::is_bad(s2) == true);
expect(irt::is_not_enough_memory(s2) == true);
};
"time"_test = [] {
......
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