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

signalGutz.h

Go to the documentation of this file.
00001 /*
00002 * $Id: signalGutz.h,v 1.4 2003/09/22 09:28:34 jmk Exp $
00003 */
00004 ///////////////////////////////////////////////////////////////////////////
00005 //              _____________  ______________________    __   __  _____
00006 //             /  ________  |  |   ___   ________   /   |  \ /  \   |
00007 //            |  |       |  |_ |  |_ |  |       /  /    \__  |      |
00008 //            |  |  ___  |  || |  || |  |      /  /        | |      |
00009 //            |  | |   \ |  || |  || |  |     /  /      \__/ \__/ __|__
00010 //            |  | |_@  ||  || |  || |  |    /  /          Institute
00011 //            |  |___/  ||  ||_|  || |  |   /  /_____________________
00012 //             \_______/  \______/ | |__|  /___________________________
00013 //                        |  |__|  |
00014 //                         \______/
00015 //                    University of Utah       
00016 //                           2002
00017 //
00018 // By Joe Kniss, with help from Yarden Livnat
00019 ///////////////////////////////////////////////////////////////////////////
00020 
00021 //signalGutz.h
00022 
00023 //all of this is in the "gutz" namespace
00024 // having problems?? make sure you are "using namespace gutz;"
00025 // or "gutz::"
00026 
00027 #ifndef __GUTZ_SIGNAL_GUTZ_DOT_H
00028 #define __GUTZ_SIGNAL_GUTZ_DOT_H
00029 
00030 // You can quite comfortably ignore most of the classes in this framework
00031 // if you read the documentation in this file <signal.h> for Signal.  
00032 #include "../signalGutz/signal.h"
00033 
00034 namespace gutz {
00035 
00036 ////////////////////////////////////////////////////////////////////////////
00037 /// Connect, use this to connect a gutz::Signal to a slot (member function of a
00038 ///   class that has "HAS_SLOTS" declared).
00039 /// \code
00040 /// s        = the signal,                             ex: a.theSignal 
00041 ///                                                        (MyClassA instance)
00042 /// callee   = instance of the class recieving signal, ex: &b          
00043 ///                                                        (MyClassB instance)
00044 /// fncPtr   = the "slot",                             ex: &MyClassB::theSlot
00045 /// priority = the higher the number, the earlier it will be called
00046 /// \endcode
00047 /// 
00048 /// Although this is a template function, 
00049 /// the template parameters are resolved implicitly, so you can call "connect"
00050 /// without specifying any template parameters, ex: 
00051 /// \code connect(a.theSignal, &b, &myClassB::theSlot); \endcode
00052 /// 
00053 /// Here is another, more concrete, example using connect()
00054 /// \code
00055 ///   #include <signalGutz.h>
00056 ///   #include <iostream>
00057 ///   class MySlotClass {
00058 ///   public:
00059 ///     HAS_SLOTS;
00060 ///     void someSlot(float f) { std::cerr << "someSlot(f): f = " << f; }
00061 ///   };
00062 ///
00063 ///   class MySignalClass {
00064 ///   public:
00065 ///      gutz::Signal<float>  myFloatChanged;
00066 ///      void emmitMyFloat(float f) { myFloatChanged(f); }
00067 ///   };
00068 ///   
00069 ///   ///... in some function ... (main maybe?)
00070 ///   MySignalClass sigClass;
00071 ///   MySlotClass   slotClass;
00072 ///   /// connect sigClass.myFloatChanged to slotClass's slot "someSlot(f)"
00073 ///   gutz::connect(sigClass.myFloatChanged, &slotClass, &MySlotClass::someSlot);
00074 ///   /// send a signal
00075 ///   sigClass.emmitMyFloat(3.15159265);
00076 ///   /// should print "someSlot(f): f = 3.14159265" to stdout
00077 ///   /// now disconnect the sig/slot combo
00078 ///   gutz::disconnect(sigClass.myFloatChanged, &slotClass, &MySlotClass::someSlot);
00079 ///   /// try the signal again
00080 ///   sigClass.emmitMyFloat(2.7182818);
00081 ///   /// shouldn't print anything to stdout!
00082 /// \endcode
00083 /// see also gutz::Signal for more documetation on this API \n 
00084 /// see gutz::disconnect for the reverse of this function.
00085 ////////////////////////////////////////////////////////////////////////////
00086 template<class SIG, class CE, class F>
00087 void connect( SIG &s,          ///< the signal
00088               CE *callee,      ///< pointer to class with slot
00089               F fncPtr,        ///< member function of "callee" (the slot)
00090               int priority     ///< optional priority, higher = earlier called (defaults to 0)
00091              )
00092 {
00093    s.addCall(callee, fncPtr, priority);   
00094 }
00095 
00096 /// disconnect, the opposite of gutz::connect
00097 template<class SIG, class CE, class F>
00098 void disconnect( SIG &s,       ///< the signal
00099                  CE *callee,   ///< pointer to class with slot
00100                  F fncPtr      ///< member function of "callee" (the slot)
00101                 )
00102 {
00103    s.delCall(callee, fncPtr);   
00104 }
00105 
00106 } //< end namespace gutz
00107 
00108 #endif
00109 
00110 

Send questions, comments, and bug reports to:
jmk