![]() |
Stan
2.10.0
probability, sampling & optimization
|
Parses and stores command-line arguments. More...
#include <cmd_line.hpp>
Public Member Functions | |
cmd_line (int argc, const char *argv[]) | |
Construct a command-line argument object from the specified command-line arguments. More... | |
std::string | command () |
Returns the name of the command itself. More... | |
bool | has_key (const std::string &key) const |
Return true if the specified key is defined. More... | |
template<typename T > | |
bool | val (const std::string &key, T &x) const |
Returns the value for the key provided. More... | |
bool | has_flag (const std::string &flag) const |
Return true if the specified flag is defined. More... | |
size_t | bare_size () const |
Return the number of bare arguments. More... | |
template<typename T > | |
bool | bare (size_t n, T &x) const |
Returns the bare argument. More... | |
void | print (std::ostream &out) const |
Print a human readable parsed form of the command-line arguments to the specified output stream. More... | |
Parses and stores command-line arguments.
Command-line arguments are organized into four types.
Command: The first argument (at index 0) is just the command itself. There method command()
retrieves the command.
Key/Value: The second type of argument is a key-value pair, which must be in the form –key=val
. Two hyphens are used to separate arguments from negated numbers. The method has_key(const std::string&)
indicates if there is a key and val(const std::string&,T&)
writes its value into a reference (whose type is templated; any type understand by the output operator >>
is acceptable.
Flag: Flags are specified as –flag
. The method has_flag(const std::string&)
tests if a flag is present.
Bare Argument: Bare arguments are any arguments that are not prefixed with two hyphens (–
). The method bare_size()
returns the number of bare arguments and they are retrieved with the generic method bare(const std::string&,T&)
.
Definition at line 113 of file cmd_line.hpp.
|
inline |
Construct a command-line argument object from the specified command-line arguments.
argc | Number of arguments. |
argv | Argument strings. |
Definition at line 143 of file cmd_line.hpp.
|
inline |
Returns the bare argument.
If the specified index is valid for bare arguments, write the bare argument at the specified index into the specified reference, and otherwise return false without modifying the reference.
[in] | n | Bare argument position. |
[out] | x | Reference to result. |
true
if there were enough bare arguments. T | Type of value returned. |
Definition at line 231 of file cmd_line.hpp.
|
inline |
Return the number of bare arguments.
Definition at line 213 of file cmd_line.hpp.
|
inline |
Returns the name of the command itself.
The command is always supplied as the first argument (at index 0).
Definition at line 156 of file cmd_line.hpp.
|
inline |
Return true
if the specified flag is defined.
flag | Flag to test. |
true
if flag is defined. Definition at line 204 of file cmd_line.hpp.
|
inline |
Return true
if the specified key is defined.
key | Key to test. |
true
if it has a value. Definition at line 166 of file cmd_line.hpp.
|
inline |
Print a human readable parsed form of the command-line arguments to the specified output stream.
[out] | out | Output stream. |
Definition at line 246 of file cmd_line.hpp.
|
inline |
Returns the value for the key provided.
If the specified key is defined, write the value of the key into the specified reference and return true
, otherwise do not modify the reference and return false
.
The conversions defined by std::ostream
are used to convert the base string value to the specified type. Thus this method will work as long as operator>>()
is defined for the specified type.
[in] | key | Key whose value is returned. |
[out] | x | Reference to value. |
Type | of value. |
Definition at line 190 of file cmd_line.hpp.