Stan  2.10.0
probability, sampling & optimization
Public Member Functions | List of all members
stan::io::cmd_line Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

stan::io::cmd_line::cmd_line ( int  argc,
const char *  argv[] 
)
inline

Construct a command-line argument object from the specified command-line arguments.

Parameters
argcNumber of arguments.
argvArgument strings.

Definition at line 143 of file cmd_line.hpp.

Member Function Documentation

template<typename T >
bool stan::io::cmd_line::bare ( size_t  n,
T &  x 
) const
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.

Parameters
[in]nBare argument position.
[out]xReference to result.
Returns
true if there were enough bare arguments.
Template Parameters
TType of value returned.

Definition at line 231 of file cmd_line.hpp.

size_t stan::io::cmd_line::bare_size ( ) const
inline

Return the number of bare arguments.

Returns
Number of bare arguments.

Definition at line 213 of file cmd_line.hpp.

std::string stan::io::cmd_line::command ( )
inline

Returns the name of the command itself.

The command is always supplied as the first argument (at index 0).

Returns
Name of command.

Definition at line 156 of file cmd_line.hpp.

bool stan::io::cmd_line::has_flag ( const std::string &  flag) const
inline

Return true if the specified flag is defined.

Parameters
flagFlag to test.
Returns
true if flag is defined.

Definition at line 204 of file cmd_line.hpp.

bool stan::io::cmd_line::has_key ( const std::string &  key) const
inline

Return true if the specified key is defined.

Parameters
keyKey to test.
Returns
true if it has a value.

Definition at line 166 of file cmd_line.hpp.

void stan::io::cmd_line::print ( std::ostream &  out) const
inline

Print a human readable parsed form of the command-line arguments to the specified output stream.

Parameters
[out]outOutput stream.

Definition at line 246 of file cmd_line.hpp.

template<typename T >
bool stan::io::cmd_line::val ( const std::string &  key,
T &  x 
) const
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.

Parameters
[in]keyKey whose value is returned.
[out]xReference to value.
Returns
False if the key is not found, and true if it is found.
Template Parameters
Typeof value.

Definition at line 190 of file cmd_line.hpp.


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

     [ Stan Home Page ] © 2011–2016, Stan Development Team.