00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #ifndef __SIGNALV2IMPLSERIOUS__ 00023 #define __SIGNALV2IMPLSERIOUS__ 00024 00025 #ifndef __SIGNALV2__ 00026 #error "This is an internal implementation header. You are not allowed to include it directly!" 00027 #endif 00028 00029 #include "ConnectionHandler.hxx" 00030 00031 namespace SigSlot 00032 { 00033 00034 template < typename ParmType1, typename ParmType2 > 00035 class Signalv2 : public Signal 00036 { 00037 public: 00038 typedef typename CBL::Functor2<ParmType1,ParmType2> tCallbackType; 00039 00040 public: 00041 00042 virtual ~Signalv2() 00043 { 00044 mSuper.DestroyConnections(); 00045 } 00046 00047 00048 void Connect( Slotv2<ParmType1,ParmType2>& slot ) 00049 { 00050 Connection c( AssignConnection(), this ); 00051 00052 mSuper.AddCallback( c.GetID(), &slot, slot.GetMethod() ); 00053 00054 slot.Bind(c); 00055 } 00056 00057 void Emit( ParmType1 parm1, ParmType2 parm2 ) 00058 { 00059 if ( mSuper.HasNoCallbacks() ) 00060 return; 00061 00062 typename tSuperType::tCallList calls = mSuper.GetCalls(); 00063 typename tSuperType::tCallIterator i = calls.begin(); 00064 typename tSuperType::tCallIterator end = calls.end(); 00065 00066 while ( i != end ) 00067 { 00068 (*(*i))( parm1, parm2 ); 00069 i++; 00070 } 00071 00072 } 00073 00074 void FreeConnection( Connection* pConnection ) 00075 { 00076 mSuper.RemoveCall( pConnection->GetID() ); 00077 FreeConnectionId( pConnection->GetID() ); 00078 } 00079 private: 00080 typedef Signalv2<ParmType1,ParmType2> tSignalType; 00081 typedef ConnectionHandler<tSignalType > tSuperType; 00082 00083 tSuperType mSuper; 00084 }; 00085 00086 } 00087 00088 00089 #endif // Signalv2ImplSerious.hxx 00090