ISIS Core Library 0.7.2 (api 3.0.0)
|
The ISIS base application class. More...
#include <application.hpp>
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 |
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.
typedef void( Application::* isis::util::Application::setLogFunction)(LogLevel level) const [protected] |
Definition at line 55 of file application.hpp.
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()
name | name of the application. |
Definition at line 34 of file application.cpp.
isis::util::Application::~Application | ( | ) | [virtual] |
Definition at line 47 of file application.cpp.
void isis::util::Application::addExample | ( | std::string | parameters, |
std::string | desc | ||
) |
Add an example for the programs usage.
parameters | the parameter string for the example call |
desc | the description of the example |
Definition at line 71 of file application.cpp.
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".
name | the name used for the program parameters and their description |
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 "-".
argc | ammount of command line parameters in argv |
argv | array of const char[] containing the command line parameters |
exitOnError | if 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.
name | the parameter name without "-d" |
Definition at line 65 of file application.cpp.
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.
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.