Application Class Reference

#include <Pt/System/Application.h>

Console applications without a GUI. More...

Inherits Connectable.

Inherited by Application.

Public Member Functions

 Application ()
 default Constructor.
 
 Application (int &argc, char **argv=0)
 Construct with command line arguments.
 
 Application (EventLoop *loop)
 Default construct with custom event loop.
 
 Application (EventLoop *loop, int &argc, char **argv=0)
 Construct with custom event loop.
 
 ~Application ()
 Destructor.
 
EventLooploop ()
 Returns the event loop.
 
void run ()
 Starts the contained event loop.
 
void exit ()
 Exits from the contained event loop.
 
bool ignoreSystemSignal (int sig)
 Ignores a system signal.
 
bool catchSystemSignal (int sig)
 Catch a system signal.
 
bool raiseSystemSignal (int sig)
 Raise a system signal.
 
Signal< int > & systemSignal ()
 Notifies when a system signal was caught.
 
int & argc () const
 Number of command line arguments.
 
char ** argv () const
 Command line arguments.
 
void setArgs (int &argc, char **argv)
 Set command line arguments.
 
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.
 

Static Public Member Functions

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

◆ rootdir()

static Path rootdir ( )
static

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

◆ tmpdir()

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.

◆ setEnvVar()

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

◆ unsetEnvVar()

static void unsetEnvVar ( const std::string &  name)
static
Exceptions
SystemError

◆ getEnvVar()

static std::string getEnvVar ( const std::string &  name)
static
Exceptions
SystemError