#include <iostream>#include <string>#include <filesystem>#include <algorithm>#include "utils.h"#include "spdlog/sinks/stdout_color_sinks.h"#include "spdlog/sinks/basic_file_sink.h"Functions | |
| std::mt19937 | rnd_gen (rd()) |
| void | init_logger (Configuration &config) |
| Initializes the global loggers. | |
| void | loggers_add_file_sink (std::string const &filename) |
| Adds a file sink to the global loggers. | |
| bool | string_to_bool (std::string const &str) |
| Converts a string to a boolean value. | |
| std::string | to_lowercase (std::string const &str) |
| Converts a string to lowercase. | |
| void | ensure_directories_exist (const std::string &filename) |
| Ensures that the directory for a given file exists. | |
| void | delete_files_with_extension (const std::string &path, const std::string &extension, bool recursive) |
| Deletes files with a specified extension in a given directory. | |
| std::string | resolve_path (const std::string &inputPath) |
| Resolves an input file path to an absolute path. | |
Variables | |
| std::shared_ptr< spdlog::logger > | glogger |
| Global logger for general logging. | |
| std::shared_ptr< spdlog::logger > | robotlogger |
| Global logger for robot-specific logging. | |
| std::random_device | rd |
| Random device used for seeding the random generator. | |
| void delete_files_with_extension | ( | const std::string & | path, |
| const std::string & | extension, | ||
| bool | recursive = false ) |
Deletes files with a specified extension in a given directory.
This function deletes all regular files with the specified extension within the given directory. If the recursive flag is true, it searches subdirectories as well; otherwise, it only searches the specified directory. Deletion operations and any errors encountered are logged.
| path | The directory path where files will be deleted. |
| extension | The file extension (including the dot) to match for deletion. |
| recursive | If true, deletion is performed recursively in subdirectories. |
| void ensure_directories_exist | ( | const std::string & | filename | ) |
Ensures that the directory for a given file exists.
This function checks the parent directory of the provided filename. If the directory does not exist, it attempts to create it. Successful creation is logged using glogger. If an error occurs during directory creation, the error is logged.
| filename | The file path for which the directories should be ensured. |
| void init_logger | ( | Configuration & | config | ) |
Initializes the global loggers.
This function creates a console sink with color support and attaches it to two loggers: one for global logging (glogger) and one for robot-specific logging (robotlogger). The log level for both loggers is set to info and a specific log message format is defined.
| void loggers_add_file_sink | ( | std::string const & | filename | ) |
Adds a file sink to the global loggers.
This function ensures that the directory for the given filename exists, then creates a file sink that logs messages with debug level and a specified format. The file sink is then added to both the global logger (glogger) and the robot logger (robotlogger).
| filename | The file path where the log file will be created. |
| std::string resolve_path | ( | const std::string & | inputPath | ) |
Resolves an input file path to an absolute path.
This function attempts to resolve the provided input path by first checking if the file exists in the current directory. If not found and if the DATA_DIR macro is defined, it checks relative to DATA_DIR. If the file is found in either location, the absolute path is returned; otherwise, an exception is thrown.
| inputPath | The relative or absolute path of the file. |
| std::runtime_error | If the file cannot be found in the current directory or DATA_DIR. |
| std::mt19937 rnd_gen | ( | rd() | ) |
| bool string_to_bool | ( | std::string const & | str | ) |
Converts a string to a boolean value.
The conversion is case-insensitive. The function returns true if the input string is "true" or "1", and false if it is "false" or "0". For any other input, an std::invalid_argument exception is thrown.
| str | The input string to convert. |
| std::invalid_argument | If the input string is not a valid boolean representation. |
| std::string to_lowercase | ( | std::string const & | str | ) |
Converts a string to lowercase.
This function creates and returns a lowercase copy of the input string.
| str | The string to convert. |
| std::shared_ptr<spdlog::logger> glogger |
Global logger for general logging.
| std::random_device rd |
Random device used for seeding the random generator.
| std::shared_ptr<spdlog::logger> robotlogger |
Global logger for robot-specific logging.