aGrUM  0.13.2
listener.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
29 #ifndef GUM_LISTENER_H
30 #define GUM_LISTENER_H
31 
32 #include <algorithm>
33 #include <vector>
34 
35 #include <agrum/agrum.h>
36 #include <agrum/core/debug.h>
37 
38 namespace gum {
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 
42  class Listener;
43 
44  namespace __sig__ {
45 
53  class ISignaler {
54  public:
55  virtual ~ISignaler(){};
56  virtual void detachFromTarget(Listener* target) = 0;
57  virtual void duplicateTarget(const Listener* oldtarget,
58  Listener* newtarget) = 0;
59  virtual bool hasListener() = 0;
60  };
61  } // namespace __sig__
62 
63 #endif // DOXYGEN_SHOULD_SKIP_THIS
64 
72  class Listener {
73  private:
75  typedef std::vector< __sig__::ISignaler* > Senders_list;
76 
77  public:
81  Listener();
82 
83  Listener(const Listener& l);
84 
85  virtual ~Listener();
86 
87  void attachSignal__(__sig__::ISignaler* sender);
88 
89  void detachSignal__(__sig__::ISignaler* sender);
90 
91  private:
92  Senders_list __senders;
93  };
94 } // namespace gum
95 
96 #define GUM_CONNECT(sender, signal, receiver, target) \
97  (sender).signal.attach(&(receiver), &target)
98 
99 #ifndef GUM_NO_INLINE
101 #endif // GUM_NO_INLINE
102 
103 #endif // GUM_LISTENER_H
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
std::vector< __sig__::ISignaler * > Senders_list
Alias for the list of signal senders.
Definition: listener.h:75
Class of listener.
Senders_list __senders
Definition: listener.h:92
Every class who would catch signal from signaler should derive from Listener.
Definition: listener.h:72