![]() |
PhoenixPresentation
2.0.0
Set of cmake function to automate presentation generation
|
Parse the options passed to a program. More...
#include <OptionParser.h>
Public Member Functions | |
void | addMode (const PString &modeName) |
Add a mode in the option. More... | |
template<typename T > | |
void | addOption (const PString &longOption, const PString &shortOption, const T defaultValue, const PString &docString) |
Add an option in the OptionParser. More... | |
template<typename T > | |
void | addOption (const PString &longOption, const PString &shortOption, const T defaultValue, OptionType::OptionType optionType, const PString &docString) |
Add an option in the OptionParser. More... | |
void | addOption (const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, bool isAllowEmpty, const PString &docString) |
Add an option in the OptionParser. More... | |
void | addOption (const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, bool isAllowEmpty, const PVecString &vecPossibleValue, const PString &docString) |
Add an option in the OptionParser. More... | |
void | addOption (const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, const PString &docString) |
Add an option in the OptionParser. More... | |
void | closeMode () |
Close the current mode and go back to be default one. More... | |
OptionMode & | getDefaultMode () |
Get default mode. More... | |
const OptionMode & | getDefaultMode () const |
Get default mode. More... | |
OptionMode & | getMode (const PString &name) |
Get mode by name. More... | |
const OptionMode & | getMode (const PString &name) const |
Get mode by name. More... | |
bool | isModeExist (const PString &name) const |
Check if the given mode name does exist. More... | |
OptionParser & | operator= (const OptionParser &other) |
Definition of equal operator of OptionParser. More... | |
OptionParser (bool enableHelpOption=true, const PString &programVersion="") | |
Default constructeur of OptionParser. More... | |
OptionParser (const OptionParser &other) | |
Copy constructor of OptionParser. More... | |
void | parseArgument (int argc, char **argv) |
Parse the arguments passed to the program. More... | |
void | print () const |
Print all the options. More... | |
void | setExampleLongOption (const PString &example) |
Set the example usage of the program. More... | |
void | setExampleShortOption (const PString &example) |
Set the example usage of the program. More... | |
virtual | ~OptionParser () |
Destructeur of OptionParser. More... | |
Protected Member Functions | |
void | copyOptionParser (const OptionParser &other) |
Copy function of OptionParser. More... | |
Private Member Functions | |
bool | checkArgument () const |
Check the argument of the parser. More... | |
template<typename T > | |
void | checkOptionType (OptionType::OptionType optionType) |
Check the given option type. More... | |
bool | completeOptionValue (PString &possibleValue, const PString &cursorOption, const PString &prevCursorOption) const |
Complete the possible value of an option (FILENAME, DIRECTORY, FILE_OR_DIR) More... | |
const OptionMode * | getCurrentlyParsedMode () const |
Get the currently parsed OptionMode. More... | |
const Option * | getLongOptionValue (PString &valueToBeCompleted, const PString &cursorOption) const |
Get the long option value to be completed. More... | |
OptionMode & | getParserMode (ArgParser &parser) |
Get a mode if it exist. More... | |
void | getPossibleOption (PString &possibleOption, const PString &cursorOption) const |
Get the possible options which can be used. More... | |
void | getPossibleOtherOption (PString &possibleOption, const PString &cursorOption) const |
Get the possible other options which can be used. More... | |
const Option * | getSplitOptionValue (PString &valueToBeCompleted, const PString &cursorOption, const PString &prevCursorOption) const |
Get the split option (without =) value to be completed. More... | |
void | initialisationOptionParser () |
Initialisation function of the class OptionParser. More... | |
void | parseArgumentBashCompletion (ArgParser &parser) |
Bash completion argument parsing mode. More... | |
void | parseArgumentNormalUse (ArgParser &parser) |
Classical argument parsing mode. More... | |
Private Attributes | |
size_t | p_currentMode |
Index of the current mode in the OptionParser. More... | |
OptionMode * | p_currentParserMode |
Current mode parsed. More... | |
bool | p_enableHelpOption |
True to enable automatically the printing of the help option when the program is called with –help or -h. More... | |
PString | p_exempleLongOption |
Usage example with long options. More... | |
PString | p_exempleShortOption |
Usage example with short options. More... | |
PString | p_programVersion |
Program version to be printed on –version or -v option. More... | |
VecMode | p_vecMode |
Vector of all the defined mode in the OptionParser. More... | |
Parse the options passed to a program.
When you define an option, you do not have to pass the '-' of the option name exampe : –longoption or -shortoption you pass only longoption and shortoption
Definition at line 15 of file OptionParser.h.
OptionParser::OptionParser | ( | bool | enableHelpOption = true , |
const PString & | programVersion = "" |
||
) |
Default constructeur of OptionParser.
enableHelpOption | : True to enable automatically the printing of the help option when the program is called with –help or -h |
programVersion | : version of the program to be printed on –version or -v options |
Definition at line 13 of file OptionParser.cpp.
References initialisationOptionParser().
OptionParser::OptionParser | ( | const OptionParser & | other | ) |
Copy constructor of OptionParser.
other | : class to copy |
Definition at line 22 of file OptionParser.cpp.
References copyOptionParser().
|
virtual |
void OptionParser::addMode | ( | const PString & | modeName | ) |
Add a mode in the option.
modeName | : name of the new mode to be added |
Definition at line 53 of file OptionParser.cpp.
References p_currentMode, p_enableHelpOption, p_programVersion, p_vecMode, OptionMode::setEnableHelpOption(), and OptionMode::setProgramVersion().
Referenced by createOptionParser().
void OptionParser::addOption | ( | const PString & | longOption, |
const PString & | shortOption, | ||
const T | defaultValue, | ||
const PString & | docString | ||
) |
Add an option in the OptionParser.
longOption | : long option (start with –) as –version |
shortOption | : short option (start with -) as -v |
defaultValue | : default value of the option |
docString | : documentation string of the option The type of the option will be automatically determined with the type of the default value |
Definition at line 21 of file OptionParser_impl.h.
References p_vecMode, OptionValue::setDefaultValue(), and OptionValue::setType().
void OptionParser::addOption | ( | const PString & | longOption, |
const PString & | shortOption, | ||
const T | defaultValue, | ||
OptionType::OptionType | optionType, | ||
const PString & | docString | ||
) |
Add an option in the OptionParser.
longOption | : long option (start with –) as –version |
shortOption | : short option (start with -) as -v |
defaultValue | : default value of the option |
optionType | : type of the data of the option (int, float, double, string, etc) |
docString | : documentation string of the option The function will check if the given optionType is relevant with the type of the default value |
Definition at line 39 of file OptionParser_impl.h.
References p_vecMode, OptionValue::setDefaultValue(), and OptionValue::setType().
void OptionParser::addOption | ( | const PString & | longOption, |
const PString & | shortOption, | ||
OptionType::OptionType | optionType, | ||
bool | isRequired, | ||
bool | isAllowEmpty, | ||
const PString & | docString | ||
) |
Add an option in the OptionParser.
longOption | : long option (start with –) as –version |
shortOption | : short option (start with -) as -v |
optionType | : type of the value to be parsed (INT, BOOL_ CHAR, FLOAT, STRING, FILENAME, DIRECTORY, etc) |
isRequired | : true if the option is required, false if it is optionnal |
isAllowEmpty | : the given value can be empty |
docString | : documentation string of the option |
Definition at line 91 of file OptionParser.cpp.
References p_currentMode, p_vecMode, Option::setIsAllowEmpty(), and OptionValue::setType().
void OptionParser::addOption | ( | const PString & | longOption, |
const PString & | shortOption, | ||
OptionType::OptionType | optionType, | ||
bool | isRequired, | ||
bool | isAllowEmpty, | ||
const PVecString & | vecPossibleValue, | ||
const PString & | docString | ||
) |
Add an option in the OptionParser.
longOption | : long option (start with –) as –version |
shortOption | : short option (start with -) as -v |
optionType | : type of the value to be parsed (INT, BOOL_ CHAR, FLOAT, STRING, FILENAME, DIRECTORY, etc) |
isRequired | : true if the option is required, false if it is optionnal |
isAllowEmpty | : the given value can be empty |
vecPossibleValue | : vector of possible values for this option |
docString | : documentation string of the option |
Definition at line 110 of file OptionParser.cpp.
References p_currentMode, p_vecMode, Option::setIsAllowEmpty(), OptionValue::setType(), and OptionValue::setVecPossibleValue().
void OptionParser::addOption | ( | const PString & | longOption, |
const PString & | shortOption, | ||
OptionType::OptionType | optionType, | ||
bool | isRequired, | ||
const PString & | docString | ||
) |
Add an option in the OptionParser.
longOption | : long option (start with –) as –version |
shortOption | : short option (start with -) as -v |
optionType | : type of the value to be parsed (INT, BOOL_ CHAR, FLOAT, STRING, FILENAME, DIRECTORY, etc) |
isRequired | : true if the option is required, false if it is optionnal |
docString | : documentation string of the option |
Definition at line 73 of file OptionParser.cpp.
References p_currentMode, p_vecMode, Option::setIsAllowEmpty(), and OptionValue::setType().
Referenced by createOptionParser().
|
private |
Check the argument of the parser.
Definition at line 309 of file OptionParser.cpp.
References p_vecMode.
Referenced by parseArgumentNormalUse().
|
private |
Check the given option type.
optionType | : type of the option to be checked Throw an exception if there is a problem |
Definition at line 55 of file OptionParser_impl.h.
References convertOptionTypeToString(), and isOptionTypeCompatible().
void OptionParser::closeMode | ( | ) |
Close the current mode and go back to be default one.
Definition at line 62 of file OptionParser.cpp.
References p_currentMode.
Referenced by createOptionParser().
|
private |
Complete the possible value of an option (FILENAME, DIRECTORY, FILE_OR_DIR)
[out] | possibleValue | : possible value |
cursorOption | : option of the cursor which is currently completed | |
prevCursorOption | : previous option of the cursor |
Definition at line 355 of file OptionParser.cpp.
References getLongOptionValue(), Option::getPossibleValue(), and getSplitOptionValue().
Referenced by parseArgumentBashCompletion().
|
protected |
Copy function of OptionParser.
other | : class to copy |
Definition at line 208 of file OptionParser.cpp.
References p_currentMode, p_enableHelpOption, p_exempleLongOption, p_exempleShortOption, p_programVersion, and p_vecMode.
Referenced by operator=(), and OptionParser().
|
private |
Get the currently parsed OptionMode.
Definition at line 338 of file OptionParser.cpp.
References p_vecMode.
Referenced by getPossibleOption().
OptionMode & OptionParser::getDefaultMode | ( | ) |
Get default mode.
Definition at line 161 of file OptionParser.cpp.
References p_vecMode.
const OptionMode & OptionParser::getDefaultMode | ( | ) | const |
Get default mode.
Definition at line 154 of file OptionParser.cpp.
References p_vecMode.
Referenced by getMode(), main(), and printConstParser().
|
private |
Get the long option value to be completed.
[out] | valueToBeCompleted | : base of the value to be completed |
cursorOption | : option of the cursor which is currently completed |
Definition at line 376 of file OptionParser.cpp.
References PString::isSameBegining(), and p_vecMode.
Referenced by completeOptionValue().
OptionMode & OptionParser::getMode | ( | const PString & | name | ) |
Get mode by name.
name | : name of the mode to be returned |
Definition at line 182 of file OptionParser.cpp.
References getDefaultMode(), and p_vecMode.
const OptionMode & OptionParser::getMode | ( | const PString & | name | ) | const |
Get mode by name.
name | : name of the mode to be returned |
Definition at line 169 of file OptionParser.cpp.
References getDefaultMode(), and p_vecMode.
Referenced by getParserMode(), main(), and printConstParser().
|
private |
Get a mode if it exist.
parser | : parser to be used |
Definition at line 323 of file OptionParser.cpp.
References ArgParser::getCurrentOption(), getMode(), ArgParser::getNextOption(), isModeExist(), and p_currentParserMode.
Referenced by parseArgumentNormalUse().
|
private |
Get the possible options which can be used.
[out] | possibleOption | : possible options for the bash completion |
cursorOption | : option of the cursor which is currently completed |
Definition at line 433 of file OptionParser.cpp.
References getCurrentlyParsedMode(), OptionMode::getPossibleOption(), and p_vecMode.
Referenced by parseArgumentBashCompletion().
|
private |
Get the possible other options which can be used.
[out] | possibleOption | : possible options for the bash completion |
cursorOption | : option of the cursor which is currently completed |
Definition at line 452 of file OptionParser.cpp.
References PString::isSameBegining().
Referenced by parseArgumentBashCompletion().
|
private |
Get the split option (without =) value to be completed.
[out] | valueToBeCompleted | : base of the value to be completed |
cursorOption | : option of the cursor which is currently completed | |
prevCursorOption | : previous option of the cursor |
Definition at line 404 of file OptionParser.cpp.
References p_vecMode.
Referenced by completeOptionValue().
|
private |
Initialisation function of the class OptionParser.
Definition at line 218 of file OptionParser.cpp.
References p_currentMode, p_currentParserMode, and p_vecMode.
Referenced by OptionParser().
bool OptionParser::isModeExist | ( | const PString & | name | ) | const |
Check if the given mode name does exist.
name | : name of the mode |
Definition at line 195 of file OptionParser.cpp.
References p_vecMode.
Referenced by getParserMode().
OptionParser & OptionParser::operator= | ( | const OptionParser & | other | ) |
Definition of equal operator of OptionParser.
other | : class to copy |
Definition at line 35 of file OptionParser.cpp.
References copyOptionParser().
void OptionParser::parseArgument | ( | int | argc, |
char ** | argv | ||
) |
Parse the arguments passed to the program.
argc | : number of parameters passed to the program |
argv | : list of arguments passed to the program |
Definition at line 142 of file OptionParser.cpp.
References ArgParser::isBashCompletionMode(), parseArgumentBashCompletion(), and parseArgumentNormalUse().
Referenced by main().
|
private |
Bash completion argument parsing mode.
parser | : parser to be used |
Definition at line 261 of file OptionParser.cpp.
References completeOptionValue(), ArgParser::getCursorOption(), ArgParser::getNextOption(), getPossibleOption(), getPossibleOtherOption(), ArgParser::getPrevCursorOption(), ArgParser::isEndOfOption(), and p_vecMode.
Referenced by parseArgument().
|
private |
Classical argument parsing mode.
parser | : parser to be used |
Definition at line 228 of file OptionParser.cpp.
References checkArgument(), ArgParser::getCurrentOption(), OptionMode::getName(), getParserMode(), ArgParser::isEndOfOption(), p_currentParserMode, p_enableHelpOption, p_programVersion, p_vecMode, OptionMode::parseOption(), and print().
Referenced by parseArgument().
void OptionParser::print | ( | ) | const |
Print all the options.
Definition at line 122 of file OptionParser.cpp.
References p_exempleLongOption, p_exempleShortOption, and p_vecMode.
Referenced by main(), and parseArgumentNormalUse().
void OptionParser::setExampleLongOption | ( | const PString & | example | ) |
Set the example usage of the program.
example | : example of usage |
Definition at line 43 of file OptionParser.cpp.
References p_exempleLongOption.
Referenced by createOptionParser().
void OptionParser::setExampleShortOption | ( | const PString & | example | ) |
Set the example usage of the program.
example | : example of usage |
Definition at line 48 of file OptionParser.cpp.
References p_exempleShortOption.
Referenced by createOptionParser().
|
private |
Index of the current mode in the OptionParser.
Definition at line 80 of file OptionParser.h.
Referenced by addMode(), addOption(), closeMode(), copyOptionParser(), and initialisationOptionParser().
|
private |
Current mode parsed.
Definition at line 76 of file OptionParser.h.
Referenced by getParserMode(), initialisationOptionParser(), and parseArgumentNormalUse().
|
private |
True to enable automatically the printing of the help option when the program is called with –help or -h.
Definition at line 86 of file OptionParser.h.
Referenced by addMode(), copyOptionParser(), and parseArgumentNormalUse().
|
private |
Usage example with long options.
Definition at line 82 of file OptionParser.h.
Referenced by copyOptionParser(), print(), and setExampleLongOption().
|
private |
Usage example with short options.
Definition at line 84 of file OptionParser.h.
Referenced by copyOptionParser(), print(), and setExampleShortOption().
|
private |
Program version to be printed on –version or -v option.
Definition at line 88 of file OptionParser.h.
Referenced by addMode(), copyOptionParser(), and parseArgumentNormalUse().
|
private |
Vector of all the defined mode in the OptionParser.
Definition at line 78 of file OptionParser.h.
Referenced by addMode(), addOption(), checkArgument(), copyOptionParser(), getCurrentlyParsedMode(), getDefaultMode(), getLongOptionValue(), getMode(), getPossibleOption(), getSplitOptionValue(), initialisationOptionParser(), isModeExist(), parseArgumentBashCompletion(), parseArgumentNormalUse(), and print().