Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qgar::QgarApp Class Reference
[Application coding]

#include <qgarlib/QgarApp.H>

List of all members.


Detailed Description

To handle parameters and interactive mode of an application.

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()

Todo:
Complete and update documentation
Author:
Yvan Norsa
Date:
July 25, 2002 12:52
Since:
Qgar 1.0

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.


Member Enumeration Documentation

enum qgar::QgarApp::QGEaction [protected]
 

Action types.

Enumerator:
QGE_ACTION_NONE 
QGE_ACTION_SET 

Definition at line 441 of file QgarApp.H.


Constructor & Destructor Documentation

qgar::QgarApp::QgarApp  ) 
 

Default constructor.

Definition at line 86 of file QgarApp.C.

qgar::QgarApp::~QgarApp  )  [virtual]
 

Virtual destructor.

Definition at line 104 of file QgarApp.C.


Member Function Documentation

void qgar::QgarApp::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.

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.

Parameters:
aParamName parameter name, first character is a minus (e.g. -f)
aParamStatus parameter status (see enum type qgar::QgarArgs::ParamStatus)
aParamType parameter type (see enum type qgar::QgarArgs::ParamType)
aDescription short description of the parameter
anExtension file extension, in case of an output file
aDefault default value (given as a string) for a parameter which is not a file
See also:
class qgar::QgarArgs

Definition at line 260 of file QgarApp.C.

References _args, _paramNameTab, qgar::QgarArgs::addParameter(), qgar::QgarArgs::BOOL, and qgar::QgarArgs::INT.

void qgar::QgarApp::analyzeLine int  argc,
char *  argv[]
[inline]
 

Analyze the command line.

Parameters:
argc number of arguments
argv the full command line

Definition at line 562 of file QgarApp.H.

References _args, and qgar::QgarArgs::analyzeLine().

void qgar::QgarApp::closeProgressBar  )  [inline]
 

Close the progress bar.

Definition at line 617 of file QgarApp.H.

bool qgar::QgarApp::exit  )  const [inline]
 

Does the application have to exit?

Definition at line 548 of file QgarApp.H.

References _exit.

const char * qgar::QgarApp::getStringOption const char *  aFlag  ) 
 

Get the string associated with a parameter.

Parameters:
aFlag flag introducing the parameter
Warning:
If the parameter is optional, check first that the parameter is set, using function qgar::QgarApp::isOptionSet.

Definition at line 284 of file QgarApp.C.

References _action, _actionCnt, _args, qgar::QgarArgs::getStringOption(), QGE_ACTION_NONE, and QGE_ACTION_SET.

bool qgar::QgarApp::isError  )  const [inline]
 

Is there an error in the command line?

Definition at line 571 of file QgarApp.H.

References _args, and qgar::QgarArgs::isError().

bool qgar::QgarApp::isExit  )  const [inline]
 

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().

bool qgar::QgarApp::isInteractive  )  const [inline]
 

Is the application in interactive mode?

Definition at line 539 of file QgarApp.H.

References _args, and qgar::QgarArgs::isInteractive().

bool qgar::QgarApp::isOptionSet const char *  aFlag  )  const [inline]
 

Is an optional parameter set?

Parameters:
aFlag flag introducing the parameter

Definition at line 585 of file QgarApp.H.

References _args, and qgar::QgarArgs::isOptionSet().

bool qgar::QgarApp::newValue const char *  aName  ) 
 

Has a SET *name* *value* command been read?

Parameters:
aName 

Definition at line 233 of file QgarApp.C.

References _action, _args, qgar::QgarArgs::findParam(), qgar::QgarArgs::QgarParam::newValue(), and QGE_ACTION_SET.

void qgar::QgarApp::nextCommand  ) 
 

Read on standard input.

Definition at line 154 of file QgarApp.C.

References _action, _actionCnt, _exit, _paramNameTab, _value, nextWord(), QGE_ACTION_SET, and setValue().

char * qgar::QgarApp::nextWord char *  aComLine,
int *  anIdx
 

Get next word of command line (blank space as separator).

Parameters:
aComLine number of arguments
anIdx current index in line

Definition at line 118 of file QgarApp.C.

Referenced by nextCommand().

void qgar::QgarApp::setDescription const char *  aDescription,
QgarArgs::QGEfileType  aFileType
[inline]
 

Set application description.

Parameters:
aDescription application description
aFileType type of the source file

Definition at line 521 of file QgarApp.H.

References _args, and qgar::QgarArgs::setDescription().

void qgar::QgarApp::setProgressBar int  aPercentage  )  [inline]
 

Set progress bar to a given percentage.

Parameters:
aPercentage value between 0 and 100

Definition at line 626 of file QgarApp.H.

void qgar::QgarApp::setValue char *  aFlag,
char *  aVal
[inline]
 

Set a parameter value.

Parameters:
aFlag flag introducing the parameter
aVal value to assign

Definition at line 594 of file QgarApp.H.

References _args, and qgar::QgarArgs::setParamValue().

Referenced by nextCommand().

void qgar::QgarApp::showDialog  ) 
 

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().

void qgar::QgarApp::showPicture char *  aFileName  )  [inline]
 

Display an image.

Parameters:
aFileName name of the file including the image to be displayed

Definition at line 635 of file QgarApp.H.

void qgar::QgarApp::showProgressBar  )  [inline]
 

Display the progress bar.

Definition at line 608 of file QgarApp.H.

void qgar::QgarApp::showSuperImpose char *  aFileName  )  [inline]
 

Display the superimpose file.

Parameters:
aFileName a file name

Definition at line 644 of file QgarApp.H.


Member Data Documentation

QGEaction qgar::QgarApp::_action [protected]
 

Nature of the current command.

Definition at line 486 of file QgarApp.H.

Referenced by getStringOption(), newValue(), and nextCommand().

int qgar::QgarApp::_actionCnt [protected]
 

Current number of processed actions.

Definition at line 496 of file QgarApp.H.

Referenced by getStringOption(), and nextCommand().

QgarArgs qgar::QgarApp::_args [protected]
 

Application arguments.

Definition at line 469 of file QgarApp.H.

Referenced by addParameter(), analyzeLine(), getStringOption(), isError(), isExit(), isInteractive(), isOptionSet(), newValue(), setDescription(), setValue(), and showDialog().

const unsigned char qgar::QgarApp::_CODE_END = 100 [static]
 

Value to be returned by an application which normally terminates.

Definition at line 64 of file QgarApp.C.

const unsigned char qgar::QgarApp::_CODE_ERROR = 200 [static]
 

Value to be returned by an application which abnormally terminates.

Definition at line 76 of file QgarApp.C.

const unsigned char qgar::QgarApp::_CODE_GUI = 101 [static]
 

Value to be returned by an application invoked with flag -gui.

Definition at line 70 of file QgarApp.C.

bool qgar::QgarApp::_exit [protected]
 

Flag set if the application is about to end.

Definition at line 474 of file QgarApp.H.

Referenced by exit(), and nextCommand().

std::list<std::string> qgar::QgarApp::_paramNameTab [protected]
 

Table of parameter names.

Definition at line 457 of file QgarApp.H.

Referenced by addParameter(), nextCommand(), and showDialog().

char* qgar::QgarApp::_value [protected]
 

Parameter of the current command.

Definition at line 491 of file QgarApp.H.

Referenced by nextCommand().


The documentation for this class was generated from the following files: