ISIS Core Library 0.7.2 (api 3.0.0)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Types | Protected Member Functions | Protected Attributes

isis::util::Application Class Reference

The ISIS base application class. More...

#include <application.hpp>

Inheritance diagram for isis::util::Application:
isis::data::IOApplication

Public Member Functions

void addExample (std::string parameters, std::string desc)
 Add an example for the programs usage.
template<typename MODULE >
void addLogging (std::string name)
 Add a logging module.
 Application (const char name[])
 Default Constructor.
virtual bool init (int argc, char **argv, bool exitOnError=true)
 Initializes the programm parameter map using argc/argv.
virtual void printHelp (bool withHidden=false) const
 Virtual function to display a short help text.
void removeLogging (std::string name)
 Removes a logging parameter from the application.
template<typename MODULE >
void setLog (LogLevel level) const
 Set the logging level for the specified module.
virtual ~Application ()

Static Public Member Functions

static const std::string getCoreVersion (void)

Data Fields

ParameterMap parameters

Protected Types

typedef void(Application::* setLogFunction )(LogLevel level) const

Protected Member Functions

virtual boost::shared_ptr
< MessageHandlerBase
getLogHandler (std::string module, isis::LogLevel level) const

Protected Attributes

std::map< std::string,
std::list< setLogFunction > > 
logs

Detailed Description

The ISIS base application class.

To speed up the creation of new command line tools, the ISIS core library contains a number of helper classes based on Application. An ISIS application class provides a parameter parser that tokenizes the program argument list according to given parameter names and types and saves the results in an internal parameter map.

An application needs to be initialized explicitly with a call to init().

Usage instructions and a short paramter list can be shown with the method printHelp().

See also: isis::data::IOApplication, isis::util::ParameterMap and isis::LogLevel

Definition at line 47 of file application.hpp.


Member Typedef Documentation

typedef void( Application::* isis::util::Application::setLogFunction)(LogLevel level) const [protected]

Definition at line 55 of file application.hpp.


Constructor & Destructor Documentation

isis::util::Application::Application ( const char  name[])

Default Constructor.

Creates the application and its parameter map. No programm parameter is parsed here. To do that use init()

Parameters:
namename of the application.

Definition at line 34 of file application.cpp.

isis::util::Application::~Application ( ) [virtual]

Definition at line 47 of file application.cpp.


Member Function Documentation

void isis::util::Application::addExample ( std::string  parameters,
std::string  desc 
)

Add an example for the programs usage.

Parameters:
parametersthe parameter string for the example call
descthe description of the example

Definition at line 71 of file application.cpp.

template<typename MODULE >
void isis::util::Application::addLogging ( std::string  name) [inline]

Add a logging module.

This enables a logging module MODULE and adds related program parameters to control its logging level. This logging level then applies to LOG-commands using that specific module.

The MODULE must be a struct like

 struct MyLogModule {static const char *name() {return "MyModuleLog";}; enum {use = _ENABLE_LOG};}; 

than

 addLogging<MyLogModule>("MyLog"); 

will install a parameter "-dMyLog" which will control all calls to

 LOG(MyLogModule,...) << ... 

if _ENABLE_LOG was set for the compilation. Otherwise this commands will not have an effect.

Multiple MODLUES can have the same parameter name, so

 struct MyLogModule {static const char *name() {return "MyModuleLog";}; enum {use = _ENABLE_LOG};};
 struct MyDebugModule {static const char *name() {return "MyModuleDbg";}; enum {use = _ENABLE_DEBUG};};

 addLogging<MyLogModule>("MyLog");
 addLogging<MyDebugModule>("MyLog");

will control

 LOG(MyLogModule,...) << ... 

and

 LOG(MyDebugModule,...) << ... 

through the parameter "-dMyLog".

Parameters:
namethe name used for the program parameters and their description
Note:
This does not set the logging handler. That is done by reimplementing getLogHandler( std::string module, isis::LogLevel level )const.
If name is an empty string (""), its assumed as the logging for the application.

Definition at line 98 of file application.hpp.

const std::string isis::util::Application::getCoreVersion ( void  ) [static]

Definition at line 175 of file application.cpp.

boost::shared_ptr< MessageHandlerBase > isis::util::Application::getLogHandler ( std::string  module,
isis::LogLevel  level 
) const [protected, virtual]

Reimplemented in isis::data::IOApplication.

Definition at line 171 of file application.cpp.

bool isis::util::Application::init ( int  argc,
char **  argv,
bool  exitOnError = true 
) [virtual]

Initializes the programm parameter map using argc/argv.

For every entry in parameters an corresponding command line parameter is searched and parsed. A command line parameter corresponds to an entry of parameters if it string-equals caseless to this entry and is preceded by "-".

Parameters:
argcammount of command line parameters in argv
argvarray of const char[] containing the command line parameters
exitOnErrorif true the programm will exit, if there is a problem during the initialisation (like missing parameters).

Reimplemented in isis::data::IOApplication.

Definition at line 76 of file application.cpp.

void isis::util::Application::printHelp ( bool  withHidden = false) const [virtual]

Virtual function to display a short help text.

Ths usually shall print the programm name plus all entries of parameters with their description.

Reimplemented in isis::data::IOApplication.

Definition at line 123 of file application.cpp.

void isis::util::Application::removeLogging ( std::string  name)

Removes a logging parameter from the application.

Parameters:
namethe parameter name without "-d"
Note:
the logging module cannot be removed at runtime - its usage is controled by the _ENABLE_LOG / _ENABLE_DEBUG defines at compile time.

Definition at line 65 of file application.cpp.

template<typename MODULE >
void isis::util::Application::setLog ( LogLevel  level) const [inline]

Set the logging level for the specified module.

Definition at line 132 of file application.hpp.


Field Documentation

std::map<std::string, std::list<setLogFunction> > isis::util::Application::logs [protected]

Definition at line 56 of file application.hpp.

Definition at line 61 of file application.hpp.


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