CBMC
cmdlinet Class Reference

#include <cmdline.h>

+ Inheritance diagram for cmdlinet:
+ Collaboration diagram for cmdlinet:

Classes

struct  option_namest
 
struct  optiont
 

Public Types

typedef std::vector< std::string > argst
 

Public Member Functions

virtual bool parse (int argc, const char **argv, const char *optstring)
 Parses a commandline according to a specification given in optstring. More...
 
std::string get_value (char option) const
 
std::string get_value (const char *option) const
 
const std::list< std::string > & get_values (const std::string &option) const
 
const std::list< std::string > & get_values (char option) const
 
std::list< std::string > get_comma_separated_values (const char *option) const
 Collect all occurrences of option option and split their values on each comma, merging them into a single list of values. More...
 
virtual bool isset (char option) const
 
virtual bool isset (const char *option) const
 
virtual void set (const std::string &option, bool value=true)
 Set option option to value, or true if the value is omitted. More...
 
virtual void set (const std::string &option, const std::string &value)
 
virtual void set (const std::string &option, const char *value)
 
virtual void clear ()
 
bool has_option (const std::string &option) const
 
option_namest option_names () const
 Pseudo-object that can be used to iterate over options in this cmdlinet (should not outlive this) More...
 
 cmdlinet ()
 
virtual ~cmdlinet ()
 
std::vector< std::string > get_argument_suggestions (const std::string &unknown_argument)
 

Public Attributes

argst args
 
std::string unknown_arg
 

Protected Member Functions

void parse_optstring (const char *optstring)
 Parses an optstring and writes the result to cmdlinet::options. More...
 
bool parse_arguments (int argc, const char **argv)
 Parses a commandline according to a previously parsed optstring and writes the result to cmdlinet::options. More...
 
std::optional< std::size_t > getoptnr (char option) const
 
std::optional< std::size_t > getoptnr (const std::string &option) const
 

Protected Attributes

std::vector< optiontoptions
 

Detailed Description

Definition at line 19 of file cmdline.h.

Member Typedef Documentation

◆ argst

typedef std::vector<std::string> cmdlinet::argst

Definition at line 150 of file cmdline.h.

Constructor & Destructor Documentation

◆ cmdlinet()

cmdlinet::cmdlinet ( )

Definition at line 16 of file cmdline.cpp.

◆ ~cmdlinet()

cmdlinet::~cmdlinet ( )
virtual

Definition at line 20 of file cmdline.cpp.

Member Function Documentation

◆ clear()

void cmdlinet::clear ( void  )
virtual

Definition at line 24 of file cmdline.cpp.

◆ get_argument_suggestions()

std::vector< std::string > cmdlinet::get_argument_suggestions ( const std::string &  unknown_argument)

Definition at line 210 of file cmdline.cpp.

◆ get_comma_separated_values()

std::list< std::string > cmdlinet::get_comma_separated_values ( const char *  option) const

Collect all occurrences of option option and split their values on each comma, merging them into a single list of values.

Definition at line 121 of file cmdline.cpp.

◆ get_value() [1/2]

std::string cmdlinet::get_value ( char  option) const

Definition at line 48 of file cmdline.cpp.

◆ get_value() [2/2]

std::string cmdlinet::get_value ( const char *  option) const

Definition at line 99 of file cmdline.cpp.

◆ get_values() [1/2]

const std::list< std::string > & cmdlinet::get_values ( char  option) const

Definition at line 89 of file cmdline.cpp.

◆ get_values() [2/2]

const std::list< std::string > & cmdlinet::get_values ( const std::string &  option) const

Definition at line 109 of file cmdline.cpp.

◆ getoptnr() [1/2]

std::optional< std::size_t > cmdlinet::getoptnr ( char  option) const
protected

Definition at line 135 of file cmdline.cpp.

◆ getoptnr() [2/2]

std::optional< std::size_t > cmdlinet::getoptnr ( const std::string &  option) const
protected

Definition at line 144 of file cmdline.cpp.

◆ has_option()

bool cmdlinet::has_option ( const std::string &  option) const
inline

Definition at line 98 of file cmdline.h.

