#include <signal.h>
Inheritance diagram for gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >:
See also gutz::connect and gutz::disconnect in signalGutz.h
If a class has member functions that will be used as slots, ie, functions that recieve signals from other classes, you need to have this public declaration in that class:
Other than that, a slot is simply any member function of a class, that's it! here is an example class that... HAS_SLOTS;
class MyClassB { public: // blah blah constructors... HAS_SLOTS; void setTheFloat(float f) {...} /// a slot taking a float void someEmptySlot(); /// a slot with 0 parameters... /// ... defined elsewhere };
If you want to create a signal, i.e. a "function" that emmits an event, you need to use the Signal<*> that is appropriate for the number of arguments that it will need, ex:
class MyClassA { public: //... gutz::Signal<float> myFloatChanged; }
myFloatChanged(1.0f);
Remember that although you use myFloatChanged like a function, it is really a "functor", a class that has "operator()" overloaded so that it behaves like a function. For you this only affects the way it is declared, as above, where the items in "<>"s are the types of the parameters used when it is called.
A signal that takes 0 parameters looks like:
gutz::Signal<> myEmptySignal;
You can have up to 8 parameters in a signal right now, just declare your signal with the number of parameters it will take, for example here is another signal that takes 4 parameters:
gutz::Signal<float, double, vec3f, const char *> mySignalThingy;
If you want a member function of a class to recieve a signal, you "connect" them together like so:
gutz::connect(a.myFloatChanged, &b, &MyClassB::setTheFloat)
Signal Implementation Notes:
an implementation of the Signal interface. A generic signal that can take upto 8 parameters, the types are specified by the template parameters A*, which default to the "not applicable" type, which is simply an empty class. The Call Type <signalCalls.h> is speciallized based on wether or not a parameter is a real type or NA to call the correct slot function.
TODO: could setup some kind of default parameters for the signal, with another huge list of template parameters, but is that really necessary?
argument types, default to "not applicable" (NA)
Definition at line 144 of file signal.h.
Functor call | |
Takes up to 8 args.
You only need to call this with the number of args that are valid for the signal. | |
void | operator() (A1 a1=NA(), A2 a2=NA(), A3 a3=NA(), A4 a4=NA(), A5 a5=NA(), A6 a6=NA(), A7 a7=NA(), A8 a8=NA()) |
Utilities | |
bool | slotsAttached () const |
check if the slot has anyone attached to it. | |
Framework stuff. | |
You can ignore these functions, they are used by the signals and slots framework.
| |
template<class CE, class F> void | addCall (CE *callee, F fncPtr, int priority) |
add a slot/call at users behest, used by gutz::connect | |
template<class CE, class F> void | delCall (CE *callee, F fptr) |
remove slot/call at users behest. used by gutz::disconnect | |
void | detatchSlotIF (void const *callee) |
remove slot/call when owner destructs... | |
class | SignalTracker |
template<class SIG, class CE, class F> void | connect (SIG &, CE *, F, int) |
Connect, use this to connect a gutz::Signal to a slot (member function of a class that has "HAS_SLOTS" declared). | |
template<class SIG, class CE, class F> void | disconnect (SIG &, CE *, F) |
disconnect, the opposite of gutz::connect | |
Public Types | |
typedef Signal< A1, A2, A3, A4, A5, A6, A7, A8 > | MyType |
typedef _CallIF< A1, A2, A3, A4, A5, A6, A7, A8 > | CallIFT |
typedef std::vector< CallIFT * > | CallPVec |
typedef CallPVec::iterator | CallPVecIter |
Public Member Functions | |
Signal () | |
~Signal () | |
Protected Member Functions | |
void | dbg (const char *where=0, int i1=-8888, int i2=-8888) |
printing debug statements | |
Protected Attributes | |
CallPVec | _calls |
|
|
|
|
|
Definition at line 149 of file signal.h. Referenced by gutz::Signal< gutz::planef >::addCall(), gutz::Signal< gutz::planef >::delCall(), and gutz::Signal< gutz::planef >::detatchSlotIF(). |
|
|
|
|
|
notify all slots/calls that the signal is no longer valid |
|
add a slot/call at users behest, used by gutz::connect
|
|
printing debug statements switch debug off, even in debug mode Definition at line 271 of file signal.h. Referenced by gutz::Signal< gutz::planef >::addCall(), and gutz::Signal< gutz::planef >::operator()(). |
|
remove slot/call at users behest. used by gutz::disconnect
|
|
remove slot/call when owner destructs... from SignalIF interface, actually called by a gutz::SignalTracker. Implements gutz::SignalIF. |
|
|
|
check if the slot has anyone attached to it. You might want to know if calling the slot will have any affect. This is especially important if the parameters you are passing are not by reference and are "heavy", ie large objects. |
|
Connect, use this to connect a gutz::Signal to a slot (member function of a class that has "HAS_SLOTS" declared).
s = the signal, ex: a.theSignal (MyClassA instance) callee = instance of the class recieving signal, ex: &b (MyClassB instance) fncPtr = the "slot", ex: &MyClassB::theSlot priority = the higher the number, the earlier it will be called Although this is a template function, the template parameters are resolved implicitly, so you can call "connect" without specifying any template parameters, ex: connect(a.theSignal, &b, &myClassB::theSlot); Here is another, more concrete, example using connect() #include <signalGutz.h> #include <iostream> class MySlotClass { public: HAS_SLOTS; void someSlot(float f) { std::cerr << "someSlot(f): f = " << f; } }; class MySignalClass { public: gutz::Signal<float> myFloatChanged; void emmitMyFloat(float f) { myFloatChanged(f); } }; ///... in some function ... (main maybe?) MySignalClass sigClass; MySlotClass slotClass; /// connect sigClass.myFloatChanged to slotClass's slot "someSlot(f)" gutz::connect(sigClass.myFloatChanged, &slotClass, &MySlotClass::someSlot); /// send a signal sigClass.emmitMyFloat(3.15159265); /// should print "someSlot(f): f = 3.14159265" to stdout /// now disconnect the sig/slot combo gutz::disconnect(sigClass.myFloatChanged, &slotClass, &MySlotClass::someSlot); /// try the signal again sigClass.emmitMyFloat(2.7182818); /// shouldn't print anything to stdout! see gutz::disconnect for the reverse of this function.
Definition at line 87 of file signalGutz.h. |
|
disconnect, the opposite of gutz::connect
Definition at line 98 of file signalGutz.h. |
|
|
|