aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
listener.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library 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 Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Class of listener.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  *
28  */
29 
30 #ifndef GUM_LISTENER_H
31 #define GUM_LISTENER_H
32 
33 #include <algorithm>
34 #include <vector>
35 
36 #include <agrum/agrum.h>
37 #include <agrum/tools/core/debug.h>
38 
39 namespace gum {
40 
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 
43  class Listener;
44 
45  namespace __sig__ {
46 
47  /**
48  * @class ISignaler
49  * @headerfile listener.h <agrum/tools/core/signal/listener.h>
50  * @brief Minimum specification of signaler in order to be contained in a
51  * listener.
52  * @ingroup signal_group
53  */
54  class ISignaler {
55  public:
56  virtual ~ISignaler(){};
57  virtual void detachFromTarget(Listener* target) = 0;
58  virtual void duplicateTarget(const Listener* oldtarget, Listener* newtarget) = 0;
59  virtual bool hasListener() = 0;
60  };
61  } // namespace __sig__
62 
63 #endif // DOXYGEN_SHOULD_SKIP_THIS
64 
65  /**
66  * @class Listener
67  * @headerfile listener.h <agrum/tools/core/signal/listener.h>
68  * @brief Every class who would catch signal from signaler should derive from
69  * Listener.
70  * @ingroup signal_group
71  */
72  class Listener {
73  private:
74  /// Alias for the list of signal senders.
76 
77  public:
78  /**
79  * @brief Class constructor.
80  */
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:
93  };
94 } // namespace gum
95 
96 #define GUM_CONNECT(sender, signal, receiver, target) (sender).signal.attach(&(receiver), &target)
97 
98 #ifndef GUM_NO_INLINE
99 # include <agrum/tools/core/signal/listener_inl.h>
100 #endif // GUM_NO_INLINE
101 
102 #endif // GUM_LISTENER_H
void _detachSignal_(__sig__::ISignaler *sender)
Definition: listener_inl.h:37
virtual ~Listener()
Definition: listener.cpp:47
Listener(const Listener &l)
Definition: listener.cpp:39
Internal namespace for aGrUM signaler/listener components.
Definition: agrum.h:28
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
void _attachSignal_(__sig__::ISignaler *sender)
Definition: listener_inl.h:35
Senders_list _senders_
Definition: listener.h:92
std::vector< __sig__::ISignaler *> Senders_list
Alias for the list of signal senders.
Definition: listener.h:75
Listener()
Class constructor.
Definition: listener.cpp:34
Every class who would catch signal from signaler should derive from Listener.
Definition: listener.h:72