Generic Application. More...

#include <rapplication.h>

Inheritance diagram for RApplication:
[legend]
Collaboration diagram for RApplication:
[legend]

Public Member Functions

 RApplication (const RString &name, int argc, char **argv, const RString &localconfig=RString::Null, const RString &globalconfig=RString::Null)
 
 RApplication (const RString &name, const RString &localconfig=RString::Null, const RString &globalconfig=RString::Null)
 
void ParseArguments (int argc, char **argv)
 
RString GetName (void) const
 
RString GetApplicationFile (void) const
 
bool IsInit (void) const
 
RString GetLocalConfigDir (void) const
 
RConfigGetConfig (void)
 
RCursor< RStringGetArgs (void) const
 
bool GetParamValue (const RString &name, RString &value) const
 
RCursor< RParamValueGetParams (void) const
 
void Execute (void)
 
virtual ~RApplication (void)
 

Protected Member Functions

virtual void CreateConfig (void)
 
virtual void Init (void)
 

Protected Attributes

RString Name
 
RString File
 
RContainer< RString, true, false > Args
 
RContainer< RParamValue, true,
false > 
Params
 
RString LocalConfigDir
 
RConfig Config
 

Private Member Functions

virtual void Run (void)
 

Private Attributes

bool HasInitApp
 

Detailed Description

Generic Application.

The RApplication class provides a representation for a generic application. It defines a configuration file (stored in "~/.r/config/app") that can eventually have a template (stored in "/usr/r/config/app"). It manages also arguments on the form: "--argwithoutvalue" or "--argwithvalue value".

In practice, the important methods are CreateConfig(void) to create some configuration parameters, Init(void) to initialize the application (for example to allocate some structures) and Run(void) that contains the code to execute. Here is an example:

class MyApplication : public RApplication
{
public:
MyApplication(int argc, char** argv)
: RApplication("Test",argc,argv)
{
}
virtual void CreateConfig(void)
{
Config.InsertParam(new RParamValue("Message","Hello world !"));
}
virtual void Run(void)
{
cout<<Config.FindParam<RParamValue>("Message")->Get()<<endl;
}
};
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
MyApplication App(argc,argv);
return(EXIT_SUCCESS);
}

Constructor & Destructor Documentation

RApplication ( const RString name,
int  argc,
char **  argv,
const RString localconfig = RString::Null,
const RString globalconfig = RString::Null 
)

Construct an application. If both parameters 'localconfig' and 'globalconfig' are null (or not specified), the default directories are chosen.

Parameters
nameName of the application.
argcNumber of arguments of the program (received from main).
argvArguments of the program (received from main).
localconfigLocal configuration.
globalconfigLocal configuration.
RApplication ( const RString name,
const RString localconfig = RString::Null,
const RString globalconfig = RString::Null 
)

Construct an application. If both parameters 'localconfig' and 'globalconfig' are null (or not specified), the default directories are chosen.

This constructor doesn't analyzed the parameter passed to the program throught the main function. The method RApplication::ParseArguments should be manually called if parameters must be parsed.

Parameters
nameName of the application.
localconfigLocal configuration.
globalconfigLocal configuration.
virtual ~RApplication ( void  )
virtual

Destructor of the application. By default, the configuration is saved.

Member Function Documentation

void ParseArguments ( int  argc,
char **  argv 
)

Parse the arguments.

Parameters
argcNumber of arguments of the program (received from main).
argvArguments of the program (received from main).
RString GetName ( void  ) const

Get the name of the application.

RString GetApplicationFile ( void  ) const

Get the name of the file representing the executable.

bool IsInit ( void  ) const

Look if the application was initialized (call 'Init()' method).

RString GetLocalConfigDir ( void  ) const
Returns
the directory where the local configuration is stored.
RConfig* GetConfig ( void  )

Get a pointer over the configuration.

RCursor<RString> GetArgs ( void  ) const
Returns
a cursor on the arguments.
bool GetParamValue ( const RString name,
RString value 
) const

Get the value of a parameter passed as argument to program. Suppose the following program launch:

./testr --o ~/test.txt --d

These parameters can be treated with the code:

void MyApplication::TestParams(void)
{
RString val;
if(GetParamValue("o",val))
{
// Create the file with name is given by the variable 'val'.
}
if(GetParamValue("d",val))
{
// The value of 'val' is RString::Null.
}
if(GetParamValue("z",val))
{
// Nothing happens since '--z' was not passed to the program.
}
}
Parameters
nameName of the parameter.
valueThe value of the parameter. It can be RString::Null if no value is associated.
Returns
true if the parameter was found.
RCursor<RParamValue> GetParams ( void  ) const
Returns
a cursor on the parameters.
virtual void CreateConfig ( void  )
protectedvirtual

Create the configuration structure. New parameters can be added by defining a new method.

Reimplemented in QRGUIApplication.

virtual void Init ( void  )
protectedvirtual

Initialize the application. By default, it create the configuration structure and load the configuration file.

virtual void Run ( void  )
privatevirtual

Run the application.

void Execute ( void  )

Execute the application. In practice, it initializes the application if necessary, and then calls the Run() method.

Field Documentation

RString Name
protected

Name of the application.

RString File
protected

Name of executable file.

RContainer<RString,true,false> Args
protected

Arguments of the application.

RContainer<RParamValue,true,false> Params
protected

Parameters of the application.

RString LocalConfigDir
protected

Local directory of the configuration.

RConfig Config
protected

Configuration

bool HasInitApp
private

Application initialized?