Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
icl_core::config::Getopt Class Reference

Handles commandline parameters. More...

#include <GetoptParser.h>

Classes

struct  KeyValue
 

Public Types

enum  CommandLineCleaning { eCLC_None, eCLC_Cleanup }
 
typedef ICL_CORE_VC_DEPRECATE ParameterRegistrationCheck tParameterRegistrationCheck ICL_CORE_GCC_DEPRECATE
 
typedef ICL_CORE_VC_DEPRECATE CommandLineCleaning tCommandLineCleaning ICL_CORE_GCC_DEPRECATE
 
typedef icl_core::List< KeyValueKeyValueList
 
enum  ParameterRegistrationCheck { ePRC_Strict, ePRC_Relaxed }
 

Public Member Functions

void activateExtraCmdParams (const icl_core::String &delimiter="--")
 
void addParameter (const GetoptParameter &parameter)
 
void addParameter (const GetoptParameterList &parameters)
 
void addParameter (const GetoptPositionalParameter &parameter)
 
void addParameter (const GetoptPositionalParameterList &parameters)
 
int & argc ()
 Get the original argc. More...
 
char ** argv () const
 Get the original argv. More...
 
icl_core::String extraCmdParam (size_t index) const
 
size_t extraCmdParamCount () const
 
bool initialize (int &argc, char *argv[], bool remove_read_arguments)
 
bool initialize (int &argc, char *argv[], CommandLineCleaning cleanup=eCLC_None, ParameterRegistrationCheck registration_check=ePRC_Strict)
 
bool isInitialized () const
 
icl_core::String paramNonOpt (size_t index) const
 
size_t paramNonOptCount () const
 
icl_core::String paramOpt (const icl_core::String &name) const
 
bool paramOptPresent (const icl_core::String &name) const
 
KeyValueList paramPrefixOpt (const icl_core::String &prefix) const
 
bool paramPrefixOptPresent (const icl_core::String &prefix) const
 
void printHelp () const
 
icl_core::String programDescription () const
 
icl_core::String programName () const
 
icl_core::String programVersion () const
 
void setProgramDescription (icl_core::String const &description)
 
void setProgramVersion (icl_core::String const &version)
 

Static Public Member Functions

static Getoptinstance ()
 

Private Types

typedef icl_core::Map< icl_core::String, GetoptParameterParameterMap
 

Private Member Functions

 Getopt ()
 

Private Attributes

int m_argc
 
char ** m_argv
 
icl_core::Vector< icl_core::Stringm_extra_cmd_param
 
bool m_extra_cmd_param_activated
 
icl_core::String m_extra_cmd_param_delimiter
 
bool m_initialized
 
GetoptPositionalParameterList m_optional_positional_parameters
 
icl_core::Vector< icl_core::Stringm_param_non_opt
 
icl_core::Map< icl_core::String, icl_core::Stringm_param_opt
 
ParameterMap m_parameters
 
icl_core::Map< icl_core::String, KeyValueListm_prefix_param_opt
 
ParameterMap m_prefix_parameters
 
icl_core::String m_program_description
 
icl_core::String m_program_name
 
icl_core::String m_program_version
 
GetoptPositionalParameterList m_required_positional_parameters
 
ParameterMap m_short_parameters
 
ParameterMap m_short_prefix_parameters
 

Detailed Description

Handles commandline parameters.

Getopt reads all commandline parameters and extracts commandline options (both key/value and simple ones). All parameters, which which were not identified as option parameters can be accessed as non-option parameters.

Commandline options have to be registered with calls to AddParameter(). Then parsing the commandline is initialized by a call to Initialize() with the commandline as arguments.

Getopt is implemented as a singleton so that it can be used from everywhere after it has been initialized once.

Definition at line 54 of file GetoptParser.h.

Member Typedef Documentation

Definition at line 62 of file GetoptParser.h.

Definition at line 69 of file GetoptParser.h.

Definition at line 81 of file GetoptParser.h.

Definition at line 310 of file GetoptParser.h.

Member Enumeration Documentation

