CLAM-Development  1.4.0
Signalv2ImplSerious.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __SIGNALV2IMPLSERIOUS__
23 #define __SIGNALV2IMPLSERIOUS__
24 
25 #ifndef __SIGNALV2__
26 #error "This is an internal implementation header. You are not allowed to include it directly!"
27 #endif
28 
29 #include "ConnectionHandler.hxx"
30 
31 namespace SigSlot
32 {
33 
34 template < typename ParmType1, typename ParmType2 >
35  class Signalv2 : public Signal
36 {
37 public:
38  typedef typename CBL::Functor2<ParmType1,ParmType2> tCallbackType;
39 
40 public:
41 
42  virtual ~Signalv2()
43  {
44  mSuper.DestroyConnections();
45  }
46 
47 
49  {
50  Connection c( AssignConnection(), this );
51 
52  mSuper.AddCallback( c.GetID(), &slot, slot.GetMethod() );
53 
54  slot.Bind(c);
55  }
56 
57  void Emit( ParmType1 parm1, ParmType2 parm2 )
58  {
59  if ( mSuper.HasNoCallbacks() )
60  return;
61 
62  typename tSuperType::tCallList calls = mSuper.GetCalls();
63  typename tSuperType::tCallIterator i = calls.begin();
64  typename tSuperType::tCallIterator end = calls.end();
65 
66  while ( i != end )
67  {
68  (*(*i))( parm1, parm2 );
69  i++;
70  }
71 
72  }
73 
74  void FreeConnection( Connection* pConnection )
75  {
76  mSuper.RemoveCall( pConnection->GetID() );
77  FreeConnectionId( pConnection->GetID() );
78  }
79 private:
80  typedef Signalv2<ParmType1,ParmType2> tSignalType;
81  typedef ConnectionHandler<tSignalType > tSuperType;
82 
83  tSuperType mSuper;
84 };
85 
86 }
87 
88 
89 #endif // Signalv2ImplSerious.hxx
90