SpECTRE  v2024.03.19
Options::Parser< OptionList, Group > Class Template Reference

Class that handles parsing an input file. More...

#include <ParseOptions.hpp>

Public Member Functions

 Parser (std::string help_text)
 
void parse (std::string options)
 Parse a string to obtain options and their values. More...
 
void parse (const Option &options)
 Parse an Option to obtain options and their values.
 
void parse_file (const std::string &file_name)
 Parse a file containing options. More...
 
template<typename T , typename Metavariables = NoSuchType>
T::type get () const
 Get the value of the specified option. More...
 
template<typename TagList , typename Metavariables = NoSuchType, typename F >
decltype(auto) apply (F &&func) const
 Call a function with the specified options as arguments. More...
 
template<typename Metavariables = NoSuchType, typename F >
decltype(auto) apply_all (F &&func) const
 Call a function with the typelist of parsed options (i.e., the supplied option list with the chosen branches of any Alternatives inlined) and the option values as arguments. More...
 
template<typename TagsAndSubgroups = tags_and_subgroups_list>
std::string help () const
 Get the help string.
 
void pup (PUP::er &p)
 
template<typename Tag , typename Metavariables >
Tag::type get () const
 
template<typename OverlayOptions >
void overlay (std::string options)
 Overlay the options from a string or file on top of the currently parsed options. More...
 
template<typename OverlayOptions >
void overlay_file (const std::string &file_name)
 Overlay the options from a string or file on top of the currently parsed options. More...
 

Detailed Description

template<typename OptionList, typename Group = NoSuchType>
class Options::Parser< OptionList, Group >

Class that handles parsing an input file.

Options must be given YAML data to parse before output can be extracted. This can be done either from a file (parse_file method), from a string (parse method), or, in the case of recursive parsing, from an Option (parse method). The options can then be extracted using the get method.

Example

struct Bounded {
using type = int;
static constexpr Options::String help = {
"Option with bounds and a suggested value"};
// These are optional
static type suggested_value() { return 3; }
static type lower_bound() { return 2; }
static type upper_bound() { return 10; }
};
std::string help() const
Get the help string.
Definition: ParseOptions.hpp:646
T lower_bound(T... args)
const char *const String
The string used in option structs.
Definition: String.hpp:8
T upper_bound(T... args)
Options::Parser<tmpl::list<Bounded>> opts("Overall help text");
opts.parse("Bounded: 3");
CHECK(opts.get<Bounded>() == 3);
Class that handles parsing an input file.
Definition: ParseOptions.hpp:174
See also
the Option Parsing tutorial
Template Parameters
OptionListthe list of option structs to parse
Groupthe option group with a group hierarchy

Constructor & Destructor Documentation

◆ Parser()

template<typename OptionList , typename Group >
Options::Parser< OptionList, Group >::Parser ( std::string  help_text)
explicit
Parameters
help_textan overall description of the options

Member Function Documentation

◆ apply()

template<typename OptionList , typename Group = NoSuchType>
template<typename TagList , typename Metavariables = NoSuchType, typename F >
decltype(auto) Options::Parser< OptionList, Group >::apply ( F &&  func) const

Call a function with the specified options as arguments.

Template Parameters
TagLista typelist of options to pass

Returns: the result of the function call

◆ apply_all()

template<typename OptionList , typename Group = NoSuchType>
template<typename Metavariables = NoSuchType, typename F >
decltype(auto) Options::Parser< OptionList, Group >::apply_all ( F &&  func) const

Call a function with the typelist of parsed options (i.e., the supplied option list with the chosen branches of any Alternatives inlined) and the option values as arguments.

Returns: the result of the function call. This must have the same type for all valid sets of parsed arguments.

◆ get()

template<typename OptionList , typename Group = NoSuchType>
template<typename T , typename Metavariables = NoSuchType>
T::type Options::Parser< OptionList, Group >::get ( ) const

Get the value of the specified option.

Template Parameters
Tthe option to retrieve

Returns: the value of the option

◆ overlay()

template<typename OptionList , typename Group >
template<typename OverlayOptions >
void Options::Parser< OptionList, Group >::overlay ( std::string  options)

Overlay the options from a string or file on top of the currently parsed options.

Any tag included in the list passed as the template parameter can be overridden by a new parsed value. Newly parsed options replace the previous values. Any tags not appearing in the new input are left unchanged.

◆ overlay_file()

template<typename OptionList , typename Group >
template<typename OverlayOptions >
void Options::Parser< OptionList, Group >::overlay_file ( const std::string file_name)

Overlay the options from a string or file on top of the currently parsed options.

Any tag included in the list passed as the template parameter can be overridden by a new parsed value. Newly parsed options replace the previous values. Any tags not appearing in the new input are left unchanged.

◆ parse()

template<typename OptionList , typename Group >
void Options::Parser< OptionList, Group >::parse ( std::string  options)

Parse a string to obtain options and their values.

Parameters
optionsthe string holding the YAML formatted options

◆ parse_file()

template<typename OptionList , typename Group >
void Options::Parser< OptionList, Group >::parse_file ( const std::string file_name)

Parse a file containing options.

Parameters
file_namethe path to the file to parse

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