fw4spl
Signals.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifdef DEBUG
8 #include "fwCore/spyLog.hpp"
9 #endif
10 
11 #include "fwCom/SignalBase.hpp"
12 #include "fwCom/Signals.hpp"
13 
14 namespace fwCom
15 {
16 
18 {
19 }
20 
21 //-----------------------------------------------------------------------------
22 
24 {
25 #ifdef DEBUG
26  for( SignalMapType::value_type elem : m_signals )
27  {
28  OSLM_ASSERT( "Signal '"<< elem.first <<"' has connected slots", elem.second->getNumberOfConnections() == 0 );
29  }
30 #endif
31 }
32 
33 //-----------------------------------------------------------------------------
34 
35 Signals& Signals::operator()( const SignalKeyType &key, const SignalBase::sptr &Signal )
36 {
37  m_signals.insert( SignalMapType::value_type(key, Signal) );
38  return *this;
39 }
40 
41 //-----------------------------------------------------------------------------
42 
43 SignalBase::sptr Signals::operator[]( const SignalKeyType &key ) const
44 {
45  SignalMapType::const_iterator it = m_signals.find(key);
46 
47  if(it != m_signals.end())
48  {
49  return it->second;
50  }
51 
52  return SignalBase::sptr();
53 }
54 
55 //-----------------------------------------------------------------------------
56 
57 Signals::SignalKeyContainerType Signals::getSignalKeys() const
58 {
59  Signals::SignalKeyContainerType SignalKeys;
60  for( SignalMapType::value_type elem : m_signals )
61  {
62  SignalKeys.push_back(elem.first);
63  }
64  return SignalKeys;
65 }
66 
67 //-----------------------------------------------------------------------------
68 
70 {
71 }
72 
73 //-----------------------------------------------------------------------------
74 
76 {
77  return *this;
78 }
79 
80 //-----------------------------------------------------------------------------
81 
82 } // namespace fwCom
83 
Signals & operator=(const Signals &)
Copy constructor forbidden.
Definition: Signals.cpp:75
FWCOM_API Signals & operator()(const SignalKeyType &key, const std::shared_ptr< SignalBase > &Signal)
Registers SignalBase in m_signals.
Definition: Signals.cpp:35
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
Namespace containing fw4spl communication tools.
Definition: DumpEditor.hpp:30
FWCOM_API Signals()
Constructor, does nothing.
Definition: Signals.cpp:17
This class proposes a mapping between a SignalKeyType and a SignalBase.
Definition: Signals.hpp:28
SignalMapType m_signals
Association < key , SPTR( SignalBase ) >
Definition: Signals.hpp:62
FWCOM_API SignalKeyContainerType getSignalKeys() const
Returns all SignalKeyType registered in m_signals.
Definition: Signals.cpp:57
virtual FWCOM_API ~Signals()
Constructor, check if all signals are disconnected.
Definition: Signals.cpp:23
FWCOM_API std::shared_ptr< SignalBase > operator[](const SignalKeyType &key) const
Returns the SignalBase associated to the key, if key does not exist, the ptr is null.
Definition: Signals.cpp:43
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...