QMCPACK
CustomTestInput Class Reference
+ Inheritance diagram for CustomTestInput:
+ Collaboration diagram for CustomTestInput:

Classes

struct  WeirdStuff
 

Public Types

using Repeater = std::vector< std::pair< std::string, std::string > >
 
- Public Types inherited from InputSection
using Real = QMCTraits::FullPrecRealType
 
using Position = typename QMCTypes< Real, OHMMS_DIM >::PosType
 

Public Member Functions

 CustomTestInput ()
 
void setFromStreamCustom (const std::string &ename, const std::string &name, std::istringstream &svalue) override
 Derived class can overrides this to do custom parsing of the element values for Custom elements These can have a name attribute only. More...
 
void report (std::ostream &ostr)
 
- Public Member Functions inherited from InputSection
 InputSection ()=default
 
 InputSection (const InputSection &other)=default
 
InputSectionoperator= (const InputSection &other)=default
 
bool has (const std::string &name) const
 
template<typename T >
get (const std::string &name) const
 
template<typename T >
bool setIfInInput (T &var, const std::string &tag)
 set var if input section has read the tag More...
 
void readXML (xmlNodePtr cur)
 Read variable values (initialize) from XML input, call checkValid. More...
 
void init (const std::unordered_map< std::string, std::any > &init_values)
 

Additional Inherited Members

- Static Public Member Functions inherited from InputSection
template<typename ENUM_T >
static std::string reverseLookupInputEnumMap (ENUM_T enum_val, const std::unordered_map< std::string, std::any > &enum_map)
 Get string represtation of enum class type value from enum_val. More...
 
- Protected Types inherited from InputSection
using DelegateHandler = std::function< std::any(xmlNodePtr cur, std::string &value_name)>
 Function that returns Input class as std::any. More...
 
- Protected Member Functions inherited from InputSection
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. More...
 
void registerDelegate (const std::string &tag, DelegateHandler delegate_handler)
 register factory function for delegate input More...
 
virtual void checkParticularValidity ()
 Do validation for a particular subtype of InputSection Called by check_valid. More...
 
virtual std::any assignAnyEnum (const std::string &tag) const
 Derived class overrides this to get proper assignment of scoped enum values. More...
 
void report () const
 
void report (std::ostream &out) const
 
- Static Protected Member Functions inherited from InputSection
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 static const std::unordered_map<std::string, std::any> lookup_input_enum_value{{"integrator-uniform_grid", Integrator::UNIFORM_GRID}, {"integrator-uniform", Integrator::UNIFORM}, {"integrator-density", Integrator::DENSITY}, {"evaluator-loop", Evaluator::LOOP}, {"evaluator-matrix", Evaluator::MATRIX}};. More...
 
- Protected Attributes inherited from InputSection
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. More...
 
std::vector< std::string > section_name_alternates
 For historical reasons some sections must recognize several different names. Assign them to this variable in your subtype. More...
 
std::unordered_set< std::string > attributes
 
std::unordered_set< std::string > parameters
 
std::unordered_set< std::string > delegates
 
std::unordered_set< std::string > required
 
std::unordered_set< std::string > multiple
 
std::unordered_set< std::string > strings
 
std::unordered_set< std::string > multi_strings
 
std::unordered_set< std::string > multi_reals
 
std::unordered_set< std::string > bools
 
std::unordered_set< std::string > integers
 
std::unordered_set< std::string > reals
 
std::unordered_set< std::string > positions
 
std::unordered_set< std::string > custom
 
std::unordered_set< std::string > enums
 list of enum inputs which allow a finite set of strings to map to enum values The enum class types and values need only be known to IS subtypes More...
 
std::unordered_map< std::string, std::any > default_values
 
std::unordered_map< std::string, std::function< std::any(xmlNodePtr cur, std::string &value_key)> > delegate_factories_
 
std::unordered_map< std::string, std::any > values_
 

Detailed Description

Definition at line 393 of file test_InputSection.cpp.


Class Documentation

