Line |
Branch |
Exec |
Source |
1 |
|
|
#pragma once |
2 |
|
|
|
3 |
|
|
#include "Object.h" |
4 |
|
|
#include <deque> |
5 |
|
|
|
6 |
|
|
namespace iguana { |
7 |
|
|
|
8 |
|
|
/// @brief Configuration file manager |
9 |
|
|
class ConfigFileReader : public Object |
10 |
|
|
{ |
11 |
|
|
|
12 |
|
|
public: |
13 |
|
|
|
14 |
|
|
/// @param name the name of this configuration file handler |
15 |
|
|
ConfigFileReader(std::string_view name = "config"); |
16 |
|
|
|
17 |
|
|
/// Get the config files' _fixed_ installation prefix |
18 |
|
|
/// @warning if the Iguana installation is _relocated_, this directory will **not** be correct, |
19 |
|
|
/// since it is compiled in the shared library; as a fallback, you may use the environment variable |
20 |
|
|
/// `$IGUANA_CONFIG_PATH`. |
21 |
|
|
/// @return the absolute path to the installed configuration file directory |
22 |
|
|
static std::string GetConfigInstallationPrefix(); |
23 |
|
|
|
24 |
|
|
/// Add a directory to the configuration files' search paths. |
25 |
|
|
/// @param dir the directory, which may be relative or absolute |
26 |
|
|
void AddDirectory(std::string const& dir); |
27 |
|
|
|
28 |
|
|
/// Add a configuration file to be parsed |
29 |
|
|
/// @param name the name of the file |
30 |
|
|
void AddFile(std::string const& name); |
31 |
|
|
|
32 |
|
|
/// Print the list of directories (search path) |
33 |
|
|
/// @param level the log level |
34 |
|
|
void PrintDirectories(Logger::Level const level = Logger::info); |
35 |
|
|
|
36 |
|
|
/// Find a configuration file by name. You may either give just a file name, or specify the full path and filename. |
37 |
|
|
/// The following locations are searched, in order: |
38 |
|
|
/// - current working directory `./` |
39 |
|
|
/// - directories included by `ConfigFileReader::AddDirectory`, starting from the most recently added directory |
40 |
|
|
/// - the common installation prefix |
41 |
|
|
/// @param name the configuration file name (with or without a directory) |
42 |
|
|
/// @return the found configuration file (with the directory) |
43 |
|
|
std::string FindFile(std::string const& name); |
44 |
|
|
|
45 |
|
|
/// Convert a full algorithm name to its corresponding default config file name |
46 |
|
|
/// @param algo_name the algorithm name |
47 |
|
|
/// @param ext the file extension |
48 |
|
|
/// @return the config file name |
49 |
|
|
static std::string ConvertAlgoNameToConfigName(std::string_view algo_name, std::string_view ext = "yaml"); |
50 |
|
|
|
51 |
|
|
protected: |
52 |
|
|
|
53 |
|
|
/// Stack of directories to search for a file |
54 |
|
|
std::deque<std::string> m_directories; |
55 |
|
|
|
56 |
|
|
/// Stack of file names to parse |
57 |
|
|
std::deque<std::string> m_files; |
58 |
|
|
}; |
59 |
|
|
} |
60 |
|
|
|