6 std::ostream &
operator<<(std::ostream & s, std::vector<double>
const & v) {
14 std::ostream &
operator<<(std::ostream & s, std::vector<int>
const & v) {
22 std::ostream &
operator<<(std::ostream & s, std::vector<std::string>
const & v) {
30 void ParameterMap::throw_error(std::string errormessage)
const {
throw std::runtime_error(errormessage); }
34 std::cout << std::boolalpha;
35 std::cout <<
"\n#=====================================================\n";
36 std::cout <<
"# Parameter map contains " << parameters.size() <<
" elements:\n";
37 std::cout <<
"#=====================================================\n";
38#if (defined(__INTEL_COMPILER) && __INTEL_COMPILER + __INTEL_COMPILER_UPDATE < 1904)
39 std::cout <<
"Showing values is currently disabled for Intel compilers < 19.0.4.243 as old versions have a "
40 "compiler bug with std::variant\n";
41 std::cout <<
"You can try commening this test out in FML/ParameterMap/ParameterMap.cpp"
42 <<
" if you want to try to use it, but it will likely fail!\n";
43 for (
auto && param : parameters) {
44 std::string name = param.first;
45 std::cout <<
" " << std::setw(30) << std::left << name <<
" : (showing value disabled)\n";
48 for (
auto && param : parameters) {
49 std::string name = param.first;
51 std::cout <<
" " << std::setw(30) << std::left << name <<
" : ";
52 if(value.index() != 0)
53 std::cout << std::setw(15);
54 std::cout << value <<
"\n";
57 std::cout <<
"#=====================================================\n\n";
67 value = std::get<T>(parameters.at(name));
68 }
catch (
const std::out_of_range & e) {
69 std::string errormessage =
70 "[ParameterMap::get] Required parameter [" + name +
"] was not found in the parameter map\n";
71 throw_error(errormessage);
72 }
catch (
const std::bad_variant_access & e) {
73 std::string errormessage =
"[ParameterMap::get] The type of the parameter [" + name +
"] => [" +
74 typeid(value).name() +
"] does not match that in the parameter map\n";
75 throw_error(errormessage);
84 value = std::get<T>(parameters.at(name));
86 value = fiducial_value;
94 template std::string ParameterMap::get<std::string>(std::string)
const;
95 template double ParameterMap::get<double>(std::string)
const;
96 template int ParameterMap::get<int>(std::string)
const;
97 template bool ParameterMap::get<bool>(std::string)
const;
98 template std::vector<double> ParameterMap::get<std::vector<double>>(std::string)
const;
99 template std::vector<int> ParameterMap::get<std::vector<int>>(std::string)
const;
101 template std::string ParameterMap::get<std::string>(std::string, std::string)
const;
102 template double ParameterMap::get<double>(std::string,
double)
const;
103 template int ParameterMap::get<int>(std::string,
int)
const;
104 template bool ParameterMap::get<bool>(std::string,
bool)
const;
105 template std::vector<double> ParameterMap::get<std::vector<double>>(std::string, std::vector<double>)
const;
106 template std::vector<int> ParameterMap::get<std::vector<int>>(std::string, std::vector<int>)
const;
std::map< std::string, ParameterTypes > & get_map()
Get a reference to the underlying map.
void info() const
Show info about the parameter map.
bool contains(std::string name) const
Check if a parameter map contains a value.
T get(std::string name) const
Fetch a value. If it doesn't exist we throw an error.
std::ostream & operator<<(std::ostream &s, std::vector< double > const &v)
std::variant< bool, int, double, std::string, std::vector< int >, std::vector< double >, std::vector< std::string > > ParameterTypes
All the types we can have in the parameter file: string, int, boolean, double and vectors of double a...