59{
60
62 if (!config_result)
63 {
64 if (config_result.error() != "Help requested." && config_result.error() != "Version requested." &&
65 config_result.error() != "No arguments provided.")
66 {
67
68 std::cerr << "[ERROR] Argument parsing error: " << config_result.error() << '\n';
69 return 1;
70 }
71 return 0;
72 }
73
74 const auto& [script_file, log_level, num_threads, validate, log_file, generate_kml, kml_file, output_dir] =
75 config_result.value();
76
77
78 const char* log_file_ptr = log_file ? log_file->c_str() : nullptr;
80 {
81
83 std::cerr << "[ERROR] Failed to configure logging: " << ((err != nullptr) ? err : "Unknown error") << '\n';
85 return 1;
86 }
87
89
91 "Running FERS with arguments: script_file={}, log_level={}, num_threads={}, validate={}, log_file={}",
93
95
96
98 if (context == nullptr)
99 {
101 return 1;
102 }
103
104
106 {
108 LOG(
FERS_LOG_FATAL,
"Failed to set output directory: {}", err ? err :
"Unknown error");
111 return 1;
112 }
113
114
117 {
122 return 1;
123 }
124
125 if (generate_kml)
126 {
128 const std::string kml_output_file = kml_output_path.string();
129
130 LOG(
FERS_LOG_INFO,
"Generating KML file for scenario: {}", kml_output_file);
132 {
134 }
135 else
136 {
138 LOG(
FERS_LOG_FATAL,
"Failed to generate KML file: {}", err ? err :
"Unknown error");
140 }
141
143 return 0;
144 }
145
146
148 {
150 LOG(
FERS_LOG_ERROR,
"Failed to set number of threads: {}", err ? err :
"Unknown error");
152 }
153
154
157 {
162 return 1;
163 }
165
167
168 return 0;
169}
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.
int fers_set_output_directory(fers_context_t *context, const char *out_dir)
Sets the output directory for simulation results.
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::filesystem::path resolveKmlOutputPath(const std::string &script_file, const std::filesystem::path &final_output_dir, const std::optional< std::string > &kml_file) noexcept
std::filesystem::path resolveOutputDir(const std::string &script_file, const std::optional< std::string > &output_dir) noexcept
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.