Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
icl_core::config::Getopt Class Reference

Handles commandline parameters. More...

#include <GetoptParser.h>

List of all members.

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.
char ** argv () const
 Get the original argv.
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,
GetoptParameter
ParameterMap

Private Member Functions

 Getopt ()

Private Attributes

int m_argc
char ** m_argv
icl_core::Vector
< icl_core::String
m_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::String
m_param_non_opt
icl_core::Map
< icl_core::String,
icl_core::String
m_param_opt
ParameterMap m_parameters
icl_core::Map
< icl_core::String,
KeyValueList
m_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

Definition at line 704 of file GetoptParser.cpp.


Member Function Documentation

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.

Adds a parameter to the list of commandline options.

Definition at line 45 of file GetoptParser.cpp.

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

Definition at line 65 of file GetoptParser.cpp.

Adds a positional parameter to the list of commandline options.

Definition at line 74 of file GetoptParser.cpp.

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

Definition at line 86 of file GetoptParser.cpp.

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.

Get the extra command parameter at index.

Definition at line 385 of file GetoptParser.cpp.

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.

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.

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.

Get the number of non-option parameters.

Definition at line 443 of file GetoptParser.cpp.

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.

Checks if the option name is present.

Definition at line 408 of file GetoptParser.cpp.

Get the list of defined suffixes for the specified prefix.

Definition at line 413 of file GetoptParser.cpp.

Check in a prefix option is present.

Definition at line 426 of file GetoptParser.cpp.

Prints the help text.

Definition at line 473 of file GetoptParser.cpp.

Get the program description.

Definition at line 463 of file GetoptParser.cpp.

Get the program name.

Definition at line 448 of file GetoptParser.cpp.

Get the program version.

Definition at line 453 of file GetoptParser.cpp.

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

Definition at line 468 of file GetoptParser.cpp.

Set the program version.

Definition at line 458 of file GetoptParser.cpp.


Member Data Documentation

Definition at line 322 of file GetoptParser.h.

Definition at line 323 of file GetoptParser.h.

Definition at line 330 of file GetoptParser.h.

Definition at line 317 of file GetoptParser.h.

Definition at line 318 of file GetoptParser.h.

Definition at line 320 of file GetoptParser.h.

Definition at line 316 of file GetoptParser.h.

Definition at line 327 of file GetoptParser.h.

Definition at line 328 of file GetoptParser.h.

Definition at line 311 of file GetoptParser.h.

Definition at line 329 of file GetoptParser.h.

Definition at line 312 of file GetoptParser.h.

Definition at line 326 of file GetoptParser.h.

Definition at line 324 of file GetoptParser.h.

Definition at line 325 of file GetoptParser.h.

Definition at line 315 of file GetoptParser.h.

Definition at line 313 of file GetoptParser.h.

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 Thu Jun 6 2019 20:22:26