BSMPT 3.0.7
BSMPT - Beyond the Standard Model Phase Transitions : A C++ package for the computation of the EWPT in BSM models
Loading...
Searching...
No Matches
BSMPT::parser Class Reference

The parser class provides the argument parser for the CLI and JSON methods. This is case insensitive. More...

#include <BSMPT/utility/parser.h>

Classes

struct  KeyValue
 
struct  Options
 

Public Member Functions

 parser (const bool &enable_column_output)
 
void enable_minimizer_options ()
 enable_minimizer_options Enables the options regarding the minimizer.
 
void add_argument_only_display (const std::string &argument, const std::string &description, const std::string &default_val)
 add_argument Silently adds a new argument for the parser options.
 
void add_argument (const std::string &argument, bool required)
 add_argument Silently adds a new argument for the parser options.
 
void add_argument (const std::string &argument, const std::string &description, bool required)
 add_argument Adds a new argument for the parser options.
 
void add_argument (const std::string &argument, const std::string &description, const std::string &default_val, bool required)
 add_argument Adds a new argument for the parser options.
 
void add_subtext (const std::string &subtext)
 add_subtext add subtext to description column
 
void add_input (const std::vector< std::string > &input)
 add_input Add the vector with each input as it is given in the CLI in the form "--argument=value".
 
void print_help () const
 print_help Prints the header and the arguments with their description.
 
template<typename T = std::string>
get_value (const std::string &argument) const
 get_value Get the value for the required parameter.
 
bool all_required_set () const
 all_required_set Check ifs all required parameter are set.
 
void check_required_parameters () const
 check_required_parameters Calls all_required_set() and throws a parserException if not all required parameters are set.
 
void set_help_header (const std::string &header)
 set_help_header Sets the header which is printed in print_help()
 

Private Member Functions

std::string get_value_as_string (const std::string &argument) const
 get_value Get the value for the required parameter.
 
void add_json_input (const std::string &filename)
 add_json_input Add the input parameters with a json file.
 
void add_input (const std::vector< KeyValue > &input)
 add_input Set the key value pairs.
 
std::string to_lower (const std::string &input) const
 get_key_value Converts the CLI input in the form "--argName=value" into a key value pair.
 
KeyValue get_key_value (const std::string &input)
 

Private Attributes

std::vector< std::pair< std::string, Options > > mOrderedArguments
 
std::unordered_map< std::string, OptionsmRequiredArguments
 
std::unordered_map< std::string, OptionsmOptionalArguments
 
bool extra_column_output = false
 
std::string mHeader
 
bool mHelpAlreadyPrinted {false}
 Helper to avoid multiple prints of the help output.
 

Detailed Description

The parser class provides the argument parser for the CLI and JSON methods. This is case insensitive.

Member Function Documentation

◆ add_argument() [1/3]

void BSMPT::parser::add_argument ( const std::string &  argument,
bool  required 
)

add_argument Silently adds a new argument for the parser options.

Parameters
argumentThe parameter name for the CLI or JSON key. This will be treated case insensitive.
requiredDecide if it is a required parameter or not.

◆ add_argument() [2/3]

void BSMPT::parser::add_argument ( const std::string &  argument,
const std::string &  description,
bool  required 
)

add_argument Adds a new argument for the parser options.

Parameters
argumentThe parameter name for the CLI or JSON key. This will be treated case insensitive.
descriptionThe description for the parameter shown in help.
requiredDecide if it is a required parameter or not.

◆ add_argument() [3/3]

void BSMPT::parser::add_argument ( const std::string &  argument,
const std::string &  description,
const std::string &  default_val,
bool  required 
)

add_argument Adds a new argument for the parser options.

Parameters
argumentThe parameter name for the CLI or JSON key. This will be treated case insensitive.
descriptionThe description for the parameter shown in help.
default_valThe default value for optional parameters.
requiredDecide if it is a required parameter or not.

◆ add_argument_only_display()

void BSMPT::parser::add_argument_only_display ( const std::string &  argument,
const std::string &  description,
const std::string &  default_val 
)

add_argument Silently adds a new argument for the parser options.

Parameters
argumentThe parameter name for the CLI or JSON key. This will be treated case insensitive.
descriptionThe description for the parameter shown in help.
default_valThe default value for optional parameters.

◆ add_input() [1/2]

void BSMPT::parser::add_input ( const std::vector< KeyValue > &  input)
private

add_input Set the key value pairs.

Parameters
inputThe vector containing all key value pairs.

◆ add_input() [2/2]

void BSMPT::parser::add_input ( const std::vector< std::string > &  input)

add_input Add the vector with each input as it is given in the CLI in the form "--argument=value".

Parameters
inputThe vector containing the CLI inputs.
Exceptions
parserExceptionif the argument was not expected by the parser.

◆ add_json_input()

void BSMPT::parser::add_json_input ( const std::string &  filename)
private

add_json_input Add the input parameters with a json file.

Parameters
filenameThe file containing the json.

◆ add_subtext()

void BSMPT::parser::add_subtext ( const std::string &  subtext)

add_subtext add subtext to description column

Parameters
subtextstring to print in description column

◆ all_required_set()

bool BSMPT::parser::all_required_set ( ) const

all_required_set Check ifs all required parameter are set.

Returns
true/false if all required parameters are set.

◆ check_required_parameters()

void BSMPT::parser::check_required_parameters ( ) const

check_required_parameters Calls all_required_set() and throws a parserException if not all required parameters are set.

Exceptions
parserExceptionif not all required parameter are set.

◆ get_value()

template<typename T = std::string>
T BSMPT::parser::get_value ( const std::string &  argument) const
inline

get_value Get the value for the required parameter.

Parameters
argumentThe required CLI name or JSON key.
Returns
The value if the parameter was set.
Exceptions
parserExceptionif the argument was not set or if the value can not be casted from a string to the type.

◆ get_value_as_string()

std::string BSMPT::parser::get_value_as_string ( const std::string &  argument) const
private

get_value Get the value for the required parameter.

Parameters
argumentThe required CLI name or JSON key.
Returns
The value if the parameter was set.
Exceptions
parserExceptionif the argument was not set or if the value can not be casted from a string to the type.

◆ set_help_header()

void BSMPT::parser::set_help_header ( const std::string &  header)

set_help_header Sets the header which is printed in print_help()

Parameters
headerThe header to print.

◆ to_lower()

std::string BSMPT::parser::to_lower ( const std::string &  input) const
private

get_key_value Converts the CLI input in the form "--argName=value" into a key value pair.

Parameters
inputThe CLI option in the form of "--argName=foo".
Returns
Returns the matching KeyValue.

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