CLAM-Development  1.4.0
Signalv1ImplSerious.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 __SIGNALV1IMPLSERIOUS__
23 #define __SIGNALV1IMPLSERIOUS__
24 
25 #ifndef __SIGNALV1__
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 >
35  class Signalv1 : public Signal
36 {
37 public:
38  typedef typename CBL::Functor1<ParmType1> tCallbackType;
39 
40 public:
41 
42  virtual ~Signalv1()
43  {
44  mSuper.DestroyConnections();
45  }
46 
47  void Connect( Slotv1<ParmType1>& slot )
48  {
49  Connection c( AssignConnection(), this );
50 
51  mSuper.AddCallback( c.GetID(), &slot, slot.GetMethod() );
52 
53  slot.Bind(c);
54  }
55 
56  void Emit( ParmType1 parm )
57  {
58  if ( mSuper.HasNoCallbacks() )
59  return;
60 
61  typename tSuperType::tCallList calls = mSuper.GetCalls();
62  typename tSuperType::tCallIterator i = calls.begin();
63  typename tSuperType::tCallIterator end = calls.end();
64 
65  while ( i != end )
66  {
67  (*(*i))( parm );
68  i++;
69  }
70 
71  }
72 
73  void FreeConnection( Connection* pConnection )
74  {
75  mSuper.RemoveCall( pConnection->GetID() );
76  FreeConnectionId( pConnection->GetID() );
77  }
78 private:
79  typedef Signalv1<ParmType1> tSignalType;
80  typedef ConnectionHandler<tSignalType > tSuperType;
81 
82  tSuperType mSuper;
83 };
84 
85 }
86 
87 #endif // Signalv1ImplSerious.hxx
88