Application Class Reference

#include <Pt/System/Application.h>

Console process root. 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.
static Path tmpdir ()
 Returns the systems tmp directory.
static void setEnvVar (const std::string &name, const std::string &value)
 Set environment variable.
static void unsetEnvVar (const std::string &name)
 Unset environment variable.
static std::string getEnvVar (const std::string &name)
 Get environment variable.
static unsigned long usedMemory ()
 Returns the amount of used memory.

Detailed Description

Application is the console process root. There is one instance per process. It uses an EventLoop. The default constructors create a MainLoop. A custom loop can be passed in. The application does not own a loop passed by the caller.

run() enters the loop. exit() leaves it. loop() returns the loop so timers and selectables can attach to it. instance() returns the single application.

Command line arguments are available through argc(), argv(), and getArg(). catchSystemSignal() reports a C signal on systemSignal. ignoreSystemSignal() leaves a signal to the default handler. chdir(), cwd(), rootdir(), and tmpdir() are the process directories. setEnvVar(), unsetEnvVar(), and getEnvVar() change the environment.

int main(int argc, char* argv[])
{
app.run();
return 0;
}
Console process root.
Definition Application.h:74
char ** argv() const
Command line arguments.
Definition Application.h:139
int & argc() const
Number of command line arguments.
Definition Application.h:134

Member Function Documentation

◆ rootdir()

Path rootdir ( )
static

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

◆ tmpdir()

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()

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

◆ unsetEnvVar()

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

◆ getEnvVar()

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