arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 > Class Template Reference

#include <signal.h>

Inheritance diagram for gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >:

gutz::SignalIF List of all members.

Detailed Description

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
class gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >

An API for signals and slots.

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:

 HAS_SLOTS; 

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
    };
Notice that we only have "HAS_SLOTS;" declared once! That's all you need no matter how many different slots you have. Also notice that you don't need the "gutz::" namespace resolution, we took care of that for you. HAS_SLOTS is a #define that declares a member variable in your class, it is used to keep track of any signal that connects to a slot. This is needed so that you can delete the class whenever you need without having to worry about disconnecting every signal attached to it.

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" can now be used like a function that takes 1 float argument:
     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)
This means {connect "a"'s signal "myFloatChanged" to "b"'s member function "setTheFloat"}, ( where "a" is an instance of "MyClassA", and "b" is an instance of class "MyClassB"). Notice that "a" is passed to "connect" by reference, "b" is passed as a pointer, and "setTheFloat" is passed as a pointer to a member function.
Remember that the class recieving the signal ("MyClassB" in this example) must have "HAS_SLOTS" inside it's declaration. connect() also takes a priority integer value, the higher the number the earlier the connected function will be called when there are multiple slots recieving the signal, mostly usefull for debugging, probably not a usefull extension since we have no "real" symantics associated with this value. See gutz::connect for more details.

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.


Hiding these was easy using template friends, however, sucky because we needed a full template declaration, even though we would have liked a partial specialization of class where the signal is always us, ie MyType.

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


Member Typedef Documentation

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
typedef _CallIF<A1,A2,A3,A4,A5,A6,A7,A8> gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::CallIFT
 

Definition at line 147 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
typedef std::vector<CallIFT*> gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::CallPVec
 

Definition at line 148 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
typedef CallPVec::iterator gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::CallPVecIter
 

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().

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
typedef Signal<A1,A2,A3,A4,A5,A6,A7,A8> gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::MyType
 

Definition at line 146 of file signal.h.


Constructor & Destructor Documentation

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::Signal  )  [inline]
 

Definition at line 150 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::~Signal  )  [inline]
 

notify all slots/calls that the signal is no longer valid

Definition at line 151 of file signal.h.


Member Function Documentation

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
template<class CE, class F>
void gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::addCall CE *  callee,
fncPtr,
int  priority
[inline, protected]
 

add a slot/call at users behest, used by gutz::connect

Definition at line 211 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
void gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::dbg const char *  where = 0,
int  i1 = -8888,
int  i2 = -8888
[inline, protected]
 

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()().

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
template<class CE, class F>
void gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::delCall CE *  callee,
fptr
[inline, protected]
 

remove slot/call at users behest. used by gutz::disconnect

Definition at line 229 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
void gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::detatchSlotIF void const *  callee  )  [inline, protected, virtual]
 

remove slot/call when owner destructs...

from SignalIF interface, actually called by a gutz::SignalTracker.

Implements gutz::SignalIF.

Definition at line 251 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
void gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::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()
[inline]
 

Definition at line 167 of file signal.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
bool gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::slotsAttached  )  const [inline]
 

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.

Definition at line 188 of file signal.h.


Friends And Related Function Documentation

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
template<class SIG, class CE, class F>
void connect SIG &  s,
CE *  callee,
fncPtr,
int  priority
[friend]
 

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 also gutz::Signal for more documetation on this API
see gutz::disconnect for the reverse of this function.
Parameters:
s  the signal
callee  pointer to class with slot
fncPtr  member function of "callee" (the slot)
priority  optional priority, higher = earlier called (defaults to 0)

Definition at line 87 of file signalGutz.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
template<class SIG, class CE, class F>
void disconnect SIG &  s,
CE *  callee,
fncPtr
[friend]
 

disconnect, the opposite of gutz::connect

Parameters:
s  the signal
callee  pointer to class with slot
fncPtr  member function of "callee" (the slot)

Definition at line 98 of file signalGutz.h.

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
friend class SignalTracker [friend]
 

Definition at line 246 of file signal.h.


Member Data Documentation

template<class A1 = NA, class A2 = NA, class A3 = NA, class A4 = NA, class A5 = NA, class A6 = NA, class A7 = NA, class A8 = NA>
CallPVec gutz::Signal< A1, A2, A3, A4, A5, A6, A7, A8 >::_calls [protected]
 

Definition at line 287 of file signal.h.

Referenced by gutz::Signal< gutz::planef >::addCall(), gutz::Signal< gutz::planef >::delCall(), gutz::Signal< gutz::planef >::detatchSlotIF(), gutz::Signal< gutz::planef >::operator()(), gutz::Signal< gutz::planef >::slotsAttached(), and gutz::Signal< gutz::planef >::~Signal().


The documentation for this class was generated from the following file:
Send questions, comments, and bug reports to:
jmk