MADNESS 0.10.1
madness::commandlineparser Struct Reference

very simple command line parser More...

#include <commandlineparser.h>

Public Member Functions

 commandlineparser ()
 commandlineparser (int argc, char **argv)
std::string check_for_input_file (std::string line)
 special option: the input file has no hyphens in front and is just a value
bool key_exists (std::string key) const
void print_map () const
void set_defaults ()
 set default values from the command line
void set_keyval (const std::string key, const std::string value)
void set_keyval_keep_case (const std::string key, const std::string value)
std::string value (const std::string key) const
std::string value_raw (const std::string key) const

Static Public Member Functions

static std::string base_name (std::string const &path, std::string const &delims="/")
static std::string remove_blanks (const std::string arg)
 remove all blanks
static std::string remove_extension (std::string const &filename)
static std::string remove_first_equal (const std::string arg)
static std::string remove_front_hyphens (const std::string arg)
static std::vector< std::string > split (std::string s, const std::string delimiter)
 split a string s into a vector of strings, using delimiter
static std::string tolower (std::string s)
 make lower case
static std::string trim_blanks (const std::string arg)
 remove blanks at the beginning and the end only

Public Attributes

std::map< std::string, std::string > keyval
std::map< std::string, std::string > keyval_raw

Detailed Description

very simple command line parser

parser reads out key/value pairs from the command line of the form --key=val or --key. By default values are case-folded so that chemistry-style enum knobs (e.g. --xc=HF, --localize=BOYS) match the lowercased allowed_values of QCCalculationParametersBase-derived classes.

Two accessors are exposed for retrieving values:

  • value(key) — case-folded value (back-compat). Use for enum-like chemistry parameters.
  • value_raw(key) — original-case value. Use for paths and free-form identifiers (archive filenames, JSON paths, …).

The bare-positional input-file form (e.g. madness_app /Some/Path/in.in) is also case-preserving — both value("input") and value_raw("input") return the path with original case.

Constructor & Destructor Documentation

◆ commandlineparser() [1/2]

madness::commandlineparser::commandlineparser ( )
inline

References set_defaults().

◆ commandlineparser() [2/2]

madness::commandlineparser::commandlineparser ( int argc,
char ** argv )
inline

Member Function Documentation

◆ base_name()

std::string madness::commandlineparser::base_name ( std::string const & path,
std::string const & delims = "/" )
inlinestatic

◆ check_for_input_file()

std::string madness::commandlineparser::check_for_input_file ( std::string line)
inline

special option: the input file has no hyphens in front and is just a value

References split().

Referenced by commandlineparser().

◆ key_exists()

◆ print_map()

void madness::commandlineparser::print_map ( ) const
inline

References keyval.

Referenced by main(), and main().

◆ remove_blanks()

std::string madness::commandlineparser::remove_blanks ( const std::string arg)
inlinestatic

remove all blanks

References madness::arg().

◆ remove_extension()

std::string madness::commandlineparser::remove_extension ( std::string const & filename)
inlinestatic

References madness::filename, and p().

◆ remove_first_equal()

std::string madness::commandlineparser::remove_first_equal ( const std::string arg)
inlinestatic

References madness::arg().

Referenced by commandlineparser().

◆ remove_front_hyphens()

std::string madness::commandlineparser::remove_front_hyphens ( const std::string arg)
inlinestatic

References madness::arg().

Referenced by commandlineparser().

◆ set_defaults()

void madness::commandlineparser::set_defaults ( )
inline

set default values from the command line

References keyval.

Referenced by commandlineparser(), and commandlineparser().

◆ set_keyval()

◆ set_keyval_keep_case()

void madness::commandlineparser::set_keyval_keep_case ( const std::string key,
const std::string value )
inline

◆ split()

std::vector< std::string > madness::commandlineparser::split ( std::string s,
const std::string delimiter )
inlinestatic

split a string s into a vector of strings, using delimiter

Parameters
[in]sthe string (pass by value!)

Referenced by check_for_input_file(), main(), and madness::QCParameter::print_line().

◆ tolower()

◆ trim_blanks()

std::string madness::commandlineparser::trim_blanks ( const std::string arg)
inlinestatic

remove blanks at the beginning and the end only

References madness::arg().

Referenced by set_keyval(), and set_keyval_keep_case().

◆ value()

◆ value_raw()

std::string madness::commandlineparser::value_raw ( const std::string key) const
inline

Original-case value lookup — use for paths and free-form identifiers (archive filenames, JSON paths, etc.). For enum-like chemistry knobs matched against allowed_values, prefer value(key) instead.

References key_exists(), keyval, keyval_raw, MADNESS_CHECK_THROW, and tolower().

Referenced by main(), and madness::Molecule::GeometryParameters::set_global_convenience_options().

Member Data Documentation

◆ keyval

std::map<std::string, std::string> madness::commandlineparser::keyval

◆ keyval_raw

std::map<std::string, std::string> madness::commandlineparser::keyval_raw

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