#include <qgarlib/QgarApp.H>
It is based on class qgar::QgarArgs.
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 179 of file QgarApp.H.
Public Member Functions | |
Constructors | |
| QgarApp () | |
| Default constructor. | |
Destructor | |
| virtual | ~QgarApp () |
| Virtual destructor. | |
The application | |
| void | setDescription (const char *aDescription, QgarArgs::QGEfileType aFileType) |
| Set application description. | |
| bool | isExit () const |
| Does the client have to exit the application? | |
| bool | isInteractive () const |
| Is the application in interactive mode? | |
| bool | exit () const |
| Does the application have to exit? | |
The command line | |
| void | analyzeLine (int argc, char *argv[]) |
| Analyze the command line. | |
| char * | nextWord (char *aComLine, int *anIdx) |
| Get next word of command line (blank space as separator). | |
| bool | isError () const |
| Is there an error in the command line? | |
Input | |
| void | nextCommand () |
| Read on standard input. | |
| bool | newValue (const char *aName) |
| Has a SET *name* *value* command been read? | |
The parameters | |
| void | addParameter (const char *aParamName, QgarArgs::QGEparamStatus aParamStatus, QgarArgs::QGEparamType aParamType, const char *aDescription, const char *anExtension=0, const char *aDefault=0) |
| Declare a parameter supported by an application. | |
| bool | isOptionSet (const char *aFlag) const |
| Is an optional parameter set? | |
| const char * | getStringOption (const char *aFlag) |
| Get the string associated with a parameter. | |
| void | setValue (char *aFlag, char *aVal) |
| Set a parameter value. | |
The progress bar | |
| void | showProgressBar () |
| Display the progress bar. | |
| void | closeProgressBar () |
| Close the progress bar. | |
| void | setProgressBar (int aPercentage) |
| Set progress bar to a given percentage. | |
The dialog with the QgarGui user interface | |
| void | showPicture (char *aFileName) |
| Display an image. | |
| void | showSuperImpose (char *aFileName) |
| Display the superimpose file. | |
| void | showDialog () |
| Display a dialog to change parameter values. | |
Static Public Attributes | |
Termination codes | |
| static const unsigned char | _CODE_END = 100 |
| Value to be returned by an application which normally terminates. | |
| static const unsigned char | _CODE_GUI = 101 |
| Value to be returned by an application invoked with flag -gui. | |
| static const unsigned char | _CODE_ERROR = 200 |
| Value to be returned by an application which abnormally terminates. | |
Protected Types | |
Type definitions | |
| enum | QGEaction { QGE_ACTION_NONE, QGE_ACTION_SET } |
| Action types. More... | |
Protected Attributes | |
Information about parameters | |
| std::list< std::string > | _paramNameTab |
| Table of parameter names. | |
Information about the application | |
| QgarArgs | _args |
| Application arguments. | |
| bool | _exit |
| Flag set if the application is about to end. | |
Information about actions | |
| QGEaction | _action |
| Nature of the current command. | |
| char * | _value |
| Parameter of the current command. | |
| int | _actionCnt |
| Current number of processed actions. | |
|
|
Action types.
|
|
|
Default constructor.
|
|
|
Virtual destructor.
|
|
||||||||||||||||||||||||||||
|
Declare a parameter supported by an application. This method must be called for each supported parameter. If a 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 a 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 260 of file QgarApp.C. References _args, _paramNameTab, qgar::QgarArgs::addParameter(), qgar::QgarArgs::BOOL, and qgar::QgarArgs::INT. |
|
||||||||||||
|
Analyze the command line.
Definition at line 562 of file QgarApp.H. References _args, and qgar::QgarArgs::analyzeLine(). |
|
|
Close the progress bar.
|
|
|
Does the application have to exit?
Definition at line 548 of file QgarApp.H. References _exit. |
|
|
Get the string associated with a parameter.
Definition at line 284 of file QgarApp.C. References _action, _actionCnt, _args, qgar::QgarArgs::getStringOption(), QGE_ACTION_NONE, and QGE_ACTION_SET. |
|
|
Is there an error in the command line?
Definition at line 571 of file QgarApp.H. References _args, and qgar::QgarArgs::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 531 of file QgarApp.H. References _args, and qgar::QgarArgs::isExit(). |
|
|
Is the application in interactive mode?
Definition at line 539 of file QgarApp.H. References _args, and qgar::QgarArgs::isInteractive(). |
|
|
Is an optional parameter set?
Definition at line 585 of file QgarApp.H. References _args, and qgar::QgarArgs::isOptionSet(). |
|
|
Has a SET *name* *value* command been read?
Definition at line 233 of file QgarApp.C. References _action, _args, qgar::QgarArgs::findParam(), qgar::QgarArgs::QgarParam::newValue(), and QGE_ACTION_SET. |
|
|
Read on standard input.
Definition at line 154 of file QgarApp.C. References _action, _actionCnt, _exit, _paramNameTab, _value, nextWord(), QGE_ACTION_SET, and setValue(). |
|
||||||||||||
|
Get next word of command line (blank space as separator).
Definition at line 118 of file QgarApp.C. Referenced by nextCommand(). |
|
||||||||||||
|
Set application description.
Definition at line 521 of file QgarApp.H. References _args, and qgar::QgarArgs::setDescription(). |
|
|
Set progress bar to a given percentage.
|
|
||||||||||||
|
Set a parameter value.
Definition at line 594 of file QgarApp.H. References _args, and qgar::QgarArgs::setParamValue(). Referenced by nextCommand(). |
|
|
Display a dialog to change parameter values.
Definition at line 339 of file QgarApp.C. References _args, _paramNameTab, qgar::QgarArgs::findParam(), and qgar::QgarArgs::QgarParam::printGUI(). |
|
|
Display an image.
|
|
|
Display the progress bar.
|
|
|
Display the superimpose file.
|
|
|
Nature of the current command.
Definition at line 486 of file QgarApp.H. Referenced by getStringOption(), newValue(), and nextCommand(). |
|
|
Current number of processed actions.
Definition at line 496 of file QgarApp.H. Referenced by getStringOption(), and nextCommand(). |
|
|
Application arguments.
Definition at line 469 of file QgarApp.H. Referenced by addParameter(), analyzeLine(), getStringOption(), isError(), isExit(), isInteractive(), isOptionSet(), newValue(), setDescription(), setValue(), and showDialog(). |
|
|
Value to be returned by an application which normally terminates.
|
|
|
Value to be returned by an application which abnormally terminates.
|
|
|
Value to be returned by an application invoked with flag -gui.
|
|
|
Flag set if the application is about to end.
Definition at line 474 of file QgarApp.H. Referenced by exit(), and nextCommand(). |
|
|
Table of parameter names.
Definition at line 457 of file QgarApp.H. Referenced by addParameter(), nextCommand(), and showDialog(). |
|
|
Parameter of the current command.
Definition at line 491 of file QgarApp.H. Referenced by nextCommand(). |