/** * Return the dimensions for the variable with the specified * name. * * @param name Name of variable. * @return Dimensions of variable. */ std::vector<size_t> dims_r(const std::string& name) const { if (contains_r_only(name)) { return (vars_r_.find(name)->second).second; } else if (contains_i(name)) { return (vars_i_.find(name)->second).second; } return empty_vec_ui_; }
void validate_dims(const std::string& stage, const std::string& name, const std::string& base_type, const std::vector<size_t>& dims_declared) const { bool is_int_type = base_type == "int"; if (is_int_type) { if (!contains_i(name)) { std::stringstream msg; msg << (contains_r(name) ? "int variable contained non-int values" : "variable does not exist" ) << "; processing stage=" << stage << "; variable name=" << name << "; base type=" << base_type; throw std::runtime_error(msg.str()); } } else { if (!contains_r(name)) { std::stringstream msg; msg << "variable does not exist" << "; processing stage=" << stage << "; variable name=" << name << "; base type=" << base_type; throw std::runtime_error(msg.str()); } } std::vector<size_t> dims = dims_r(name); if (dims.size() != dims_declared.size()) { std::stringstream msg; msg << "mismatch in number dimensions declared and found in context" << "; processing stage=" << stage << "; variable name=" << name << "; dims declared="; add_vec(msg,dims_declared); msg << "; dims found="; add_vec(msg,dims); throw std::runtime_error(msg.str()); } for (size_t i = 0; i < dims.size(); ++i) { if (dims_declared[i] != dims[i]) { std::stringstream msg; msg << "mismatch in dimension declared and found in context" << "; processing stage=" << stage << "; variable name=" << name << "; position=" << i << "; dims declared="; add_vec(msg,dims_declared); msg << "; dims found="; add_vec(msg,dims); throw std::runtime_error(msg.str()); } } }
/** * Return the double values for the variable with the specified * name or null. * * @param name Name of variable. * @return Values of variable. */ std::vector<double> vals_r(const std::string& name) const { if (contains_r_only(name)) { return (vars_r_.find(name)->second).first; } else if (contains_i(name)) { std::vector<int> vec_int = (vars_i_.find(name)->second).first; std::vector<double> vec_r(vec_int.size()); for (size_t ii = 0; ii < vec_int.size(); ii++) { vec_r[ii] = vec_int[ii]; } return vec_r; } return empty_vec_r_; }
/** * Return <code>true</code> if this json_data contains the specified * variable name. This method returns <code>true</code> * even if the values are all integers. * * @param name Variable name to test. * @return <code>true</code> if the variable exists. */ bool contains_r(const std::string& name) const { return contains_r_only(name) || contains_i(name); }
/** * Return the integer values for the variable with the specified * name. * * @param name Name of variable. * @return Values. */ std::vector<int> vals_i(const std::string& name) const { if (contains_i(name)) { return (vars_i_.find(name)->second).first; } return empty_vec_i_; }