aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
listener.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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)
59  = 0;
60  virtual bool hasListener() = 0;
61  };
62  } // namespace __sig__
63 
64 #endif // DOXYGEN_SHOULD_SKIP_THIS
65 
66  /**
67  * @class Listener
68  * @headerfile listener.h <agrum/tools/core/signal/listener.h>
69  * @brief Every class who would catch signal from signaler should derive from
70  * Listener.
71  * @ingroup signal_group
72  */
73  class Listener {
74  private:
75  /// Alias for the list of signal senders.
77 
78  public:
79  /**
80  * @brief Class constructor.
81  */
82  Listener();
83 
84  Listener(const Listener& l);
85 
86  virtual ~Listener();
87 
88  void attachSignal__(__sig__::ISignaler* sender);
89 
90  void detachSignal__(__sig__::ISignaler* sender);
91 
92  private:
94  };
95 } // namespace gum
96 
97 #define GUM_CONNECT(sender, signal, receiver, target)
98  (sender).signal.attach(&(receiver), &target)
99 
100 #ifndef GUM_NO_INLINE
101 # include <agrum/tools/core/signal/listener_inl.h>
102 #endif // GUM_NO_INLINE
103 
104 #endif // GUM_LISTENER_H
Senders_list senders__
Definition: listener.h:93
virtual ~Listener()
Definition: listener.cpp:44
Listener(const Listener &l)
Definition: listener.cpp:36
Internal namespace for aGrUM signaler/listener components.
Definition: agrum.h:28
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
void attachSignal__(__sig__::ISignaler *sender)
Definition: listener_inl.h:35
std::vector< __sig__::ISignaler *> Senders_list
Alias for the list of signal senders.
Definition: listener.h:76
Listener()
Class constructor.
Definition: listener.cpp:34
Every class who would catch signal from signaler should derive from Listener.
Definition: listener.h:73
void detachSignal__(__sig__::ISignaler *sender)
Definition: listener_inl.h:39