fw4spl
Slots.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 #include "fwCom/Slot.hpp"
8 #include "fwCom/Slot.hxx"
9 
10 #include "fwCom/Slots.hpp"
11 
12 #include <fwThread/Worker.hpp>
13 
14 namespace fwCom
15 {
16 
18 {
19 }
20 
21 //-----------------------------------------------------------------------------
22 
24 {
25 #ifdef DEBUG
26  for( SlotMapType::value_type elem : m_slots )
27  {
28  SLM_ASSERT( "Slot '"<< elem.first <<"' has connected signals", elem.second->getNumberOfConnections() == 0 );
29  }
30 #endif
31 }
32 
33 //-----------------------------------------------------------------------------
34 
35 void Slots::setWorker( const ::fwThread::Worker::sptr &worker )
36 {
37  for( SlotMapType::value_type elem : m_slots )
38  {
39  elem.second->setWorker(worker);
40  }
41 }
42 
43 //-----------------------------------------------------------------------------
44 
45 Slots& Slots::operator()( const SlotKeyType &key, const SlotBase::sptr &slot )
46 {
47  m_slots.insert( SlotMapType::value_type(key, slot) );
48  return *this;
49 }
50 
51 //-----------------------------------------------------------------------------
52 
53 SlotBase::sptr Slots::operator[]( const SlotKeyType &key ) const
54 {
55  SlotMapType::const_iterator it = m_slots.find(key);
56 
57  if(it != m_slots.end())
58  {
59  return it->second;
60  }
61 
62  return SlotBase::sptr();
63 }
64 
65 //-----------------------------------------------------------------------------
66 
67 Slots::SlotKeyContainerType Slots::getSlotKeys() const
68 {
69  Slots::SlotKeyContainerType slotKeys;
70  for( SlotMapType::value_type elem : m_slots )
71  {
72  slotKeys.push_back(elem.first);
73  }
74  return slotKeys;
75 }
76 
77 //-----------------------------------------------------------------------------
78 
80 {
81 }
82 
83 //-----------------------------------------------------------------------------
84 
86 {
87  return *this;
88 }
89 
90 //-----------------------------------------------------------------------------
91 
92 
93 
94 } // namespace fwCom
95 
Slots & operator=(const Slots &)
Copy constructor forbidden.
Definition: Slots.cpp:85
Namespace containing fw4spl communication tools.
Definition: DumpEditor.hpp:30
SlotMapType m_slots
Association < key , SPTR( SlotBase ) >
Definition: Slots.hpp:80
virtual FWCOM_API ~Slots()
Constructor, check if all slots are disconnected.
Definition: Slots.cpp:23
This class proposes a mapping between a SlotKeyType and a SlotBase.
Definition: Slots.hpp:33
FWCOM_API SlotKeyContainerType getSlotKeys() const
Returns all SlotKeyType registered in m_slots.
Definition: Slots.cpp:67
#define SLM_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:308
FWCOM_API std::shared_ptr< SlotBase > operator[](const SlotKeyType &key) const
Returns the SlotBase associated to the key, if key does not exist, the ptr is null.
Definition: Slots.cpp:53
FWCOM_API Slots()
Constructor, does nothing.
Definition: Slots.cpp:17
FWCOM_API Slots & operator()(const SlotKeyType &key, const std::shared_ptr< SlotBase > &slot)
Registers SlotBase in m_slots.
FWCOM_API void setWorker(const std::shared_ptr< ::fwThread::Worker > &worker)
Assigns the worker to all slots stored in m_slots.
Definition: Slots.cpp:35