Application Class Reference

#include <Pt/System/Application.h>

Console applications without a GUI. More...

Inherits Connectable.

Public Member Functions

 Application (int argc=0, char **argv=0)
 Construct with command line arguments.
 
 Application (EventLoop *loop, int argc=0, char **argv=0)
 Construct with custom event loop.
 
 ~Application ()
 Destructor.
 
int argc () const
 Number of command line arguments.
 
char ** argv () const
 Command line arguments.
 
bool catchSystemSignal (int sig)
 Catch a system signal.
 
void exit ()
 Exits from the contained event loop.
 
template<typename T >
Arg< T > getArg (const char *name)
 Returns the value of a long option.
 
template<typename T >
Arg< T > getArg (const char *name, const T &def)
 Returns the value of a long option.
 
template<typename T >
Arg< T > getArg (const char name)
 Returns the value of a short option.
 
template<typename T >
Arg< T > getArg (const char name, const T &def)
 Returns the value of a short option.
 
bool ignoreSystemSignal (int sig)
 Ignores a system signal.
 
EventLooploop ()
 Returns the event loop.
 
bool raiseSystemSignal (int sig)
 Raise a system signal.
 
void run ()
 Starts the contained event loop.
 
Signal< int > & systemSignal ()
 Notifies when a system signal was caught.
 

Static Public Member Functions

static void chdir (const Path &path)
 Changes the current directory.
 
static Path cwd ()
 Returns the current directory.
 
static std::string getEnvVar (const std::string &name)
 Get environment variable. More...
 
static Applicationinstance ()
 Returns an instance to the application.
 
static Path rootdir ()
 Returns the system root path. More...
 
static void setEnvVar (const std::string &name, const std::string &value)
 Set environment variable. More...
 
static Path tmpdir ()
 Returns the systems tmp directory. More...
 
static void unsetEnvVar (const std::string &name)
 Unset environment variable. More...
 

Detailed Description

This class is used by non-GUI applications to provide the central event loop, handle C signals and process command line arguments. There can be only one instance per application. The application and therefore the event loop is started with a call to run() and can be exited with a call to exit(). The event loop can be obtained by calling loop(). Command line arguments can be parsed as Arg and static methods exist to set environment variables.

Member Function Documentation

static Path rootdir ( )
static

Returns "/" (root) on Linux, "c:\" on Windows

static Path tmpdir ( )
static

Returns the value of the environment variable named TEMP or TMP. If neither one is set, "/tmp" is returned on POSIX systems or a path to the current directory.

static void setEnvVar ( const std::string &  name,
const std::string &  value 
)
static
Exceptions
SystemError
static void unsetEnvVar ( const std::string &  name)
static
Exceptions
SystemError
static std::string getEnvVar ( const std::string &  name)
static
Exceptions
SystemError