◆ qmcplusplus::CustomTestInput::WeirdStuff

struct qmcplusplus::CustomTestInput::WeirdStuff

Definition at line 396 of file test_InputSection.cpp.

+ Collaboration diagram for CustomTestInput::WeirdStuff:
Class Members
string letters
array< int, 3 > numbers

Member Typedef Documentation

◆ Repeater

using Repeater = std::vector<std::pair<std::string, std::string> >

Definition at line 401 of file test_InputSection.cpp.

Constructor & Destructor Documentation

◆ CustomTestInput()

CustomTestInput ( )
inline

Definition at line 402 of file test_InputSection.cpp.

403  {
404  section_name = "Test";
405  attributes = {"name", "samples", "kmax", "full", "custom_attribute", "with_custom::custom_attribute"};
406  parameters = {"label", "count", "width", "with_custom"};
407  strings = {"name", "label", "with_custom"};
408  reals = {"kmax"};
409  integers = {"samples", "count"};
410  bools = {"full"};
411  custom = {"weird_stuff", "repeater", "custom_attribute"};
412  }
std::unordered_set< std::string > strings
Definition: InputSection.h:67
std::unordered_set< std::string > reals
Definition: InputSection.h:72
std::unordered_set< std::string > parameters
Definition: InputSection.h:63
std::unordered_set< std::string > custom
Definition: InputSection.h:74
std::unordered_set< std::string > integers
Definition: InputSection.h:71
std::unordered_set< std::string > attributes
Definition: InputSection.h:62
std::unordered_set< std::string > bools
Definition: InputSection.h:70
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.
Definition: InputSection.h:57

Member Function Documentation

◆ report()

void report ( std::ostream &  ostr)
inline

Definition at line 445 of file test_InputSection.cpp.

Referenced by qmcplusplus::TEST_CASE().

445 { InputSection::report(ostr); }

◆ setFromStreamCustom()

void setFromStreamCustom ( const std::string &  ename,
const std::string &  name,
std::istringstream &  svalue 
)
inlineoverridevirtual

Derived class can overrides this to do custom parsing of the element values for Custom elements These can have a name attribute only.

Parameters
[in]enamename of the element svalue comes from, top level attributes do not have ename.
[in]namename of the attribute
[in]svalueinput stream consisting of the contents of one element. It is expected that your custom stream handler will consume this entirely.

Reimplemented from InputSection.

Definition at line 413 of file test_InputSection.cpp.

References qmcplusplus::has(), CustomTestInput::WeirdStuff::letters, CustomTestInput::WeirdStuff::numbers, and qmcplusplus::modernstrutil::split().

414  {
415  if (ename == "weird_stuff")
416  {
417  WeirdStuff ws;
418  svalue >> ws.letters;
419  svalue >> ws.numbers[0];
420  svalue >> ws.numbers[1];
421  svalue >> ws.numbers[2];
422  values_[name] = ws;
423  }
424  else if (ename == "repeater")
425  {
426  std::string compound;
427  svalue >> compound;
428  auto split_vstrv = split(compound, ":");
429  if (has(name))
430  std::any_cast<Repeater>(&(values_[name]))->emplace_back(split_vstrv[0], split_vstrv[1]);
431  else
432  values_[name] = Repeater{{split_vstrv[0], split_vstrv[1]}};
433  }
434  else if (name == "custom_attribute" || name == "with_custom::custom_attribute")
435  {
436  std::string cus_at;
437  std::getline(svalue, cus_at);
438  values_[name] = cus_at;
439  }
440  else
441  throw std::runtime_error("bad name passed: " + name +
442  " or custom setFromStream not implemented in derived class.");
443  }
std::vector< std::string > split(const std::string &s)
Definition: string_utils.h:57
std::unordered_map< std::string, std::any > values_
Definition: InputSection.h:83
std::vector< std::pair< std::string, std::string > > Repeater
bool has(const std::string &name) const
Definition: InputSection.h:87

The documentation for this class was generated from the following file: