19 #include "boost/optional/optional_io.hpp"
26 #ifndef __SDDSPARSER_H__
27 #define __SDDSPARSER_H__
36 std::string retval(for_string);
52 void setInput(
const std::string &input);
72 void getValue(
int t, std::string column_name,
T& nval) {
81 if(t <= 0 || static_cast<size_t>(t) > num_rows)
82 row_idx = num_rows - 1;
84 row_idx =
static_cast<size_t>(t) - 1;
87 nval = getBoostVariantValue<T>(val, (int)
getColumnType(column_name));
100 template <
typename T>
102 std::string col_name,
T& nval) {
105 double value_before_ref = 0;
106 double value_after_ref = 0;
115 size_t num_rows = ref_values.size();
117 for(this_row = 0; this_row < num_rows; this_row++) {
118 value_after_ref = boost::get<double>(ref_values[this_row]);
120 if(ref_val < value_after_ref) {
123 if(this_row > 0) prev_row = this_row - 1;
125 value_before = getBoostVariantValue<T>(col_values[prev_row],
datatype);
126 value_after = getBoostVariantValue<T>(col_values[this_row],
datatype);
128 value_before_ref = boost::get<double>(ref_values[prev_row]);
129 value_after_ref = boost::get<double>(ref_values[this_row]);
135 if(this_row == num_rows)
137 "all values < specified reference value");
140 if(ref_val - value_before_ref < 1
e-8)
143 nval = value_before + (ref_val - value_before_ref)
144 * (value_after - value_before)
145 / (value_after_ref - value_before_ref);
147 if (!std::isfinite(nval))
149 "Interpolated value either NaN or Inf.");
160 template <
typename T>
172 template <
typename T>
179 nval = boost::get<T>(value);
182 "unknown parameter name: '" + parameter_name +
"'!");
189 template <
typename T>
195 value = boost::get<float>(val);
198 value = boost::get<double>(val);
201 value = boost::get<short>(val);
204 value = boost::get<long>(val);
208 "can't convert value to type T");
213 "can't convert value");
constexpr double e
The value of .
void getParameterValue(std::string parameter_name, T &nval)
ast::columnData_t getColumnData(const std::string &columnName)
int getColumnIndex(std::string col_name) const
static void fixCaseSensitivity(std::string &for_string)
std::map< std::string, int > columnNameToID_m
mapping from column name to ID in columns_m
void setInput(const std::string &input)
void getInterpolatedValue(double spos, std::string col_name, T &nval)
boost::variant< float, double, short, long, char, std::string > variant_t
std::vector< variant_t > columnData_t
parameterList sddsParameters_m
std::map< std::string, int > paramNameToID_m
mapping from parameter name to offset in params_m
void getInterpolatedValue(std::string ref_name, double ref_val, std::string col_name, T &nval)
T getBoostVariantValue(const ast::variant_t &val, int datatype) const
Convert value from boost variant (only numeric types) to a value of type T.
void getValue(int t, std::string column_name, T &nval)
ast::datatype getColumnType(const std::string &col_name)
static std::string fixCaseSensitivity(const std::string &for_string)
std::string sddsFileName_m