#include <application.h>
Public Types | |
typedef std::pair< const char *, unsigned > | HelpOpt |
Description of and max value for help option. | |
Public Member Functions | |
Basic functions. | |
virtual const char * | getName () const =0 |
Returns the name of this application. | |
virtual const char * | getVersion () const =0 |
Returns the version number of this application. | |
virtual const int * | getSignals () const |
Returns a null-terminated array of signals that this application handles. | |
virtual const char * | getUsage () const |
Returns the usage information of this application. | |
virtual HelpOpt | getHelpOption () const |
Returns the application's help option and its description. | |
virtual PosOption | getPositional () const |
Returns the parser function for handling positional options. | |
virtual void | error (const char *msg) const |
Prints the given error message to stderr. | |
virtual void | info (const char *msg) const |
Prints the given info message to stderr. | |
virtual void | warn (const char *msg) const |
Prints the given warning message to stderr. | |
Protected Member Functions | |
Application () | |
int | blockSignals () |
void | exit (int exitCode) const |
void | killAlarm () |
void | processSignal (int sigNum) |
void | setVerbose (unsigned v) |
void | shutdown (bool hasError) |
void | unblockSignals (bool deliverPending) |
unsigned | verbose () const |
virtual | ~Application () |
Life cycle and option handling | |
virtual void | initOptions (OptionContext &root)=0 |
Adds all application options to the given context. | |
virtual void | validateOptions (const OptionContext &root, const ParsedOptions &parsed, const ParsedValues &values)=0 |
Validates parsed options. Shall throw to signal error. | |
virtual void | setup ()=0 |
Called once after option processing is done. | |
virtual void | run ()=0 |
Shall run the application. Called after setup and option processing. | |
virtual void | shutdown () |
Called after run returned. The default is a noop. | |
virtual void | onUnhandledException () |
Called on an exception from run(). The default terminates the application. | |
virtual bool | onSignal (int) |
Called when a signal is received. Tthe default terminates the application. | |
Private Member Functions | |
bool | getOptions (int argc, char **argv) |
Static Private Member Functions | |
static void | sigHandler (int sig) |
Private Attributes | |
volatile sig_atomic_t | blocked_ |
int | exitCode_ |
bool | fastExit_ |
volatile sig_atomic_t | pending_ |
unsigned | timeout_ |
unsigned | verbose_ |
Static Private Attributes | |
static Application * | instance_s = 0 |
Main functions. | |
int | main (int argc, char **argv) |
Runs this application with the given command-line arguments. | |
void | setExitCode (int n) |
Sets the value that should be returned as the application's exit code. | |
int | getExitCode () const |
Returns the application's exit code. | |
virtual void | printHelp (const OptionContext &root) |
Prints the application's help information (called if options contain '--help'). | |
virtual void | printVersion () |
Prints the application's version message (called if options contain '--version'). | |
virtual void | printUsage () |
Prints the application's usage message (default is: "usage: getName() getUsage()"). | |
static Application * | getInstance () |
Returns the application object that is running. |
Definition at line 42 of file application.h.
typedef std::pair<const char*, unsigned> ProgramOptions::Application::HelpOpt |
Description of and max value for help option.
Definition at line 45 of file application.h.
ProgramOptions::Application::Application | ( | ) | [protected] |
Definition at line 44 of file application.cpp.
ProgramOptions::Application::~Application | ( | ) | [protected, virtual] |
Definition at line 45 of file application.cpp.
int ProgramOptions::Application::blockSignals | ( | ) | [protected] |
Definition at line 113 of file application.cpp.
virtual void ProgramOptions::Application::error | ( | const char * | msg | ) | const [inline, virtual] |
Prints the given error message to stderr.
Definition at line 63 of file application.h.
void ProgramOptions::Application::exit | ( | int | exitCode | ) | const [protected] |
Definition at line 106 of file application.cpp.
int ProgramOptions::Application::getExitCode | ( | ) | const |
Returns the application's exit code.
Definition at line 90 of file application.cpp.
virtual HelpOpt ProgramOptions::Application::getHelpOption | ( | ) | const [inline, virtual] |
Returns the application's help option and its description.
Reimplemented in Clasp::Cli::ClaspAppBase.
Definition at line 59 of file application.h.
Application * ProgramOptions::Application::getInstance | ( | ) | [static] |
Returns the application object that is running.
Definition at line 75 of file application.cpp.
virtual const char* ProgramOptions::Application::getName | ( | ) | const [pure virtual] |
Returns the name of this application.
Implemented in Clasp::Cli::ClaspApp.
bool ProgramOptions::Application::getOptions | ( | int | argc, |
char ** | argv | ||
) | [private] |
Definition at line 180 of file application.cpp.
virtual PosOption ProgramOptions::Application::getPositional | ( | ) | const [inline, virtual] |
Returns the parser function for handling positional options.
Reimplemented in Clasp::Cli::ClaspAppBase.
Definition at line 61 of file application.h.
virtual const int* ProgramOptions::Application::getSignals | ( | ) | const [inline, virtual] |
Returns a null-terminated array of signals that this application handles.
Reimplemented in Clasp::Cli::ClaspAppBase.
Definition at line 55 of file application.h.
virtual const char* ProgramOptions::Application::getUsage | ( | ) | const [inline, virtual] |
Returns the usage information of this application.
Reimplemented in Clasp::Cli::ClaspApp.
Definition at line 57 of file application.h.
virtual const char* ProgramOptions::Application::getVersion | ( | ) | const [pure virtual] |
Returns the version number of this application.
Implemented in Clasp::Cli::ClaspApp.
virtual void ProgramOptions::Application::info | ( | const char * | msg | ) | const [inline, virtual] |
Prints the given info message to stderr.
Definition at line 65 of file application.h.
virtual void ProgramOptions::Application::initOptions | ( | OptionContext & | root | ) | [protected, pure virtual] |
Adds all application options to the given context.
Implemented in Clasp::Cli::ClaspAppBase.
void ProgramOptions::Application::killAlarm | ( | ) | [protected] |
Definition at line 165 of file application.cpp.
int ProgramOptions::Application::main | ( | int | argc, |
char ** | argv | ||
) |
Runs this application with the given command-line arguments.
Definition at line 49 of file application.cpp.
bool ProgramOptions::Application::onSignal | ( | int | x | ) | [protected, virtual] |
Called when a signal is received. Tthe default terminates the application.
Reimplemented in Clasp::Cli::ClaspAppBase.
Definition at line 158 of file application.cpp.
void ProgramOptions::Application::onUnhandledException | ( | ) | [protected, virtual] |
Called on an exception from run(). The default terminates the application.
Definition at line 79 of file application.cpp.
void ProgramOptions::Application::printHelp | ( | const OptionContext & | root | ) | [virtual] |
Prints the application's help information (called if options contain '--help').
Reimplemented in Clasp::Cli::ClaspApp, and Clasp::Cli::ClaspAppBase.
Definition at line 226 of file application.cpp.
void ProgramOptions::Application::printUsage | ( | ) | [virtual] |
Prints the application's usage message (default is: "usage: getName() getUsage()").
Definition at line 242 of file application.cpp.
void ProgramOptions::Application::printVersion | ( | ) | [virtual] |
Prints the application's version message (called if options contain '--version').
Reimplemented in Clasp::Cli::ClaspAppBase.
Definition at line 236 of file application.cpp.
void ProgramOptions::Application::processSignal | ( | int | sigNum | ) | [protected] |
Definition at line 146 of file application.cpp.
virtual void ProgramOptions::Application::run | ( | ) | [protected, pure virtual] |
Shall run the application. Called after setup and option processing.
Implemented in Clasp::Cli::ClaspAppBase.
void ProgramOptions::Application::setExitCode | ( | int | n | ) |
Sets the value that should be returned as the application's exit code.
Definition at line 86 of file application.cpp.
virtual void ProgramOptions::Application::setup | ( | ) | [protected, pure virtual] |
Called once after option processing is done.
Implemented in Clasp::Cli::ClaspAppBase.
void ProgramOptions::Application::setVerbose | ( | unsigned | v | ) | [protected] |
Definition at line 249 of file application.cpp.
void ProgramOptions::Application::shutdown | ( | ) | [protected, virtual] |
Called after run returned. The default is a noop.
Reimplemented in Clasp::Cli::ClaspAppBase.
Definition at line 103 of file application.cpp.
void ProgramOptions::Application::shutdown | ( | bool | hasError | ) | [protected] |
Definition at line 95 of file application.cpp.
void ProgramOptions::Application::sigHandler | ( | int | sig | ) | [static, private] |
Definition at line 131 of file application.cpp.
void ProgramOptions::Application::unblockSignals | ( | bool | deliverPending | ) | [protected] |
Definition at line 120 of file application.cpp.
virtual void ProgramOptions::Application::validateOptions | ( | const OptionContext & | root, |
const ParsedOptions & | parsed, | ||
const ParsedValues & | values | ||
) | [protected, pure virtual] |
Validates parsed options. Shall throw to signal error.
Implemented in Clasp::Cli::ClaspAppBase.
unsigned ProgramOptions::Application::verbose | ( | ) | const [protected] |
Definition at line 246 of file application.cpp.
virtual void ProgramOptions::Application::warn | ( | const char * | msg | ) | const [inline, virtual] |
Prints the given warning message to stderr.
Definition at line 67 of file application.h.
volatile sig_atomic_t ProgramOptions::Application::blocked_ [private] |
Definition at line 126 of file application.h.
int ProgramOptions::Application::exitCode_ [private] |
Definition at line 122 of file application.h.
bool ProgramOptions::Application::fastExit_ [private] |
Definition at line 125 of file application.h.
Application * ProgramOptions::Application::instance_s = 0 [static, private] |
Definition at line 128 of file application.h.
volatile sig_atomic_t ProgramOptions::Application::pending_ [private] |
Definition at line 127 of file application.h.
unsigned ProgramOptions::Application::timeout_ [private] |
Definition at line 123 of file application.h.
unsigned ProgramOptions::Application::verbose_ [private] |
Definition at line 124 of file application.h.