dbp::application Class Reference

Console application class. More...

#include <application.h>

Inheritance diagram for dbp::application:
Inheritance graph
[legend]
Collaboration diagram for dbp::application:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void set_name (const std::string &app_name)
 Set application name.
virtual void set_description (const std::string &description)
 Set application description.
virtual void register_cmdline_parameter (const cmdline_parameter &param, application_int::cmdline_parameter_handler handler)
 Register the application command line parameter.
virtual void on_execute (on_execute_handler handler)
 Register the application main execute cycle handler.
virtual void on_exception (on_exception_handler handler)
 Register the exception handler.
virtual int run (int argc, char *argv[])
 Execute the application.
const std::string & get_name () const
 Get application name.
const std::string & get_path () const
 Get the application path.
const std::string & get_description () const
 Get application description.

Friends

class singleton< application >

Detailed Description

Console application class.

The basic application class. If you want to create simple, generic application (console utility, for example), you need to use this class, for example:

/*
 * Classic "Hello, world!" example console application.
 *
 * This example shows how to write "skeleton" of the application with
 * DCL framework using dbp::application class.
 *
 * As the result, the simple console application will be produced.
 */

#include <iostream>
#include <string>

// include all classes from dclbase library
#include <dcl/dclbase.h>

// use the DCL default namespace by default
using namespace dbp;

// declare our own application class
class hello_world_app {
public:
        // the constructor of the hello_world_app class initializes the
        // console application by obtaining a link to the dbp::application class
        // via its instance() method call.
        hello_world_app(): app(application::instance()) {
                // set the application name
                app.set_name(_("Hello World Application"));
                // set the application description
                app.set_description(_("Prints a classic greeting"));
                // register the custom command line parameter handler
                app.register_cmdline_parameter(cmdline_parameter('v', "version",
                  _("show the application version"), "", cmdline_parameter::OPTION),
                  create_delegate(this, &hello_world_app::on_version_parameter));
                // register the execute event handler
                app.on_execute(create_delegate(this, &hello_world_app::on_execute));
        }
        // the reference to the console application class
        application &app;
private:
        // "-v" command line parameter handler
        bool on_version_parameter(cmdline_parameter&) {
                std::cout << _("version 1.0.0") << std::endl;
                return false;
        };
        // execute event handler
        int on_execute() {
                std::cout << _("Hello, world!") << std::endl;
                return 0;
        };
};

// initialize and run the application via provided macros
IMPLEMENT_APP(hello_world_app().app);


Member Function Documentation

const std::string& dbp::application::get_description (  )  const [inline]

Get application description.

Returns a value previously set by set_description() call.

const std::string& dbp::application::get_name (  )  const [inline]

Get application name.

Returns a value previously set by set_name() call.

const std::string& dbp::application::get_path (  )  const [inline]

Get the application path.

Returns a path to the the application executable.

virtual void dbp::application::on_execute ( on_execute_handler  handler  )  [virtual]

Register the application main execute cycle handler.

You need to register your own application execution handler with application logic.

See the 'examples/hello_world/console_application' directory for the sample code.

Parameters:
handler an execute command delegate.
virtual void dbp::application::register_cmdline_parameter ( const cmdline_parameter param,
application_int::cmdline_parameter_handler  handler 
) [virtual]

Register the application command line parameter.

You can register one or more command line parameters supported by your application. When application starts, it checks of command line parameters passed for registered ones. If none is found, it reports about invalid command line parameter; if registered one is found, on_cmdline_parameter handler is called.

See the 'examples/hello_world/console_application' directory for the sample code using this method.

Parameters:
param the command line parameter to register.
handler a command line parameter delegate.

Implements dbp::application_int.

virtual void dbp::application::set_description ( const std::string &  description  )  [virtual]

Set application description.

Parameters:
description a brief application description for displaying purposes.

Implements dbp::application_int.

virtual void dbp::application::set_name ( const std::string &  name  )  [virtual]

Set application name.

The application name is used for displaying purposes. The internationalization (i18n) resources path (catalog) is also initialized from the application name.

Parameters:
name the name of the application.

Implements dbp::application_int.


The documentation for this class was generated from the following file:

 
Support This Project
SourceForge.net Logo