48#define LOG(level, ...) \
51 std::string _msg = std::format(__VA_ARGS__); \
52 fers_log(level, _msg.c_str()); \
57int main(
const int argc,
char* argv[])
63 if (config_result.error() !=
"Help requested." && config_result.error() !=
"Version requested." &&
64 config_result.error() !=
"No arguments provided.")
67 std::cerr <<
"[ERROR] Argument parsing error: " << config_result.error() << std::endl;
73 const auto& [script_file, log_level, num_threads, validate, log_file, generate_kml] = config_result.value();
76 const char* log_file_ptr = log_file ? log_file->c_str() :
nullptr;
81 std::cerr <<
"[ERROR] Failed to configure logging: " << (err ? err :
"Unknown error") << std::endl;
89 "Running FERS with arguments: script_file={}, log_level={}, num_threads={}, validate={}, log_file={}",
113 std::filesystem::path kml_output_path = script_file;
114 kml_output_path.replace_extension(
".kml");
115 const std::string kml_output_file = kml_output_path.string();
117 LOG(
FERS_LOG_INFO,
"Generating KML file for scenario: {}", kml_output_file);
125 LOG(
FERS_LOG_FATAL,
"Failed to generate KML file: {}", err ? err :
"Unknown error");
137 LOG(
FERS_LOG_ERROR,
"Failed to set number of threads: {}", err ? err :
"Unknown error");
int fers_load_scenario_from_xml_file(fers_context_t *context, const char *xml_filepath, int validate)
Loads a scenario into the context from a FERS XML file.
char * fers_get_last_error_message()
Retrieves the last error message that occurred on the current thread.
int fers_generate_kml(const fers_context_t *context, const char *output_kml_filepath)
Generates a KML file for visualizing the scenario in the context.
fers_log_level_t
Log levels for the FERS library.
void fers_context_destroy(fers_context_t *context)
Destroys a FERS simulation context and releases all associated memory.
fers_context_t * fers_context_create()
Creates a new FERS simulation context.
int fers_run_simulation(fers_context_t *context, fers_progress_callback_t callback, void *user_data)
Runs the simulation defined in the provided context.
void fers_free_string(char *str)
Frees a string that was allocated and returned by the libfers API.
int fers_configure_logging(fers_log_level_t level, const char *log_file_path)
Configures the internal logger.
int fers_set_thread_count(unsigned num_threads)
Sets the number of worker threads for the simulation.
Command-line argument parsing utilities for the application.
int main(const int argc, char *argv[])
std::expected< Config, std::string > parseArguments(const int argc, char *argv[]) noexcept
Parses command-line arguments.
std::string getLevelString(const Level level) noexcept
Converts a log level enum value to its string representation.