aGrUM  0.13.2
signaler0_inl.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 // To help IDE parsers
31 
32 namespace gum {
33 
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35  namespace __sig__ {
36 
37  INLINE
38  bool BasicSignaler0::hasListener() { return (!(_connectors.empty())); }
39 
40  INLINE
41  void BasicSignaler0::detach(Listener* target) {
42  auto it = std::find_if(
43  _connectors.begin(), _connectors.end(), __find_target(target));
44 
45  while (it != _connectors.end()) {
46  delete *it;
47  target->detachSignal__(this);
48 
49  it = _connectors.erase(it); // it is the next one
50  it = std::find_if(it, _connectors.end(), __find_target(target));
51  }
52  }
53 
54  INLINE
55  void BasicSignaler0::_detachFromTarget(Listener* target) {
56  auto it = std::find_if(
57  _connectors.begin(), _connectors.end(), __find_target(target));
58 
59  while (it != _connectors.end()) {
60  delete *it;
61 
62  it = _connectors.erase(it); // it is the next one
63  it = std::find_if(it, _connectors.end(), __find_target(target));
64  }
65  }
66 
67  INLINE
68  void BasicSignaler0::_duplicateTarget(const Listener* oldtarget,
69  Listener* newtarget) {
70  auto it = std::find_if(
71  _connectors.begin(), _connectors.end(), __find_target(oldtarget));
72 
73  while (it != _connectors.end()) {
74  _connectors.push_back((*it)->duplicate(newtarget));
75 
76  it++;
77  it = std::find_if(it, _connectors.end(), __find_target(oldtarget));
78  }
79  }
80 
81  INLINE
82  std::function< bool(IConnector0* el) >
83  BasicSignaler0::__find_target(const gum::Listener* l) {
84  return [=](IConnector0* el) -> bool { return el->target() == l; };
85  }
86 
87  } // namespace __sig__
88 #endif
89 
90 } // namespace gum
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Class of gum::Signaler0.
Every class who would catch signal from signaler should derive from Listener.
Definition: listener.h:72