0.2.0
Loading...
Searching...
No Matches
ConfigManager.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <vector>
17#include <string>
18#include <deque>
19#include <memory>
20
21#include <boost/program_options/options_description.hpp>
22#include <boost/program_options/variables_map.hpp>
23
24#include <fmt/core.h>
25
26namespace NAV::ConfigManager
27{
29extern boost::program_options::variables_map vm;
30
33
36
39[[nodiscard]] const boost::program_options::options_description& GetProgramOptions();
40
45std::vector<std::string> FetchConfigs(const int argc, const char* argv[]); // NOLINT
46
50void CheckOptions(const int argc, const char* argv[]); // NOLINT
51
57template<typename T>
58const T& Get(const std::string& key, const T& defaultValue)
59{
60 if (vm.count(key))
61 {
62 return vm[key].as<T>();
63 }
64
65 return defaultValue;
66}
67
72template<typename T>
73const T& Get(const std::string& key)
74{
75 if (vm.count(key))
76 {
77 return vm[key].as<T>();
78 }
79
80 throw std::runtime_error(fmt::format("The key '{}' does not exist.", key));
81}
82
84bool HasKey(const std::string& key);
85
87std::vector<std::string> GetKeys();
88
91
94
95} // namespace NAV::ConfigManager
void LoadGlobalSettings()
Loads the global settings.
void initialize()
Initializes the config manager. Call this function before using other functions.
boost::program_options::variables_map vm
Map which stores all options.
const T & Get(const std::string &key, const T &defaultValue)
Retrieves the value of a corresponding key from the configuration, if one exists.
Definition ConfigManager.hpp:58
void CheckOptions(const int argc, const char *argv[])
Writes all command line options into the log.
bool HasKey(const std::string &key)
Checks if a corresponding key exists in the configuration.
std::vector< std::string > GetKeys()
Returns all keys in the configuration, as a vector.
std::vector< std::string > FetchConfigs(const int argc, const char *argv[])
Fetches the configs from the command line parameters.
const boost::program_options::options_description & GetProgramOptions()
Get the Program Options object.
void deinitialize()
Deinitializes the config manager. Call this if you want to Fetch config again.
void SaveGlobalSettings()
Saves the global settings.