BasicApp Class Reference
[Basic classesSingle inited classes]

Basic functions to handle the application. More...

#include <basicapp.h>

Inheritance diagram for BasicApp:

Inheritance graph
[legend]
Collaboration diagram for BasicApp:

Collaboration graph
[legend]
List of all members.

Public Member Functions

DECLSPEC BasicApp (int argc, char *argv[], const char *datapath=NULL, const char *debug=NULL)
DECLSPEC BasicApp (int argc, char *argv[], TiXmlElement *el)
DECLSPEC int init (TiXmlElement *el=NULL)
virtual DECLSPEC void destroy ()
virtual long mainLoop ()
DECLSPEC const char * getExePath ()
DECLSPEC const char * getDataPath ()
DECLSPEC std::string makeDataPath (const char *path)
const char * getUserdataPath ()
DECLSPEC std::string makeUserPath (const char *path)
int getArgC ()
const char * getArgV (int n)
DECLSPEC void exitWithMessage (const char *str)

Static Public Member Functions

static DECLSPEC bool setWorkingDir (const char *dn)
static DECLSPEC bool chDirToUser ()
static DECLSPEC const char * getOSName ()
static DECLSPEC const char * getCPUArch ()
static DECLSPEC const char * getRunningOSName ()
static DECLSPEC const char * getRunningOSVersion ()
static DECLSPEC const char * getRunningOSArch ()
static DECLSPEC BasicAppgetThe ()

Static Public Attributes

static BasicAppthe

Protected Member Functions

DECLSPEC void setDataPath (const char *path)
DECLSPEC void setUserdataPath (const char *path)
DECLSPEC void onInit ()

Protected Attributes

int nInitFailStatus

Detailed Description

Basic functions to handle the application.

Do not use two or more variables of this class at a time. But to use the netrinjo-engine, it has to be contructed once.

BasicApp is used to handle the main process and getting important paths. Only use it in a derived class and inherit mainLoop(). For better understanding of this class have a look at an example application.


Constructor & Destructor Documentation

BasicApp::BasicApp ( int  argc,
char *  argv[],
const char *  datapath = NULL,
const char *  debug = NULL 
)

Constructor

Parameters:
argc number of arguments given to the app
argv content of the arguments given to the app
datapath the path to the data-containing directory, if NULL, the executable's directory is taken
debug the filename of the log-file, if NULL, logging is not possible
nInitFailStatus is set to zero by default.

BasicApp::BasicApp ( int  argc,
char *  argv[],
TiXmlElement el 
)

Constructor, using XML data

Parameters:
argc number of arguments given to the app
argv content of the arguments given to the app
el the XML data, the value of the Attribute "DataPath" is read and is then returned by the method getDataPath()
nInitFailStatus is set to zero by default.


Member Function Documentation

int BasicApp::init ( TiXmlElement el = NULL  ) 

May be implemented in derived classes.

Parameters:
el the XML data, used for initialisation (not useful, if that was already specified on creation)
Returns:
nInitFailStatus: if important initial routins fail, it should not return zero
recommended usage: call init() in the "main(..)" function and exit, if init() does not return zero In the derived class, inherit onInit() and perform all initialisation routines there.

void BasicApp::destroy (  )  [virtual]

by calling destroy() the application finishes the log-file and exits with "0"

Reimplemented from BasicObject.

Reimplemented in XmlApp.

virtual long BasicApp::mainLoop (  )  [inline, virtual]

only for derived classes

See also:
init()
recommended usage: call mainLoop() at the end of the "main(..)" function and return with it's result (like: "return app.mainLoop();") In the derived class, inherit mainLoop() and store all operations you need for running your app, probably a loop that continues, until the program shoul be quitted.

Reimplemented in XmlApp.

const char * BasicApp::getExePath (  ) 

Returns:
the path of the application's executable; the last character is a '/' (slash)

const char * BasicApp::getDataPath (  ) 

Returns:
the path to the data-containing directory; if not set, this is equal to getExePath(); the last character is a '/' (slash)

std::string BasicApp::makeDataPath ( const char *  path  ) 

