Pogosim
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1#ifndef UTILS_H
2#define UTILS_H
3
4#include <spdlog/spdlog.h>
5#include <spdlog/sinks/stdout_color_sinks.h> // For colored console output
6#include <spdlog/fmt/ostr.h> // Enables << operator for logging
7
8#include <box2d/box2d.h>
9
10#include <random>
11#include <algorithm>
12
13#include "configuration.h"
14
15#define _USE_MATH_DEFINES
16
17
18#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
19 #include <span>
20 template<class T> using span_t = std::span<const T>;
21#else
22 #include <vector>
23 template<class T> using span_t = const std::vector<T>&; // read-only view
24#endif
25
26
28extern std::shared_ptr<spdlog::logger> glogger;
30extern std::shared_ptr<spdlog::logger> robotlogger;
31
33extern std::random_device rd;
35extern std::mt19937 rnd_gen;
36
52template<typename T>
53[[nodiscard]] constexpr bool contains(const std::vector<T>& vec,
54 const T& value) {
55 return std::find(vec.begin(), vec.end(), value) != vec.end();
56}
57
58
73[[nodiscard]] constexpr bool all_true(const std::vector<bool>& flags) {
74 return std::ranges::all_of(flags, [](bool v) { return v; });
75}
76
77
85void init_logger(Configuration& config);
86
96void loggers_add_file_sink(std::string const& filename);
97
110bool string_to_bool( std::string const& str);
111
120std::string to_lowercase(std::string const& str);
121
131void ensure_directories_exist(const std::string& filename);
132
144void delete_files_with_extension(const std::string& path, const std::string& extension, bool recursive = false);
145
159std::string resolve_path(const std::string& inputPath);
160
161
162#endif // UTILS_H
163
164// MODELINE "{{{1
165// vim:expandtab:softtabstop=4:shiftwidth=4:fileencoding=utf-8
166// vim:foldmethod=marker
Class for managing hierarchical configuration parameters.
Definition configuration.h:64
std::shared_ptr< spdlog::logger > robotlogger
Global logger for robot-specific logging.
Definition utils.cpp:12
std::random_device rd
Random device used for seeding the random generator.
Definition utils.cpp:15
std::shared_ptr< spdlog::logger > glogger
Global logger for general logging.
Definition utils.cpp:11
std::string to_lowercase(std::string const &str)
Converts a string to lowercase.
Definition utils.cpp:72
constexpr bool all_true(const std::vector< bool > &flags)
Check whether every element in a std::vector<bool> is true.
Definition utils.h:73
bool string_to_bool(std::string const &str)
Converts a string to a boolean value.
Definition utils.cpp:57
std::string resolve_path(const std::string &inputPath)
Resolves an input file path to an absolute path.
Definition utils.cpp:127
void ensure_directories_exist(const std::string &filename)
Ensures that the directory for a given file exists.
Definition utils.cpp:79
const std::vector< T > & span_t
Definition utils.h:23
std::mt19937 rnd_gen
Random number generator seeded with rd.
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.
Definition utils.cpp:93
constexpr bool contains(const std::vector< T > &vec, const T &value)
Check whether a vector contains a given value.
Definition utils.h:53
void init_logger(Configuration &config)
Initializes the global loggers.
Definition utils.cpp:19
void loggers_add_file_sink(std::string const &filename)
Adds a file sink to the global loggers.
Definition utils.cpp:43