58{
59
61 if (!config_result)
62 {
63 if (config_result.error() != "Help requested." && config_result.error() != "Version requested." &&
64 config_result.error() != "No arguments provided.")
65 {
66
67 std::cerr << "[ERROR] Argument parsing error: " << config_result.error() << std::endl;
68 return 1;
69 }
70 return 0;
71 }
72
73 const auto& [script_file, log_level, num_threads, validate, log_file, generate_kml] = config_result.value();
74
75
76 const char* log_file_ptr = log_file ? log_file->c_str() : nullptr;
78 {
79
81 std::cerr << "[ERROR] Failed to configure logging: " << (err ? err : "Unknown error") << std::endl;
83 return 1;
84 }
85
87
89 "Running FERS with arguments: script_file={}, log_level={}, num_threads={}, validate={}, log_file={}",
91
92
94 if (!context)
95 {
97 return 1;
98 }
99
100
103 {
108 return 1;
109 }
110
111 if (generate_kml)
112 {
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();
116
117 LOG(
FERS_LOG_INFO,
"Generating KML file for scenario: {}", kml_output_file);
119 {
121 }
122 else
123 {
125 LOG(
FERS_LOG_FATAL,
"Failed to generate KML file: {}", err ? err :
"Unknown error");
127 }
128
130 return 0;
131 }
132
133
135 {
137 LOG(
FERS_LOG_ERROR,
"Failed to set number of threads: {}", err ? err :
"Unknown error");
139 }
140
141
144 {
149 return 1;
150 }
152
154
155 return 0;
156}
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.
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.
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.