utils/include/arguments

Defines

FEASST_CHECK_ALL_USED(args)

Check that all arguments are used.

namespace feasst

Typedefs

typedef std::map<std::string, std::string> argtype

Use a map of string pairs as a dictionary for arguments.

typedef std::vector<std::pair<std::string, argtype>> arglist

Functions

template<typename T>
bool used(const std::string &key, const T &args)

Return true if key is used in args (templated for arglist or argtype).

Classes should take argtype as input for (optional) arguments that may or may not have default values:

MakeTestArgs({{“arg”, “value”}});

All arguments are pairs of strings that may be converted to int, double or bool via utils/include/io.h.

Constructurs should take argtype as object and pointer. The point implementation removes arguments as they are processed, while the argtype constructor passes the arguments to the other constructor, and then checks that all argtype were used. Thus, the pointer implementation is used for base classes and containers, while the object implementation is for the user.

Please see utils/test/arguments.cpp TestArgs and TEST(Arguments, args) for a working example of how to implement arguments in a class.

std::string str(const std::string &key, const argtype &args)

Read an argument, but do not remove it. WARNING: This should typically only be used for error checking.

std::string str(const std::string &key, argtype *args)

Read an argument and remove it.

std::string str(const arglist &args)

Return a human-readable string representing argtype (use io template)

Return a human-readable string representing arglist

std::string str(const std::string &key, argtype *args, const std::string dflt)

Same as above, but with a default value should key not be in args.

double dble(const std::string &key, argtype *args)

Read an argument and remove it from args, then return as double.

double dble(const std::string &key, argtype *args, const double dflt)

Same as above, but with a default value should key not be in args.

float flt(const std::string &key, argtype *args, const float dflt)

Same as above, but with a default value should key not be in args.

int integer(const std::string &key, argtype *args)

Read an argument and remove it from args, then return as double.

int integer(const std::string &key, argtype *args, const int dflt)

Same as above, but with a default value should key not be in args.

bool boolean(const std::string &key, argtype *args)

Read an argument and remove it from args, then return as a boolean.

bool boolean(const std::string &key, argtype *args, const bool dflt)

Same as above, but with a default value should key not be in args.

void append(const std::string &key, argtype *args, const std::string &append)

Append to given key.

template<class T>
std::shared_ptr<T> parse(T *obj, arglist *args)

If args contains derived class of T, return factory pointer and remove from args.

void add_if_not_used(const std::string &key, argtype *args, const std::string &value)

If an argument is not used, add it.

argtype line_to_argtype(const std::string line)

convert a space-delimited string into argtype

void replace_value(const std::string search, const std::string replace, arglist *args)

Find all values equal to “search” in args and replace with “replace”.

void replace_in_value(const std::string &from, const std::string &to, arglist *args)

Find all values that contain “search” in args and replace with “replace”.

std::vector<double> parse_dimensional(const std::string &key, argtype *args, const int max)

Read data from arguments beginning with key and counting from 0 up. For example, “{{“x0”, “1”}, {“x1”, “2”}}” will return {1, 2} vector.

std::pair<std::string, argtype> parse_line(const std::string line, argtype *variables, bool *assign_to_list)

Parse a text interface line. These typically begin with an object Name, then space-separated arguments. First, look for set_variable, to generate a list of variables to use for name substitution. Finally, replace any value beginnig with /feasst with the install_dir().