CLAM-Development  1.4.0
ConnectionHandler.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 
25 #ifndef __CONNECTIONHANDLER__
26 #define __CONNECTIONHANDLER__
27 
28 #include <list>
29 #include <utility>
30 #include "Connection.hxx"
31 
38 namespace SigSlot
39 {
40  class Slot;
41 
56  template < class SignalType >
58  {
59  public:
61  typedef typename SignalType::tCallbackType tCallbackType;
63  typedef typename SignalType::tConnectionId tConnectionId;
64 
74  struct tCallback
75  {
79 
81  : mConnection( id ), mSlot( slot ), mCallback( cb )
82  {
83  }
84  };
85 
89 
92  typedef std::list<tCallbackPtr> tCallList;
93 
96  typedef typename std::list<tCallbackPtr >::iterator tCallIterator;
97 
100  typedef std::list<tCallback> tCallbackList;
101 
104  typedef typename std::list<tCallback>::iterator tCbListIterator;
105 
108  typedef typename std::list<tCallback>::const_iterator const_tCbListIterator;
109 
110 
111  public:
118  void AddCallback( tConnectionId pConnection, Slot* slot, tCallbackType cb )
119  {
120  mCallbacks.push_back( tCallback( pConnection, slot, cb ) );
121  }
122 
123 
128  bool HasNoCallbacks( ) const
129  {
130  return mCallbacks.empty();
131  }
132 
142  {
143  mCalls.clear();
144 
145  tCbListIterator i = mCallbacks.begin();
146  tCbListIterator end = mCallbacks.end();
147 
148  while ( i!=end)
149  {
150  mCalls.push_back( &(i->mCallback) );
151  i++;
152  }
153 
154  return mCalls;
155  }
156 
166  {
167  tCbListIterator i = mCallbacks.begin();
168  tCbListIterator end = mCallbacks.end();
169 
170  while ( i!=end )
171  {
172  if ( i->mConnection == id )
173  {
174  mCallbacks.erase( i );
175  break;
176  }
177  i++;
178  }
179  }
180 
186  {
187  tCbListIterator elem;
188 
189  while ( !mCallbacks.empty() )
190  {
191  elem = mCallbacks.begin();
192 
193  elem->mSlot->Unbind( elem->mConnection );
194  }
195  }
196 
197  private:
198 
199  tCallList mCalls;
200  tCallbackList mCallbacks;
202  };
203 
204 }
205 
206 #endif //ConnectionHandler.hxx
207