MoCSI API Reference
Loading...
Searching...
No Matches
InputManager.h
Go to the documentation of this file.
1#ifndef INPUT_MANAGER_H
2#define INPUT_MANAGER_H
3
4#include <any>
5#include <cmath>
6#include <iostream>
7#include <string>
8#include <unordered_map>
9#include <vector>
10
26{
27 public:
29 InputManager(const std::string& default_ini_file_path);
30 void loadUserInput(const std::string& user_ini_file_path);
31 void parseCommandLineArguments(int argc, const char* argv[],
32 const std::string& user_ini_path);
33
34 int getIntParameters(const std::string& key) const;
35 double getDoubleParameters(const std::string& key) const;
36 bool getBoolParameters(const std::string& key) const;
37 std::string getStringParameters(const std::string& key) const;
38 std::vector<std::string> getStringVectorParameters(const std::string& key) const;
39 std::vector<double> getDoubleVectorParameters(const std::string& key) const;
40
41 void printInput() const;
42 void addBuildInfo();
43 void forceValueOverwrite(const std::string& key, const std::string& value);
44 std::unordered_map<std::string, std::any> data() { return m_parameters; };
45
46 private:
47 std::unordered_map<std::string, std::any> m_parameters;
48 std::unordered_map<std::string, int> m_intParameters;
49 std::unordered_map<std::string, double> m_doubleParameters;
50 std::unordered_map<std::string, bool> m_boolParameters;
51 std::unordered_map<std::string, std::vector<std::string>> m_stringVectorParameters;
52 std::unordered_map<std::string, std::vector<double>> m_doubleVectorParameters;
53
54 double m_invalid_double = NAN;
55 int m_invalid_int = -999999;
56
57 void mergeIni(const std::string& filePath);
58 void updateKeys(const std::unordered_map<std::string, std::any>& new_input);
59 void parseValuesToType();
60
61 bool checkKeysAnyMap(const std::string& key) const;
62 bool checkKeysIntMap(const std::string& key) const;
63 bool checkKeysDoubleMap(const std::string& key) const;
64 bool checkKeysStringVectorMap(const std::string& key) const;
65 bool checkKeysDoubleVectorMap(const std::string& key) const;
66
67 void processCommandLineInput(const std::string& key, const std::string& value);
68 static std::vector<std::string> stringToVector(const std::string& string_to_parse);
69 static std::vector<double> doubleArrayStringToVector(const std::string& string_to_parse);
70 static bool isNone(const std::string& string_to_check);
71};
72
73#endif
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
This class that manages parameter input through the default ini and user supplied ini files + CLI....
Definition InputManager.h:26
int getIntParameters(const std::string &key) const
Getter function to access the m_intParameters map and returns an int.
Definition InputManager.cpp:461
void addBuildInfo()
Adds build metadata to the simulation configuration.
Definition InputManager.cpp:146
std::vector< double > getDoubleVectorParameters(const std::string &key) const
Definition InputManager.cpp:513
void printInput() const
Function that prints the current content of m_parameters to the console.
Definition InputManager.cpp:158
InputManager()
Constructor for the InputManager class. Used in case the file can only be passed at runtime.
Definition InputManager.cpp:16
double getDoubleParameters(const std::string &key) const
Getter function to access the m_DoubleParameters map and returns a double.
Definition InputManager.cpp:477
std::unordered_map< std::string, std::any > data()
Definition InputManager.h:44
void forceValueOverwrite(const std::string &key, const std::string &value)
Definition InputManager.cpp:60
void parseCommandLineArguments(int argc, const char *argv[], const std::string &user_ini_path)
Definition InputManager.cpp:78
bool getBoolParameters(const std::string &key) const
Getter function to access the m_parameters map and returns a bool. Throws a BadInput error,...
Definition InputManager.cpp:531
std::vector< std::string > getStringVectorParameters(const std::string &key) const
Definition InputManager.cpp:503
void loadUserInput(const std::string &user_ini_file_path)
Public function to load and merge user supplied ini files with the already stored data.
Definition InputManager.cpp:42
std::string getStringParameters(const std::string &key) const
Getter function to access the m_parameters map and returns a string. Throws a BadInput error,...
Definition InputManager.cpp:493