#include <qgarlib/QgarArgs.H>
The class can be used alone, or coupled with class qgar::QgarApp which allows an application to be interactively used. See class qgar::QgarApp for further instructions.
The class allows a quick and easy definition of the different parameters accepted by an application.
A user can get help about an application parameters by launching the application with flag -h.
Flag -gui allows the QgarGui QGar user interface to be provided with the arguments of a given application.
Here is a minimal and typical example of use of the class for text-graphic separation:
#include <qgarlib/QgarApp.H> #include <qgarlib/QgarArgs.H> using namespace std; using namespace qgar; int main(int argc, char* argv[]) { QgarApp app; // INITIALIZATIONS // =============== // Description of the parameters app.addParameter("-in", QgarArgs::REQPARAM, QgarArgs::FILEIN, "Source image:"); app.addParameter("-t", QgarArgs::REQPARAM, QgarArgs::FILEOUTD, "Text image:", ".text.pbm"); app.addParameter("-g", QgarArgs::REQPARAM, QgarArgs::FILEOUTD, "Graphic image:", ".graph.pbm"); app.addParameter("-s", QgarArgs::REQPARAM, QgarArgs::INT, "Dimension threshold:", 0, "20"); app.addParameter("-thr", QgarArgs::OPTPARAM, QgarArgs::INT, "Threshold:", 0, "3"); app.addParameter("-d", QgarArgs::REQPARAM, QgarArgs::FLOAT, "Black pixel density:", 0, ".6"); // Description of the application app.setDescription("Text-graphic separation", QgarArgs::PBM); // COMMAND LINE ANALYSIS // ===================== app.analyzeLine(argc, argv); // Error while parsing parameters? if (app.isError()) { return app._CODE_ERROR; } // Application invoked with flag '-gui'? if (app.isExit()) { return app._CODE_GUI; } // Set progress bar on app.showProgressBar(); app.setProgressBar(0); // GET ARGUMENTS // ============= // Get the value of parameter introduced by flag '-in' // (it must be given, as this parameter is required) const char* name = app.getStringOption("-in"); // Get the threshold value if defined by the command line int threshold = 3; if (app.isOptionSet("-thr")) { threshold = atoi(app.getStringOption("-thr")); } app.setProgressBar(5); // AND SO ON... // ============ ... // NORMAL TERMINATION // ================== return app._CODE_END; } // END main()
Definition at line 202 of file QgarArgs.H.
Public Types | |
Type definitions | |
| enum | QGEparamStatus { SINGLEFLAG, REQPARAM, OPTPARAM, REQMULTIPARAM, OPTMULTIPARAM } |
| Parameter status. More... | |
| enum | QGEparamType { INT, FLOAT, STRING, BOOL, FILEIN, FILEOUT, FILEOUTD, FILEOUTDS, PATH } |
| Types of the values associated to parameters. More... | |
| enum | QGEfileType { PPM, PGM, PBM, DXF } |
| File formats. More... | |
Public Member Functions | |
Constructors | |
| QgarArgs () | |
| Default constructor. | |
Destructor | |
| ~QgarArgs () | |
| Non-virtual destructor. | |
Command line | |
| void | analyzeLine (int argc, char *argv[]) |
| Analyze the command line. | |
Predicates | |
| bool | isOptionSet (const char *aFlag) const |
| Is given flag set? | |
| bool | isExit () const |
| Does the client have to exit the application? | |
| bool | isError () const |
| Is there an error in the command line? | |
| bool | isInteractive () const |
| Is the application in interactive mode? | |
Access | |
| const char * | getStringOption (const char *aFlag, bool aSpecial) const |
| Get the string associated with a parameter. | |
| int | getNumberOptions (const char *aFlag) const |
| Get the number of strings (representing values) associated with a multi-valued parameter. | |
| const char * | getStringOptionMulti (const char *aFlag, int anIdx) const |
| Get string index associated with a multi-valued parameter. | |
| QgarParam * | findParam (const char *aParam) const |
| Get the parameter description (null pointer if none). | |
Transformation | |
| void | setDescription (const char *aDescription, QGEfileType aFileType) |
| Declare global information about the parameter. | |
| void | addParameter (const char *aParamName, QGEparamStatus aParamStatus, QGEparamType aParamType, const char *aDescription, const char *anExtension=0, const char *aDefault=0) |
| Declare a parameter. | |
| void | setNumberOfMessages (int aCnt) |
| Declare the number of messages which will be displayed during the execution of the corresponding application. | |
| void | setParamValue (char *aFlag, char *aVal) |
| Set the parameter value. | |
Protected Member Functions | |
Display | |
| void | printGUI () const |
| Dispaly parameters. | |
| void | showUsage (const char *aCommand) const |
| Display usage message. | |
Protected Attributes | |
Application features | |
| std::list< QgarParam * > | _args |
| Application parameters. | |
| QGEfileType | _fileType |
| File type. | |
| char * | _description |
| Application description. | |
| bool | _exit |
| Exit/do not exit the application. | |
| bool | _error |
| Error/no error in the command line. | |
| bool | _interactive |
| Interactive/non-interactive application. | |
Classes | |
| class | QgarParam |
| Internal representation of an application parameter. More... | |
|
|
File formats.
Definition at line 272 of file QgarArgs.H. |
|
|
Parameter status.
Definition at line 226 of file QgarArgs.H. |
|
|
Types of the values associated to parameters.
Definition at line 251 of file QgarArgs.H. |
|
|
Default constructor.
Definition at line 266 of file QgarArgs.C. |
|
|
Non-virtual destructor.
Definition at line 283 of file QgarArgs.C. References _args, and _description. |
|
||||||||||||||||||||||||||||
|
Declare a parameter. This method must be called for each supported parameter. If the parameter is an output file, its name is the concatenation of the name of the input file (without its extension) and of argument anExtension. If the parameter is not an output file, its default value may be given by argument aDefault. If the parameter status is qgar::QgarArgs::SINGLEFLAG, the corresponding type must be qgar::QgarArgs::BOOL.
Definition at line 640 of file QgarArgs.C. References _args. Referenced by qgar::QgarApp::addParameter(). |
|
||||||||||||
|
Analyze the command line.
Definition at line 307 of file QgarArgs.C. References _args, _error, _exit, _interactive, qgar::QgarArgs::QgarParam::addArgument(), findParam(), OPTMULTIPARAM, OPTPARAM, qgar::QgarArgs::QgarParam::paramStatus(), printGUI(), REQMULTIPARAM, REQPARAM, qgar::QgarArgs::QgarParam::setUseFlag(), qgar::QgarArgs::QgarParam::setValue(), showUsage(), and SINGLEFLAG. Referenced by qgar::QgarApp::analyzeLine(). |
|
|
Get the parameter description (null pointer if none).
Definition at line 601 of file QgarArgs.C. References _args. Referenced by analyzeLine(), getNumberOptions(), getStringOption(), getStringOptionMulti(), isOptionSet(), qgar::QgarApp::newValue(), setParamValue(), and qgar::QgarApp::showDialog(). |
|
|
Get the number of strings (representing values) associated with a multi-valued parameter.
Definition at line 530 of file QgarArgs.C. References findParam(), qgar::QgarArgs::QgarParam::numbOptions(), OPTMULTIPARAM, qgar::QgarArgs::QgarParam::paramStatus(), and REQMULTIPARAM. |
|
||||||||||||
|
Get the string associated with a parameter.
Definition at line 496 of file QgarArgs.C. References findParam(), OPTPARAM, qgar::QgarArgs::QgarParam::paramStatus(), REQPARAM, and qgar::QgarArgs::QgarParam::value(). Referenced by qgar::QgarApp::getStringOption(). |
|
||||||||||||
|
Get string index associated with a multi-valued parameter.
Definition at line 564 of file QgarArgs.C. References qgar::QgarArgs::QgarParam::argument(), findParam(), qgar::QgarArgs::QgarParam::numbOptions(), OPTMULTIPARAM, qgar::QgarArgs::QgarParam::paramStatus(), and REQMULTIPARAM. |
|
|
Is there an error in the command line?
Definition at line 904 of file QgarArgs.H. References _error. Referenced by qgar::QgarApp::isError(). |
|
|
Does the client have to exit the application? The client has to exit if the application has been launched with either a -h flag (help) or a -gui flag (get application parameters). Definition at line 895 of file QgarArgs.H. References _exit. Referenced by qgar::QgarApp::isExit(). |
|
|
Is the application in interactive mode?
Definition at line 913 of file QgarArgs.H. References _interactive. Referenced by qgar::QgarApp::isInteractive(). |
|
|
Is given flag set?
Definition at line 455 of file QgarArgs.C. References findParam(), OPTMULTIPARAM, OPTPARAM, qgar::QgarArgs::QgarParam::paramStatus(), SINGLEFLAG, and qgar::QgarArgs::QgarParam::useFlag(). Referenced by qgar::QgarApp::isOptionSet(). |
|
|
Dispaly parameters.
Definition at line 688 of file QgarArgs.C. References _args, _description, _fileType, DXF, PBM, PGM, and PPM. Referenced by analyzeLine(). |
|
||||||||||||
|
Declare global information about the parameter.
Definition at line 627 of file QgarArgs.C. References _description, and _fileType. Referenced by qgar::QgarApp::setDescription(). |
|
|
Declare the number of messages which will be displayed during the execution of the corresponding application.
Definition at line 927 of file QgarArgs.H. |
|
||||||||||||
|
Set the parameter value.
Definition at line 659 of file QgarArgs.C. References findParam(), and qgar::QgarArgs::QgarParam::setNewValue(). Referenced by qgar::QgarApp::setValue(). |
|
|
Display usage message.
Definition at line 733 of file QgarArgs.C. References _args, and _description. Referenced by analyzeLine(). |
|
|
Application parameters.
Definition at line 703 of file QgarArgs.H. Referenced by addParameter(), analyzeLine(), findParam(), printGUI(), showUsage(), and ~QgarArgs(). |
|
|
Application description.
Definition at line 713 of file QgarArgs.H. Referenced by printGUI(), setDescription(), showUsage(), and ~QgarArgs(). |
|
|
Error/no error in the command line.
Definition at line 723 of file QgarArgs.H. Referenced by analyzeLine(), and isError(). |
|
|
Exit/do not exit the application.
Definition at line 718 of file QgarArgs.H. Referenced by analyzeLine(), and isExit(). |
|
|
File type.
Definition at line 708 of file QgarArgs.H. Referenced by printGUI(), and setDescription(). |
|
|
Interactive/non-interactive application.
Definition at line 728 of file QgarArgs.H. Referenced by analyzeLine(), and isInteractive(). |