// Copyright (c) 2020 INRA Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef ORG_VLEPROJECT_IRRITATOR_2020 #define ORG_VLEPROJECT_IRRITATOR_2020 #include #include #include #include #include #include #include namespace irt { using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using sz = size_t; /***************************************************************************** * * Return status of many function * ****************************************************************************/ enum class status { success, unknown_dynamics, block_allocator_bad_capacity, block_allocator_not_enough_memory, head_allocator_bad_capacity, head_allocator_not_enough_memory, simulation_not_enough_model, simulation_not_enough_memory_message_list_allocator, simulation_not_enough_memory_input_port_list_allocator, simulation_not_enough_memory_output_port_list_allocator, data_array_init_capacity_error, data_array_not_enough_memory, data_array_archive_init_capacity_error, data_array_archive_not_enough_memory, array_init_capacity_zero, array_init_capacity_too_big, array_init_not_enough_memory, vector_init_capacity_zero, vector_init_capacity_too_big, vector_init_not_enough_memory, dynamics_unknown_id, dynamics_unknown_port_id, dynamics_not_enough_memory, model_connect_output_port_unknown, model_connect_input_port_unknown, model_connect_already_exist, model_adder_empty_init_message, model_adder_bad_init_message, model_adder_bad_external_message, model_mult_empty_init_message, model_mult_bad_init_message, model_mult_bad_external_message, model_integrator_internal_error, model_integrator_output_error, model_integrator_running_without_x_dot, model_integrator_ta_with_bad_x_dot, model_integrator_bad_external_message, 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_cross_bad_external_message, model_time_func_bad_init_message, model_accumulator_bad_external_message, gui_not_enough_memory, io_file_format_error, io_file_format_model_error, io_file_format_model_number_error, io_file_format_model_unknown, io_file_format_dynamics_unknown, io_file_format_dynamics_limit_reach, io_file_format_dynamics_init_error }; constexpr bool is_success(status s) noexcept { return s == status::success; } constexpr bool is_bad(status s) noexcept { return s != status::success; } template constexpr bool is_status_equal(status s, Args... args) noexcept { return ((s == args) || ... || false); } template constexpr bool match(const T &s, Args... args) noexcept { return ((s == args) || ... || false); } #ifndef NDEBUG #if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__) && \ __GNUC__ >= 2 #define irt_breakpoint() \ do { \ __asm__ __volatile__("int $03"); \ } while (0) #elif (defined(_MSC_VER) || defined(__DMC__)) && defined(_M_IX86) #define irt_breakpoint() \ do { \ __asm int 3h \ } while (0) #elif defined(_MSC_VER) #define irt_breakpoint() \ do { \ __debugbreak(); \ } while (0) #elif defined(__alpha__) && !defined(__osf__) && defined(__GNUC__) && \ __GNUC__ >= 2 #define irt_breakpoint() \ do { \ __asm__ __volatile__("bpt"); \ } while (0) #elif defined(__APPLE__) #define irt_breakpoint() \ do { \ __builtin_trap(); \ } while (0) #else /* !__i386__ && !__alpha__ */ #define irt_breakpoint() \ do { \ raise(SIGTRAP); \ } while (0) #endif /* __i386__ */ #else #define irt_breakpoint() \ do { \ } while (0) #endif #define irt_bad_return(status__) \ do { \ irt_breakpoint(); \ return status__; \ } while (0) #define irt_return_if_bad(expr__) \ do { \ auto status__ = (expr__); \ if (status__ != status::success) { \ irt_breakpoint(); \ return status__; \ } \ } while (0) #define irt_return_if_fail(expr__, status__) \ do { \ if (!(expr__)) { \ irt_breakpoint(); \ return status__; \ } \ } while (0) inline status check_return(status s) noexcept { if (s != status::success) irt_breakpoint(); return s; } /***************************************************************************** * * Definition of Time * * TODO: * - enable template definition of float or [float|double,bool absolute] * representation of time? * ****************************************************************************/ using time = double; template struct time_domain {}; template<> struct time_domain