![]() |
PhoenixMock
1.8.7
Tools to split/merge/print mock used in Phoenix
|
Parse the options passed to a program. More...
#include <OptionParser.h>
Public Member Functions | |
void | addMode (const std::string &modeName) |
Add a mode in the option. More... | |
template<typename T > | |
void | addOption (const std::string &longOption, const std::string &shortOption, const std::list< T > &defaultValue, const std::string &docString="") |
Add an option in the OptionParser. More... | |
template<typename T > | |
void | addOption (const std::string &longOption, const std::string &shortOption, const std::list< T > &defaultValue, OptionType::OptionType optionType, const std::string &docString="") |
Add an option in the OptionParser. More... | |
template<typename T > | |
void | addOption (const std::string &longOption, const std::string &shortOption, const std::vector< T > &defaultValue, const std::string &docString="") |
Add an option in the OptionParser. More... | |
template<typename T > | |
void | addOption (const std::string &longOption, const std::string &shortOption, const std::vector< T > &defaultValue, OptionType::OptionType optionType, const std::string &docString="") |
Add an option in the OptionParser. More... | |
template<typename T > | |
void | addOption (const std::string &longOption, const std::string &shortOption, const T defaultValue, const std::string &docString="") |
Add an option in the OptionParser. More... | |
template<typename T > | |
void | addOption (const std::string &longOption, const std::string &shortOption, const T defaultValue, OptionType::OptionType optionType, const std::string &docString="") |
Add an option in the OptionParser. More... | |
void | addOption (const std::string &longOption, const std::string &shortOption, OptionType::OptionType optionType, bool isRequired, bool isAllowEmpty, const std::string &docString) |
Add an option in the OptionParser. More... | |
void | addOption (const std::string &longOption, const std::string &shortOption, OptionType::OptionType optionType, bool isRequired, const std::string &docString) |
Add an option in the OptionParser. More... | |
void | closeMode () |
Close the current mode and go back to be default one. More... | |
OptionMode & | getDefaultMode () |
const OptionMode & | getDefaultMode () const |
Get default mode. More... | |
OptionMode & | getMode (const std::string &name) |
Get mode by name. More... | |
const OptionMode & | getMode (const std::string &name) const |
Get mode by name. More... | |
bool | isModeExist (const std::string &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 std::string &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 std::string &example) |
Set the example usage of the program. More... | |
void | setExampleShortOption (const std::string &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 (std::string &possibleValue, const std::string &cursorOption, const std::string &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 (std::string &valueToBeCompleted, const std::string &cursorOption) const |
Get the long option value to be completed. More... | |
OptionMode & | getParserMode (ArgParser &parser) |
Get a mode if it exist. More... | |
void | getPossibleOption (std::string &possibleOption, const std::string &cursorOption) const |
Get the possible options which can be used. More... | |
void | getPossibleOtherOption (std::string &possibleOption, const std::string &cursorOption) const |
Get the possible other options which can be used. More... | |
const Option * | getSplitOptionValue (std::string &valueToBeCompleted, const std::string &cursorOption, const std::string &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... | |
std::string | p_exempleLongOption |
Usage example with long options. More... | |
std::string | p_exempleShortOption |
Usage example with short options. More... | |
std::string | 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 std::string & | 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 16 of file OptionParser.cpp.
References initialisationOptionParser().
OptionParser::OptionParser | ( | const OptionParser & | other | ) |
Copy constructor of OptionParser.
other | : class to copy |
Definition at line 25 of file OptionParser.cpp.
References copyOptionParser().
|
virtual |
void OptionParser::addMode | ( | const std::string & | modeName | ) |
Add a mode in the option.
modeName | : name of the new mode to be added |
Definition at line 56 of file OptionParser.cpp.
References p_currentMode, p_enableHelpOption, p_programVersion, p_vecMode, OptionMode::setEnableHelpOption(), and OptionMode::setProgramVersion().
void OptionParser::addOption | ( | const std::string & | longOption, |
const std::string & | shortOption, | ||
const std::list< T > & | defaultValue, | ||
const std::string & | 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 75 of file OptionParser_impl.h.
References p_vecMode, OptionValue::setDefaultValue(), and OptionValue::setType().
void OptionParser::addOption | ( | const std::string & | longOption, |
const std::string & | shortOption, | ||
const std::list< T > & | defaultValue, | ||
OptionType::OptionType | optionType, | ||
const std::string & | 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 113 of file OptionParser_impl.h.
References p_vecMode, OptionValue::setDefaultValue(), and OptionValue::setType().
void OptionParser::addOption | ( | const std::string & | longOption, |
const std::string & | shortOption, | ||
const std::vector< T > & | defaultValue, | ||
const std::string & | 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 58 of file OptionParser_impl.h.
References p_vecMode, OptionValue::setDefaultValue(), and OptionValue::setType().
void OptionParser::addOption | ( | const std::string & | longOption, |
const std::string & | shortOption, | ||
const std::vector< T > & | defaultValue, | ||
OptionType::OptionType | optionType, | ||
const std::string & | 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 93 of file OptionParser_impl.h.
References p_vecMode, OptionValue::setDefaultValue(), and OptionValue::setType().
void OptionParser::addOption | ( | const std::string & | longOption, |
const std::string & | shortOption, | ||
const T | defaultValue, | ||
const std::string & | 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 std::string & | longOption, |
const std::string & | shortOption, | ||
const T | defaultValue, | ||
OptionType::OptionType | optionType, | ||
const std::string & | 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 std::string & | longOption, |
const std::string & | shortOption, | ||
OptionType::OptionType | optionType, | ||
bool | isRequired, | ||
bool | isAllowEmpty, | ||
const std::string & | 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 94 of file OptionParser.cpp.
References p_currentMode, p_vecMode, Option::setIsAllowEmpty(), and OptionValue::setType().
void OptionParser::addOption | ( | const std::string & | longOption, |
const std::string & | shortOption, | ||
OptionType::OptionType | optionType, | ||
bool | isRequired, | ||
const std::string & | 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 76 of file OptionParser.cpp.
References p_currentMode, p_vecMode, Option::setIsAllowEmpty(), and OptionValue::setType().
|
private |
Check the argument of the parser.
Definition at line 292 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 129 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 65 of file OptionParser.cpp.
References p_currentMode.
|
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 338 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 191 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 321 of file OptionParser.cpp.
References p_vecMode.
Referenced by getPossibleOption().
OptionMode& OptionParser::getDefaultMode | ( | ) |
OptionMode & OptionParser::getDefaultMode | ( | ) | const |
Get default mode.
Definition at line 137 of file OptionParser.cpp.
References p_vecMode.
Referenced by getMode().
|
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 359 of file OptionParser.cpp.
References isSameBegining(), and p_vecMode.
Referenced by completeOptionValue().
OptionMode & OptionParser::getMode | ( | const std::string & | name | ) |
Get mode by name.
name | : name of the mode to be returned |
Definition at line 165 of file OptionParser.cpp.
References getDefaultMode(), and p_vecMode.
const OptionMode & OptionParser::getMode | ( | const std::string & | name | ) | const |
Get mode by name.
name | : name of the mode to be returned |
Definition at line 152 of file OptionParser.cpp.
References getDefaultMode(), and p_vecMode.
Referenced by getParserMode().
|
private |
Get a mode if it exist.
parser | : parser to be used |
Definition at line 306 of file OptionParser.cpp.
References getMode(), isModeExist(), p_currentParserMode, and createReleaseCurl::parser.
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 416 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 435 of file OptionParser.cpp.
References 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 387 of file OptionParser.cpp.
References p_vecMode.
Referenced by completeOptionValue().
|
private |
Initialisation function of the class OptionParser.
Definition at line 201 of file OptionParser.cpp.
References p_currentMode, p_currentParserMode, and p_vecMode.
Referenced by OptionParser().
bool OptionParser::isModeExist | ( | const std::string & | name | ) | const |
Check if the given mode name does exist.
name | : name of the mode |
Definition at line 178 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 38 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 125 of file OptionParser.cpp.
References parseArgumentBashCompletion(), parseArgumentNormalUse(), and createReleaseCurl::parser.
|
private |
Bash completion argument parsing mode.
parser | : parser to be used |
Definition at line 244 of file OptionParser.cpp.
References completeOptionValue(), getPossibleOption(), getPossibleOtherOption(), p_vecMode, and createReleaseCurl::parser.
Referenced by parseArgument().
|
private |
Classical argument parsing mode.
parser | : parser to be used |
Definition at line 211 of file OptionParser.cpp.
References checkArgument(), OptionMode::getName(), getParserMode(), p_currentParserMode, p_enableHelpOption, p_programVersion, p_vecMode, OptionMode::parseOption(), createReleaseCurl::parser, and print().
Referenced by parseArgument().
void OptionParser::print | ( | ) | const |
Print all the options.
Definition at line 105 of file OptionParser.cpp.
References p_exempleLongOption, p_exempleShortOption, and p_vecMode.
Referenced by main(), and parseArgumentNormalUse().
void OptionParser::setExampleLongOption | ( | const std::string & | example | ) |
Set the example usage of the program.
example | : example of usage |
Definition at line 46 of file OptionParser.cpp.
References p_exempleLongOption.
void OptionParser::setExampleShortOption | ( | const std::string & | example | ) |
Set the example usage of the program.
example | : example of usage |
Definition at line 51 of file OptionParser.cpp.
References p_exempleShortOption.
|
private |
Index of the current mode in the OptionParser.
Definition at line 94 of file OptionParser.h.
Referenced by addMode(), addOption(), closeMode(), copyOptionParser(), and initialisationOptionParser().
|
private |
Current mode parsed.
Definition at line 90 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 100 of file OptionParser.h.
Referenced by addMode(), copyOptionParser(), and parseArgumentNormalUse().
|
private |
Usage example with long options.
Definition at line 96 of file OptionParser.h.
Referenced by copyOptionParser(), print(), and setExampleLongOption().
|
private |
Usage example with short options.
Definition at line 98 of file OptionParser.h.
Referenced by copyOptionParser(), print(), and setExampleShortOption().
|
private |
Program version to be printed on –version or -v option.
Definition at line 102 of file OptionParser.h.
Referenced by addMode(), copyOptionParser(), and parseArgumentNormalUse().
|
private |
Vector of all the defined mode in the OptionParser.
Definition at line 92 of file OptionParser.h.
Referenced by addMode(), addOption(), checkArgument(), copyOptionParser(), getCurrentlyParsedMode(), getDefaultMode(), getLongOptionValue(), getMode(), getPossibleOption(), getSplitOptionValue(), initialisationOptionParser(), isModeExist(), parseArgumentBashCompletion(), parseArgumentNormalUse(), and print().