◆ isset() [1/2]

bool cmdlinet::isset ( char  option) const
virtual

Definition at line 30 of file cmdline.cpp.

◆ isset() [2/2]

bool cmdlinet::isset ( const char *  option) const
virtual

Definition at line 39 of file cmdline.cpp.

◆ option_names()

cmdlinet::option_namest cmdlinet::option_names ( ) const

Pseudo-object that can be used to iterate over options in this cmdlinet (should not outlive this)

Definition at line 161 of file cmdline.cpp.

◆ parse()

bool cmdlinet::parse ( int  argc,
const char **  argv,
const char *  optstring 
)
virtual

Parses a commandline according to a specification given in optstring.

Parameters
argcHow many arguments there are.
argvAn array of C strings. The 0th element is assumed to be the name of the command as it was invoked (e.g. /usr/bin/cmake) and is ignored. It is further assumed the array holds argc+1 elements with the C string at index argc being a terminating null pointer. This argument is parsed based on optstring.
optstringA specification of allowed command line options. This is a C string container any number of single characters other than '(', ')' or ':' signifying a "short" option consisting of just that character, or names consisting of any characters other than ')' surrounded by a matching pair of '(' and ')' signifying a "long" option with the name being the string between '(' and ')', both of which can be optionally followed by a single ':' indicating that the option takes a argument, if not present it does not. arguments must be in the next array element in argv , except for short options whose argument may also be concatenated directly on them.

Option names in argv must start with either '-' or "--", no distinction between long and short options is made here, although it is customary to use only one '-' for short options and "--" for long options.

All options are optional, if some are required it is up to the user to check that they are present.

Examples:

argc = 4 argv = {"name", "-V", "--name", "CProver", nullptr} opstring = "V(version)(name):"

here the argument to "name" would be "CProver", and "V" is a short option passed without arguments.

argc = 3 argv = {"other-name", "-fFilename", "--trace", nullptr} optstring = "f:(trace)(some-other-option):G"

here the argument to option "f" would be "Filename", "trace" is a long option with no argument, and "some-other-option" and "G" are both allowed options that don’t appear on the commandline (with and without argument respectively).

Returns
true if there was an error while parsing argv, false otherwise. If this failed due to an unknown option name being in argv, the public variable cmdlinet::unknown_arg will be non-empty and contain the name of that option.

Definition at line 153 of file cmdline.cpp.

◆ parse_arguments()

bool cmdlinet::parse_arguments ( int  argc,
const char **  argv 
)
protected

Parses a commandline according to a previously parsed optstring and writes the result to cmdlinet::options.

See also
cmdlinet::parse(int,const char**,const char*) for details the meaning of argc and argv

Definition at line 269 of file cmdline.cpp.

◆ parse_optstring()

void cmdlinet::parse_optstring ( const char *  optstring)
protected

Parses an optstring and writes the result to cmdlinet::options.

It is considered a logic error to pass an invalid option string here.

See also
cmdlinet::parse(int,const char**,const char*) for details on the format of the optstring

Definition at line 165 of file cmdline.cpp.

◆ set() [1/3]

void cmdlinet::set ( const std::string &  option,
bool  value = true 
)
virtual

Set option option to value, or true if the value is omitted.

Reimplemented in goto_cc_cmdlinet.

Definition at line 58 of file cmdline.cpp.

◆ set() [2/3]

virtual void cmdlinet::set ( const std::string &  option,
const char *  value 
)
inlinevirtual

Reimplemented in goto_cc_cmdlinet.

Definition at line 91 of file cmdline.h.

◆ set() [3/3]

void cmdlinet::set ( const std::string &  option,
const std::string &  value 
)
virtual

Reimplemented in goto_cc_cmdlinet.

Definition at line 71 of file cmdline.cpp.

Member Data Documentation

◆ args

argst cmdlinet::args

Definition at line 151 of file cmdline.h.

◆ options

std::vector<optiont> cmdlinet::options
protected

Definition at line 190 of file cmdline.h.

◆ unknown_arg

std::string cmdlinet::unknown_arg

Definition at line 152 of file cmdline.h.


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