Enumerator
eCLC_None 

command line options are left untouched

eCLC_Cleanup 

known command line options are removed

Definition at line 64 of file GetoptParser.h.

Enumerator
ePRC_Strict 

all options have to be registered

ePRC_Relaxed 

options not registered are ignored

Definition at line 57 of file GetoptParser.h.

Constructor & Destructor Documentation

icl_core::config::Getopt::Getopt ( )
private

Definition at line 704 of file GetoptParser.cpp.

Member Function Documentation

void icl_core::config::Getopt::activateExtraCmdParams ( const icl_core::String delimiter = "--")

Active extra command parameters. They are delimited from regular commandline parameters using the delimiter and run from there to the end of the commandline.

Definition at line 39 of file GetoptParser.cpp.

void icl_core::config::Getopt::addParameter ( const GetoptParameter parameter)

Adds a parameter to the list of commandline options.

Definition at line 45 of file GetoptParser.cpp.

void icl_core::config::Getopt::addParameter ( const GetoptParameterList parameters)

Adds a list of parameters to the list of commandline options.

Definition at line 65 of file GetoptParser.cpp.

void icl_core::config::Getopt::addParameter ( const GetoptPositionalParameter parameter)

Adds a positional parameter to the list of commandline options.

Definition at line 74 of file GetoptParser.cpp.

void icl_core::config::Getopt::addParameter ( const GetoptPositionalParameterList parameters)

Adds a list of positional parameters to the list of commandline options.

Definition at line 86 of file GetoptParser.cpp.

int & icl_core::config::Getopt::argc ( )

Get the original argc.

Definition at line 375 of file GetoptParser.cpp.

char ** icl_core::config::Getopt::argv ( ) const

Get the original argv.

Definition at line 380 of file GetoptParser.cpp.

icl_core::String icl_core::config::Getopt::extraCmdParam ( size_t  index) const

Get the extra command parameter at index.

Definition at line 385 of file GetoptParser.cpp.

size_t icl_core::config::Getopt::extraCmdParamCount ( ) const

Get the number of extra command parameters.

Definition at line 390 of file GetoptParser.cpp.

bool icl_core::config::Getopt::initialize ( int &  argc,
char *  argv[],
bool  remove_read_arguments 
)

Initializes Getopt with a commandline.

Deprecated:
Please use Initialize(argc, argv, eCLC_None) or Initialize(argc, argv, eCLC_Cleanup) instead which provides the same functionality.

Definition at line 95 of file GetoptParser.cpp.

bool icl_core::config::Getopt::initialize ( int &  argc,
char *  argv[],
CommandLineCleaning  cleanup = eCLC_None,
ParameterRegistrationCheck  registration_check = ePRC_Strict 
)

Initializes Getopt with a commandline.

Parameters
argcNumber of command line options in argv
argvCommand line options
cleanupCan be eCLC_None to leave argc and argv untouched or eCLC_Cleanup to remove known options from argv and decrease argc appropriately
registration_checkWhen encountering a not registered command line option, the value ePRC_Strict causes the initialization to fail, while ePRC_Relaxed accepts it anyway
Note
this would be nice but breaks backwards compatibility where people use ePRC_Strict but want to use unregistered positional parameters.

Definition at line 100 of file GetoptParser.cpp.

Getopt & icl_core::config::Getopt::instance ( )
static

Get the singleton instance.

Definition at line 33 of file GetoptParser.cpp.

bool icl_core::config::Getopt::isInitialized ( ) const
inline

Returns true if Getopt has already been initialized.

Definition at line 135 of file GetoptParser.h.

icl_core::String icl_core::config::Getopt::paramNonOpt ( size_t  index) const

Get the non-option parameter at the specified index.

Returns
An empty string if no such parameter exists.

Definition at line 431 of file GetoptParser.cpp.

size_t icl_core::config::Getopt::paramNonOptCount ( ) const

Get the number of non-option parameters.

Definition at line 443 of file GetoptParser.cpp.

icl_core::String icl_core::config::Getopt::paramOpt ( const icl_core::String name) const