Makes an absolute path out of a path, relative to the data containing folder. At first the method makeEnvPath() is called to replace environment expressions. Then it is checked, whether it is absolute or not. If the path is absolute, the result equals the one of makeEnvPath(), otherwise the data path is prepended.

Returns:
the absolute path to the file/folder in the data-containing directory

const char* BasicApp::getUserdataPath (  )  [inline]

Returns:
the path to the directory, where user specific data is loaded from; (usually a subdirectory of the user's home directory); if the folder has not been specified before, the user's home is returned. The last character is a '/' (slash)

std::string BasicApp::makeUserPath ( const char *  path  ) 

Makes an absolute path out of a path, relative to the user's data containing folder. At first the method makeEnvPath() is called to replace environment expressions. Then it is checked, whether it is absolute or not. If the path is absolute, the result equals the one of makeEnvPath(), otherwise the user's data path is prepended.

Returns:
the absolute path to the file/folder in the user-specific directory

int BasicApp::getArgC (  )  [inline]

Returns:
the number of arguments given to the application

const char* BasicApp::getArgV ( int  n  )  [inline]

Returns:
the content of the n-th argument given to the application

void BasicApp::exitWithMessage ( const char *  str  ) 

prints an error-message with "str" to the standard-output and also writes it to the logfile then it exits by calling the "BasicApp::destroy()"-function

Parameters:
str the message to print and write to the logfile

bool BasicApp::setWorkingDir ( const char *  dn  )  [static]

sets the current working directory to "dn". if "dn" does not exist, it trys to create it

Parameters:
dn the working directory to be set; may be a relative path
Returns:
true, if the working-dir could be changed, otherwise false

bool BasicApp::chDirToUser (  )  [static]

changes the current working directory to the user's home-directory Linux usually: /home/username Windows usually: C:/Documents and Settings/username

Returns:
true, if successful, false if not

const char * BasicApp::getOSName (  )  [static]

Returns:
the name of the operating system, where Netrinjo has been compiled on (e.g.: Linux, Windows)

const char * BasicApp::getCPUArch (  )  [static]

Returns:
the name of the CPU architecture (e.g.: x86_64, i386)

const char * BasicApp::getRunningOSName (  )  [static]

Returns:
the name of the running operating system, independent of the compilation-OS of Netrinjo

const char * BasicApp::getRunningOSVersion (  )  [static]

Returns:
the version of the running operating system

const char * BasicApp::getRunningOSArch (  )  [static]

Returns:
the architecture, the running operating system is compiled for

BasicApp * BasicApp::getThe (  )  [static]

Returns:
a pointer to the BasicApp variable, or NULL if not initialized. (There is only one BasicApp variable allowed in an application)
Every netrinjo-class that can only exist once at a time, has this static function.
See also:
Single inited classes

void BasicApp::setDataPath ( const char *  path  )  [protected]

Sets the path to the data containing directory. The environment variable DATAPATH is also set/updated to the new value.

Parameters:
path the path to set
See also:
getDataPath()

void BasicApp::setUserdataPath ( const char *  path  )  [protected]

Sets the path to the user specific, data containing directory. The environment variable USERPATH is also set/updated to the new value.

Parameters:
path the path to set, if it starts with "~/", it is taken relative to the user's home directory
See also:
getUserdataPath()

void BasicApp::onInit (  )  [protected, virtual]

Initializes the object's variables by reading data from the XML element. If there were no XML data used for creation, nothing is done. This function calls onInit() of its children recursively (after it has inited itself). It is highly recommended to call BasicObject::onInit(), usually at the end of the onInit() method, when overwriting it in a derived class.

Reimplemented from BasicLog.

Reimplemented in XmlApp.


Member Data Documentation

BasicApp * BasicApp::the [static]

not accessible in Windows, equals the result of getThe()

int BasicApp::nInitFailStatus [protected]

set to a number different from zero, if initialisation failed; use this in a derived class to set the return value of init()


The documentation for this class was generated from the following files:
Generated on Wed May 9 17:36:10 2007 for netrinjo by  doxygen 1.5.1