32#include "boost/optional/optional_io.hpp"
39#ifndef __SDDSPARSER_H__
40#define __SDDSPARSER_H__
49 std::string retval(for_string);
65 void setInput(
const std::string &input);
85 void getValue(
int t, std::string column_name,
T& nval) {
94 if(t <= 0 ||
static_cast<size_t>(t) > num_rows)
95 row_idx = num_rows - 1;
97 row_idx =
static_cast<size_t>(t) - 1;
100 nval = getBoostVariantValue<T>(val, (
int)
getColumnType(column_name));
113 template <
typename T>
115 std::string col_name,
T& nval) {
118 double value_before_ref = 0;
119 double value_after_ref = 0;
128 size_t num_rows = ref_values.size();
130 for(this_row = 0; this_row < num_rows; this_row++) {
131 value_after_ref = boost::get<double>(ref_values[this_row]);
133 if(ref_val < value_after_ref) {
136 if(this_row > 0) prev_row = this_row - 1;
138 value_before = getBoostVariantValue<T>(col_values[prev_row],
datatype);
139 value_after = getBoostVariantValue<T>(col_values[this_row],
datatype);
141 value_before_ref = boost::get<double>(ref_values[prev_row]);
142 value_after_ref = boost::get<double>(ref_values[this_row]);
148 if(this_row == num_rows)
150 "all values < specified reference value");
153 if(ref_val - value_before_ref < 1
e-8)
156 nval = value_before + (ref_val - value_before_ref)
157 * (value_after - value_before)
158 / (value_after_ref - value_before_ref);
160 if (!std::isfinite(nval))
162 "Interpolated value either NaN or Inf.");
173 template <
typename T>
185 template <
typename T>
192 nval = boost::get<T>(value);
195 "unknown parameter name: '" + parameter_name +
"'!");
202 template <
typename T>
208 value = boost::get<float>(val);
211 value = boost::get<double>(val);
214 value = boost::get<short>(val);
217 value = boost::get<long>(val);
221 "can't convert value to type T");
226 "can't convert value");
constexpr double e
The value of.
std::vector< variant_t > columnData_t
boost::variant< float, double, short, long, char, std::string > variant_t
std::map< std::string, int > columnNameToID_m
mapping from column name to ID in columns_m
void getParameterValue(std::string parameter_name, T &nval)
ast::columnData_t getColumnData(const std::string &columnName)
ast::datatype getColumnType(const std::string &col_name)
std::string sddsFileName_m
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 getInterpolatedValue(std::string ref_name, double ref_val, std::string col_name, T &nval)
static void fixCaseSensitivity(std::string &for_string)
void setInput(const std::string &input)
void getValue(int t, std::string column_name, T &nval)
static std::string fixCaseSensitivity(const std::string &for_string)
void getInterpolatedValue(double spos, std::string col_name, T &nval)
int getColumnIndex(std::string col_name) const
std::map< std::string, int > paramNameToID_m
mapping from parameter name to offset in params_m
parameterList sddsParameters_m