Get the value of the commandline option name.

Returns
An empty string if the option has not been set, otherwise the value of the option.

Definition at line 395 of file GetoptParser.cpp.

bool icl_core::config::Getopt::paramOptPresent ( const icl_core::String name) const

Checks if the option name is present.

Definition at line 408 of file GetoptParser.cpp.

Getopt::KeyValueList icl_core::config::Getopt::paramPrefixOpt ( const icl_core::String prefix) const

Get the list of defined suffixes for the specified prefix.

Definition at line 413 of file GetoptParser.cpp.

bool icl_core::config::Getopt::paramPrefixOptPresent ( const icl_core::String prefix) const

Check in a prefix option is present.

Definition at line 426 of file GetoptParser.cpp.

void icl_core::config::Getopt::printHelp ( ) const

Prints the help text.

Definition at line 473 of file GetoptParser.cpp.

icl_core::String icl_core::config::Getopt::programDescription ( ) const

Get the program description.

Definition at line 463 of file GetoptParser.cpp.

icl_core::String icl_core::config::Getopt::programName ( ) const

Get the program name.

Definition at line 448 of file GetoptParser.cpp.

icl_core::String icl_core::config::Getopt::programVersion ( ) const

Get the program version.

Definition at line 453 of file GetoptParser.cpp.

void icl_core::config::Getopt::setProgramDescription ( icl_core::String const &  description)

Set the program description, a short string describing the program's purpose.

Definition at line 468 of file GetoptParser.cpp.

void icl_core::config::Getopt::setProgramVersion ( icl_core::String const &  version)

Set the program version.

Definition at line 458 of file GetoptParser.cpp.

Member Data Documentation

int icl_core::config::Getopt::m_argc
private

Definition at line 322 of file GetoptParser.h.

char** icl_core::config::Getopt::m_argv
private

Definition at line 323 of file GetoptParser.h.

icl_core::Vector<icl_core::String> icl_core::config::Getopt::m_extra_cmd_param
private

Definition at line 330 of file GetoptParser.h.

bool icl_core::config::Getopt::m_extra_cmd_param_activated
private

Definition at line 317 of file GetoptParser.h.

icl_core::String icl_core::config::Getopt::m_extra_cmd_param_delimiter
private

Definition at line 318 of file GetoptParser.h.

bool icl_core::config::Getopt::m_initialized
private

Definition at line 320 of file GetoptParser.h.

GetoptPositionalParameterList icl_core::config::Getopt::m_optional_positional_parameters
private

Definition at line 316 of file GetoptParser.h.

icl_core::Vector<icl_core::String> icl_core::config::Getopt::m_param_non_opt
private

Definition at line 327 of file GetoptParser.h.

icl_core::Map<icl_core::String, icl_core::String> icl_core::config::Getopt::m_param_opt
private

Definition at line 328 of file GetoptParser.h.

ParameterMap icl_core::config::Getopt::m_parameters
private

Definition at line 311 of file GetoptParser.h.

icl_core::Map<icl_core::String, KeyValueList> icl_core::config::Getopt::m_prefix_param_opt
private

Definition at line 329 of file GetoptParser.h.

ParameterMap icl_core::config::Getopt::m_prefix_parameters
private

Definition at line 312 of file GetoptParser.h.

icl_core::String icl_core::config::Getopt::m_program_description
private

Definition at line 326 of file GetoptParser.h.

icl_core::String icl_core::config::Getopt::m_program_name
private

Definition at line 324 of file GetoptParser.h.

icl_core::String icl_core::config::Getopt::m_program_version
private

Definition at line 325 of file GetoptParser.h.

GetoptPositionalParameterList icl_core::config::Getopt::m_required_positional_parameters
private

Definition at line 315 of file GetoptParser.h.

ParameterMap icl_core::config::Getopt::m_short_parameters
private

Definition at line 313 of file GetoptParser.h.

ParameterMap icl_core::config::Getopt::m_short_prefix_parameters
private

Definition at line 314 of file GetoptParser.h.


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


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:59