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

qgar::QgarArgs Class Reference
[Application coding]

#include <qgarlib/QgarArgs.H>

List of all members.


Detailed Description

To handle the parameters given to an application.

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

Author:
Philippe Dosch
Date:
July 02, 2001 17:20
Since:
Qgar 1.0

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


Member Enumeration Documentation

enum qgar::QgarArgs::QGEfileType
 

File formats.

  • PPM: color bitmap image
  • PGM: grey-level bitmap image
  • PBM: black and white bitmap image
  • DXF: vectorial image
Enumerator:
PPM 
PGM 
PBM 
DXF 

Definition at line 272 of file QgarArgs.H.

enum qgar::QgarArgs::QGEparamStatus
 

Parameter status.

  • SINGLEFLAG: single flag, associated with no value (-f)
  • REQPARAM: required (i.e. non-optional) parameter, introducing a value (-f *val*)
  • OPTPARAM: optional parameter, introducing a value (-f *val*)
  • REQMULTIPARAM: required parameter, introducing several values (-f *val1* .. *valN*)
  • OPTMULTIPARAM: optional parameter, introducing several values (-f *val1* .. *valN*)
Enumerator:
SINGLEFLAG 
REQPARAM 
OPTPARAM 
REQMULTIPARAM 
OPTMULTIPARAM 

Definition at line 226 of file QgarArgs.H.

enum qgar::QgarArgs::QGEparamType
 

Types of the values associated to parameters.

  • INT: integer number
  • FLOAT: floating number
  • STRING: string
  • BOOL: boolean
  • FILEIN: name of an input data file
  • FILEOUT: name of an output data file
  • FILEOUTD: name of an output data file, whose content is intended to be displayed
  • FILEOUTDS: name of an output data file, whose content is intended to be displayed in superimposition mode
  • PATH: path of a directory
Enumerator:
INT 
FLOAT 
STRING 
BOOL 
FILEIN 
FILEOUT 
FILEOUTD 
FILEOUTDS 
PATH 

Definition at line 251 of file QgarArgs.H.


Constructor & Destructor Documentation

qgar::QgarArgs::QgarArgs  ) 
 

Default constructor.

Definition at line 266 of file QgarArgs.C.

qgar::QgarArgs::~QgarArgs  ) 
 

Non-virtual destructor.

Definition at line 283 of file QgarArgs.C.

References _args, and _description.


Member Function Documentation

void qgar::QgarArgs::addParameter const char *  aParamName,
QGEparamStatus  aParamStatus,
QGEparamType  aParamType,
const char *  aDescription,
const char *  anExtension = 0,
const char *  aDefault = 0
 

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.

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

Definition at line 640 of file QgarArgs.C.

References _args.

Referenced by qgar::QgarApp::addParameter().

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

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

QgarArgs::QgarParam * qgar::QgarArgs::findParam const char *  aParam  )  const
 

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

int qgar::QgarArgs::getNumberOptions const char *  aFlag  )  const
 

Get the number of strings (representing values) associated with a multi-valued parameter.

Parameters:
aFlag flag introducing the parameter

Definition at line 530 of file QgarArgs.C.

References findParam(), qgar::QgarArgs::QgarParam::numbOptions(), OPTMULTIPARAM, qgar::QgarArgs::QgarParam::paramStatus(), and REQMULTIPARAM.

const char * qgar::QgarArgs::getStringOption const char *  aFlag,
bool  aSpecial
const
 

Get the string associated with a parameter.

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

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

const char * qgar::QgarArgs::getStringOptionMulti const char *  aFlag,
int  anIdx
const
 

Get string index associated with a multi-valued parameter.

Parameters:
aFlag flag introducing the parameter
anIdx index

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.

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

Is there an error in the command line?

Definition at line 904 of file QgarArgs.H.

References _error.

Referenced by qgar::QgarApp::isError().

bool qgar::QgarArgs::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 895 of file QgarArgs.H.

References _exit.

Referenced by qgar::QgarApp::isExit().

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

Is the application in interactive mode?

Definition at line 913 of file QgarArgs.H.

References _interactive.

Referenced by qgar::QgarApp::isInteractive().

bool qgar::QgarArgs::isOptionSet const char *  aFlag  )  const
 

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

void qgar::QgarArgs::printGUI  )  const [protected]
 

Dispaly parameters.

Definition at line 688 of file QgarArgs.C.

References _args, _description, _fileType, DXF, PBM, PGM, and PPM.

Referenced by analyzeLine().

void qgar::QgarArgs::setDescription const char *  aDescription,
QGEfileType  aFileType
 

Declare global information about the parameter.

Definition at line 627 of file QgarArgs.C.

References _description, and _fileType.

Referenced by qgar::QgarApp::setDescription().

void qgar::QgarArgs::setNumberOfMessages int  aCnt  )  [inline]
 

Declare the number of messages which will be displayed during the execution of the corresponding application.

Warning:
This function must be called before displaying the first message, to allow the progress bar to be correctly managed.

Definition at line 927 of file QgarArgs.H.

void qgar::QgarArgs::setParamValue char *  aFlag,
char *  aVal
 

Set the parameter value.

Parameters:
aFlag flag introducing the parameter
aVal value to assign

Definition at line 659 of file QgarArgs.C.

References findParam(), and qgar::QgarArgs::QgarParam::setNewValue().

Referenced by qgar::QgarApp::setValue().

void qgar::QgarArgs::showUsage const char *  aCommand  )  const [protected]
 

Display usage message.

Parameters:
aCommand 

Definition at line 733 of file QgarArgs.C.

References _args, and _description.

Referenced by analyzeLine().


Member Data Documentation

std::list<QgarParam*> qgar::QgarArgs::_args [protected]
 

Application parameters.

Definition at line 703 of file QgarArgs.H.

Referenced by addParameter(), analyzeLine(), findParam(), printGUI(), showUsage(), and ~QgarArgs().

char* qgar::QgarArgs::_description [protected]
 

Application description.

Definition at line 713 of file QgarArgs.H.

Referenced by printGUI(), setDescription(), showUsage(), and ~QgarArgs().

bool qgar::QgarArgs::_error [protected]
 

Error/no error in the command line.

Definition at line 723 of file QgarArgs.H.

Referenced by analyzeLine(), and isError().

bool qgar::QgarArgs::_exit [protected]
 

Exit/do not exit the application.

Definition at line 718 of file QgarArgs.H.

Referenced by analyzeLine(), and isExit().

QGEfileType qgar::QgarArgs::_fileType [protected]
 

File type.

Definition at line 708 of file QgarArgs.H.

Referenced by printGUI(), and setDescription().

bool qgar::QgarArgs::_interactive [protected]
 

Interactive/non-interactive application.

Definition at line 728 of file QgarArgs.H.

Referenced by analyzeLine(), and isInteractive().


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