26 const std::string& name,
27 std::istringstream& svalue)
34 const std::string& element_name,
35 const std::vector<std::string>& do_not_consume)
37 xmlAttrPtr att = cur->properties;
44 std::string qualified_name{((element_name.size() > 0 && element_name !=
"parameter") ? (element_name +
"::") :
"") +
48 if (std::any_of(do_not_consume.begin(), do_not_consume.end(), [&name](
auto& dnc) {
return name == dnc; }))
56 std::stringstream
error;
57 error <<
"InputSection::readXML name " << name <<
" is not an attribute of " <<
section_name <<
"\n";
72 std::string value_key;
80 assert(cur !=
nullptr);
93 if (possible_sname == lcase_section_name)
97 [&possible_sname](
auto& name_alternate) {
98 std::string lcase_alternate{
lowerCase(name_alternate)};
99 return possible_sname == lcase_alternate;
104 if (!(checkSectionName(section_ename) || checkSectionName(section_method) || checkSectionName(section_type) ||
105 checkSectionName(section_name_actual)))
107 std::stringstream
error;
108 error <<
"Input is invalid \"" << lcase_section_name <<
"\" does not match a defined input node!";
115 xmlNodePtr element = cur->xmlChildrenNode;
116 while (element != NULL)
136 else if (ename ==
"parameter" ||
isParameter(ename))
138 if (ename ==
"parameter")
147 std::stringstream
error;
148 error <<
"InputSection::readXML name " << name <<
" is not a parameter of " <<
section_name <<
"\n";
156 else if (ename !=
"text")
158 std::stringstream
error;
159 error <<
"InputSection::readXML node name " << ename <<
" is not handled by InputSection subtype " <<
section_name 164 element = element->next;
179 for (
auto& [name, value] : init_values)
191 std::function<std::any(xmlNodePtr cur, std::string& value_key)> factory)
213 std::vector<std::string> string_values;
214 for (std::string value; svalue >> value;)
215 string_values.push_back(value);
220 std::vector<Real> real_values;
221 for (
Real value; svalue >> value;)
222 real_values.push_back(static_cast<Real>(value));
229 bool value = sval ==
"yes" || sval ==
"true" || sval ==
"1";
252 std::stringstream
error;
253 error <<
"InputSection::set_from_stream name " << name <<
" in " <<
section_name <<
" does not have a type\n";
263 " node with duplicate name!");
270 std::any_cast<std::vector<T>&>(
values_[name]).push_back(value);
272 values_[name] = std::vector<T>{value};
281 assignValue(name, std::any_cast<std::string>(value));
283 assignValue(name, std::any_cast<std::vector<std::string>>(value));
285 assignValue(name, std::any_cast<std::vector<std::string>>(value));
296 std::stringstream
error;
297 error <<
"InputSection::set_from_value name " << name <<
" in " <<
section_name <<
" does not have a type\n";
301 catch (
const std::bad_cast& exc)
313 std::stringstream
error;
314 error <<
"InputSection::check_valid required variable " << name <<
" in " <<
section_name 315 <<
" has not been assigned\n";
324 for (
auto& [name, value] :
values_)
326 out <<
"\n " << name <<
" = ";
328 out << std::any_cast<std::string>(value);
330 out << std::any_cast<bool>(value);
332 out << std::any_cast<int>(value);
334 out << std::any_cast<Real>(value);
342 const std::string& enum_value,
343 const std::unordered_map<std::string, std::any>& enum_map)
345 std::string enum_value_str(
lowerCase(enum_name +
"-" + enum_value));
348 return enum_map.at(enum_value_str);
350 catch (std::out_of_range& oor_exc)
void handleDelegate(const std::string &ename, const xmlNodePtr element)
factor out delegate handling code for sanity.
void setFromValue(const std::string &name, const std::any &svalue)
Coerce input collected via init into types matching the definition of the input types defined in the ...
helper functions for EinsplineSetBuilder
bool isBool(const std::string &name) const
std::unordered_map< std::string, std::function< std::any(xmlNodePtr cur, std::string &value_key)> > delegate_factories_
std::vector< std::string > section_name_alternates
For historical reasons some sections must recognize several different names. Assign them to this vari...
bool isMultiple(const std::string &name) const
bool isCustom(const std::string &name) const
std::unordered_map< std::string, std::any > default_values
QMCTraits::FullPrecRealType Real
void error(char const *m)
void readAttributes(xmlNodePtr cur, const std::string &element_name, const std::vector< std::string > &do_not_consume)
reads attributes for both the root node and parameter/child nodes that aren't delegated.
bool isEnumString(const std::string &name) const
bool isMultiReal(const std::string &name) const
void init(const std::unordered_map< std::string, std::any > &init_values)
virtual void checkParticularValidity()
Do validation for a particular subtype of InputSection Called by check_valid.
bool isDelegate(const std::string &name) const
typename QMCTypes< Real, OHMMS_DIM >::PosType Position
This a subclass for runtime errors that will occur on all ranks.
void readXML(xmlNodePtr cur)
Read variable values (initialize) from XML input, call checkValid.
std::string lowerCase(const std::string_view s)
++17
void checkValid()
Check validity of inputs.
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
bool isInteger(const std::string &name) const
static std::any lookupAnyEnum(const std::string &enum_name, const std::string &enum_value, const std::unordered_map< std::string, std::any > &enum_map)
Assign any enum helper for InputSection derived class assumes enum lookup table of this form: inline ...
std::unordered_map< std::string, std::any > values_
bool isAttribute(const std::string &name) const
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void setFromStream(const std::string &name, std::istringstream &svalue)
convert xmlNode contents into a std::string
void assignValue(const std::string &name, const T &value)
assign value into unordered map respecting values multiplicity It is a fatal exception to assign to a...
std::unordered_set< std::string > required
bool isString(const std::string &name) const
bool isPosition(const std::string &name) const
bool isMultiString(const std::string &name) const
void registerDelegate(const std::string &tag, DelegateHandler delegate_handler)
register factory function for delegate input
bool isReal(const std::string &name) const
bool isParameter(const std::string &name) const
bool has(const std::string &name) const
std::string section_name
"Name" of the input section, you must define this in the subtype and the ename, name, type, or method must match.
virtual void setFromStreamCustom(const std::string &ename, const std::string &name, std::istringstream &svalue)
Derived class can overrides this to do custom parsing of the element values for Custom elements These...
virtual std::any assignAnyEnum(const std::string &tag) const
Derived class overrides this to get proper assignment of scoped enum values.