Gromacs  2016.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Member Functions
gmx::CommandLineParser Class Reference

#include <gromacs/commandline/cmdlineparser.h>

Description

Implements command-line parsing for Options objects.

Typical usage (without error checking):

gmx::Options options("name", "description");
// Fill up options
gmx::CommandLineParser(&options).parse(&argc, argv);
options.finish();
*

Classes

class  Impl
 Private implementation class for CommandLineParser. More...
 

Public Member Functions

 CommandLineParser (Options *options)
 Creates a command-line parser that sets values for options. More...
 
CommandLineParserskipUnknown (bool bEnabled)
 Makes the parser skip unknown options and keep them in argv. More...
 
void parse (int *argc, char *argv[])
 Parses the command line. More...
 

Constructor & Destructor Documentation

gmx::CommandLineParser::CommandLineParser ( Options options)
explicit

Creates a command-line parser that sets values for options.

Parameters
[in]optionsOptions object whose options should be set.
Exceptions
std::bad_allocif out of memory.

Member Function Documentation

void gmx::CommandLineParser::parse ( int *  argc,
char *  argv[] 
)

Parses the command line.

Exceptions
std::bad_allocif out of memory.
InvalidInputErrorif any errors were detected in the input.

All command-line arguments are parsed, and an aggregate exception with all the detected errors is thrown in the end.

If skipUnknown() is false, the input parameters are not modified. If skipUnknown() is true, recognized options and their values are removed from the argument list. argv[0] is never modified.

CommandLineParser & gmx::CommandLineParser::skipUnknown ( bool  bEnabled)

Makes the parser skip unknown options and keep them in argv.

Parameters
[in]bEnabledWhether to skip and keep unknown options.
Returns
*this

Setting this option to true has dual effect: unknown options are silently skipped, and all recognized options are removed from argc and argv in parse(). These effects should be easy to separate into different flags if there is need for it.

The default is false: unknown options result in exceptions and argc and argv are not modified.

Does not throw.


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