49#define LOG(level, ...) \
52 std::string _msg = std::format(__VA_ARGS__); \
53 fers_log(level, _msg.c_str()); \
58int main(
const int argc,
char* argv[])
64 if (config_result.error() !=
"Help requested." && config_result.error() !=
"Version requested." &&
65 config_result.error() !=
"No arguments provided.")
68 std::cerr <<
"[ERROR] Argument parsing error: " << config_result.error() <<
'\n';
74 const auto& [script_file, log_level, num_threads, validate, log_file, generate_kml, kml_file, output_dir] =
75 config_result.value();
78 const char* log_file_ptr = log_file ? log_file->c_str() :
nullptr;
83 std::cerr <<
"[ERROR] Failed to configure logging: " << ((err !=
nullptr) ? err :
"Unknown error") <<
'\n';
91 "Running FERS with arguments: script_file={}, log_level={}, num_threads={}, validate={}, log_file={}",
98 if (context ==
nullptr)
108 LOG(
FERS_LOG_FATAL,
"Failed to set output directory: {}", err ? err :
"Unknown error");
128 const std::string kml_output_file = kml_output_path.string();
130 LOG(
FERS_LOG_INFO,
"Generating KML file for scenario: {}", kml_output_file);
138 LOG(
FERS_LOG_FATAL,
"Failed to generate KML file: {}", err ? err :
"Unknown error");
150 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.
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.
Command-line argument parsing utilities for the application.
int main(const int argc, char *argv[])
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.