Calls and Triggers
These classes provide a flexible method for handling function and
method pointers. They have many of the advantages of using
Signals in that you don't
have to know the exact form a function pointer, but without the
complexity.
Using triggers
Triggers are the simplest form of call. They allow an function
with arbitrary set of parameters to be called on an event. It is
used in classes such as
TimedTriggerQueueC
to call a method after a fixed delay, and in
TickerTriggerC which
calls a method repeatedly at a fixed frequency.
Creating a trigger is simple:
#include "Ravl/Trigger.hh"
TriggerC myTrigger;
You can assign a function to it using the Trigger call.
bool PrintNumber(int &i) {
cout << "PrintNumber called with value " << i << "\n";
return true;
}
myTrigger = Trigger(&PrintNumber,2);
Calling the function can be done with the () operator.
myTrigger();
Using calls
Calls are wrappers for C++ function pointers which allow
you to find the difference between calling a method of a
class and a normal function, and to add default arguments
to the call that the code calling the function need not know about.
Default arguments
When you setup a callback function, you can set default parameters. This
especially useful if the method you wish to call requires more information
than the callback normally provides. In the 3rd argument is set to 3, since
its only called with 2 arguments, 30 is passed as its default value.
#include "Ravl/Calls.hh"
bool callback(int &v1,double &v2,int &x) {
// Do something....
return true;
}
int myprog() {
// Declare callback variable.
CallFunc2<int,double> func;
// Setup call back.
func = Trigger(&callback,10,20,30);
// Some paramiters...
int v1 = 0;
double v2 = 1.2;
// Call function.
func(v1,v2);
}
Normal classes:
Normal functions:
Trigger(RetT (*nfunc)() ) | |
Trigger(RetT (*nfunc)(DataT & dat) ,const DataT &) | |
Trigger(RetT (*nfunc)(Data1T &,Data2T &) ,const Data1T &,const Data2T &) | |
Trigger(RetT (*nfunc)(Data1T &,Data2T &,Data3T &) ,const Data1T &,const Data2T &,const Data3T &) | |
Trigger(RetT (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &) | |
Trigger(RetT (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &,Data5T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &,const Data5T &) | |
Trigger(bool (*nfunc)() ) | |
Trigger(bool (*nfunc)(DataT & dat) ,const DataT &) | |
Trigger(bool (*nfunc)(Data1T &,Data2T &) ,const Data1T &,const Data2T &) | |
Trigger(bool (*nfunc)(Data1T &,Data2T &,Data3T &) ,const Data1T &,const Data2T &,const Data3T &) | |
Trigger(bool (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &) | |
Trigger(bool (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &,Data5T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &,const Data5T &) | |
Trigger(const ObjT &,RetT (*nfunc)() ) | |
Trigger(const ObjT &,RetT (*nfunc)(DataT &) ,const DataT &) | |
Trigger(const ObjT &,RetT (*nfunc)(Data1T &,Data2T &) ,const Data1T &,const Data2T &) | |
Trigger(const ObjT &,RetT (*nfunc)(Data1T &,Data2T &,Data3T &) ,const Data1T &,const Data2T &,const Data3T &) | |
Trigger(const ObjT &,RetT (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &) | |
Trigger(const ObjT &,RetT (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &,Data5T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &,const Data5T &) | |
Trigger(const ObjT &,bool (*nfunc)() ) | |
Trigger(const ObjT &,bool (*nfunc)(DataT &) ,const DataT &) | |
Trigger(const ObjT &,bool (*nfunc)(Data1T &,Data2T &) ,const Data1T &,const Data2T &) | |
Trigger(const ObjT &,bool (*nfunc)(Data1T &,Data2T &,Data3T &) ,const Data1T &,const Data2T &,const Data3T &) | |
Trigger(const ObjT &,bool (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &) | |
Trigger(const ObjT &,bool (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &,Data5T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &,const Data5T &) | |
TriggerR(ObjT &,RetT (*nfunc)() ) | |
TriggerR(ObjT &,RetT (*nfunc)(DataT &) ,const DataT &) | |
TriggerR(ObjT &,RetT (*nfunc)(Data1T &,Data2T &) ,const Data1T &,const Data2T &) | |
TriggerR(ObjT &,RetT (*nfunc)(Data1T &,Data2T &,Data3T &) ,const Data1T &,const Data2T &,const Data3T &) | |
TriggerR(ObjT &,RetT (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &) | |
TriggerR(ObjT &,RetT (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &,Data5T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &,const Data5T &) | |
TriggerR(ObjT &,bool (*nfunc)() ) | |
TriggerR(ObjT &,bool (*nfunc)(DataT &) ,const DataT &) | |
TriggerR(ObjT &,bool (*nfunc)(Data1T &,Data2T &) ,const Data1T &,const Data2T &) | |
TriggerR(ObjT &,bool (*nfunc)(Data1T &,Data2T &,Data3T &) ,const Data1T &,const Data2T &,const Data3T &) | |
TriggerR(ObjT &,bool (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &) | |
TriggerR(ObjT &,bool (*nfunc)(Data1T &,Data2T &,Data3T &,Data4T &,Data5T &) ,const Data1T &,const Data2T &,const Data3T &,const Data4T &,const Data5T &) | |
Advanced classes:
|