Image Component Library (ICL)
|
QApplication extension for ICL based applications. More...
#include <Application.h>
Classes | |
struct | AsynchronousEvent |
interface for events that must be executed in the GUI Thread More... | |
struct | SecondSingeltonException |
Such an exception is returned if a 2nd instance of ICLApplication is created. More... | |
Public Types | |
typedef void(* | callback )(void) |
just type definition for convenience a void valued function with no args) | |
Public Member Functions | |
ICLApplication (int argc, char **argv, const std::string &paInitString="", callback init=0, callback run=0, callback run2=0, callback run3=0, callback run4=0, callback run5=0) throw (SecondSingeltonException) | |
Constructor. | |
~ICLApplication () | |
Destructor. | |
void | addThread (callback cb) |
adds a new threaded function | |
void | addInit (callback cb) |
adds a new initialization function | |
void | addFinalization (callback cb) |
adds a new finalization function | |
int | exec () |
executes this ICLApplication | |
void | executeInGUIThread (AsynchronousEvent *event) |
internally posts the event to the GUI Thread | |
virtual bool | event (QEvent *eIn) |
overloaded event function | |
Static Public Member Functions | |
static ICLApplication * | instance () |
returns the singelton ICLApplication instance (or NULL if there is none) | |
Public Attributes | |
QApplication * | app |
Static Private Attributes | |
static ICLApplication * | s_app |
singelton instance | |
static std::vector< ExecThread * > | s_threads |
list of threads | |
static std::vector< callback > | s_inits |
list of initialization functions | |
static std::vector< callback > | s_callbacks |
list of callback functions | |
static std::vector< callback > | s_finalizes |
list of finalization functions |
QApplication extension for ICL based applications.
After the 100th time of writing
void init(){...} void run(){...} int main(int n, char **ppc){ pa_init("..."); ExecThread x(run); QApplication app(n,ppc); init(); x.run(); return app.exec(); }
I wrote a utility class that does all the stuff above for me:
void init(){...} void run(){...} int main(int n, char **ppc){ return ICLApplication(n,ppc,"...",init,run).exec(); }
Of course sometimes we need more than on initialization functions or even more than one extra-thread:
void init1(){...} void init2(){...} void run1(){...} void run2(){...} void run3(){...} int main(int n, char **ppc){ ICLApplication app(n,ppc,"..."); app.addInit(init1); app.addInit(init2); app.addThread(run1); app.addThread(run2); app.addThread(run3); return app.exec(); }
I guess there's nothing more to explain, isn't it?
typedef void(* icl::qt::ICLApplication::callback)(void) |
just type definition for convenience a void valued function with no args)
icl::qt::ICLApplication::ICLApplication | ( | int | argc, |
char ** | argv, | ||
const std::string & | paInitString = "" , |
||
callback | init = 0 , |
||
callback | run = 0 , |
||
callback | run2 = 0 , |
||
callback | run3 = 0 , |
||
callback | run4 = 0 , |
||
callback | run5 = 0 |
||
) | throw (SecondSingeltonException) |
Constructor.
argc | C++-main function arg-count |
argv | C++-main function argument list (as obtained by int main(argc,argv)) |
paInitString | if not equal to "", pa_init is called with this string |
init | initialization function pointer. Which is just called once when exec() is called |
run | first threaded function which is called in a loop before the QApplication is started using QApplication::exec(); |
run2 | second threaded function which is called in a loop before the QApplication is started using QApplication::exec(); |
run3 | third threaded function which is called in a loop before the QApplication is started using QApplication::exec(); |
run4 | fourth threaded function which is called in a loop before the QApplication is started using QApplication::exec(); |
run5 | fifth threaded function which is called in a loop before the QApplication is started using QApplication::exec(); |
Destructor.
void icl::qt::ICLApplication::addFinalization | ( | callback | cb | ) |
adds a new finalization function
Finalization functions are called, when the singelton ICLApplication instance is deleted
void icl::qt::ICLApplication::addInit | ( | callback | cb | ) |
adds a new initialization function
Initialization functions are called at the beginning of an ICLApplication::exec() call
void icl::qt::ICLApplication::addThread | ( | callback | cb | ) |
adds a new threaded function
Threaded function are executed in a loop. Execution is started immediately before the QApplication is executed within ICLApplication::exec()
virtual bool icl::qt::ICLApplication::event | ( | QEvent * | eIn | ) | [virtual] |
overloaded event function
int icl::qt::ICLApplication::exec | ( | ) |
executes this ICLApplication
callbacks are executed in the following order: init functions, entry by entry in same order as their addition to this instance threads functions, are started in a extra thead, entry by entry in same order as their addition to this instance QApplication is executed and it's return code is f passed using 'return QApplication::exec();'
void icl::qt::ICLApplication::executeInGUIThread | ( | AsynchronousEvent * | event | ) |
static ICLApplication* icl::qt::ICLApplication::instance | ( | ) | [static] |
returns the singelton ICLApplication instance (or NULL if there is none)
QApplication* icl::qt::ICLApplication::app |
ICLApplication* icl::qt::ICLApplication::s_app [static, private] |
singelton instance
std::vector<callback> icl::qt::ICLApplication::s_callbacks [static, private] |
list of callback functions
std::vector<callback> icl::qt::ICLApplication::s_finalizes [static, private] |
list of finalization functions
std::vector<callback> icl::qt::ICLApplication::s_inits [static, private] |
list of initialization functions
std::vector<ExecThread*> icl::qt::ICLApplication::s_threads [static, private] |
list of threads