@@ -50,6 +50,15 @@ public:
5050
5151 // return true and display warning iff paramName is present
5252 bool warnIfPresent (const std::string paramName, const std::string advice);
53+
54+ private:
55+ // / @brief Wrapper for retrieving an unparsed value with an enhanced error
56+ // / message.
57+ // / @param paramName the name of the parameter to fetch
58+ // / @throws std::out_of_range (with an error message that specifies
59+ // / `paramName`) if the parameter is not present
60+ // / @return the unparsed parameter value (i.e., as a string)
61+ std::string _get_inner (const std::string paramName);
5362};
5463
5564// implementations
@@ -93,30 +102,38 @@ template <>
93102bool ParsedParams::get<bool >(const std::string paramName)
94103{
95104 bool b;
96- std::istringstream (params[ paramName] ) >> std::boolalpha >> b;
105+ std::istringstream (_get_inner ( paramName) ) >> std::boolalpha >> b;
97106 return b;
98107}
99108
100109template <>
101110double ParsedParams::get<double >(const std::string paramName)
102111{
103- return std::stod (params[ paramName] );
112+ return std::stod (_get_inner ( paramName) );
104113}
105114
106115template <>
107116int ParsedParams::get<int >(const std::string paramName)
108117{
109- return std::stoi (params[ paramName] );
118+ return std::stoi (_get_inner ( paramName) );
110119}
111120
112121template <>
113122float ParsedParams::get<float >(const std::string paramName)
114123{
115- return std::stof (params[ paramName] );
124+ return std::stof (_get_inner ( paramName) );
116125}
117126
118127template <>
119128std::string ParsedParams::get<std::string>(const std::string paramName)
120129{
121- return params[paramName];
130+ return _get_inner (paramName);
131+ }
132+
133+ std::string ParsedParams::_get_inner (const std::string paramName)
134+ {
135+ if (params.count (paramName) == 0 ) {
136+ throw std::out_of_range (" missing required input parameter: " + paramName);
137+ }
138+ return params.at (paramName);
122139}
0 commit comments