fw4spl
Slots.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 #ifndef __FWCOM_SLOTS_HPP__
8 #define __FWCOM_SLOTS_HPP__
9 
10 #include <map>
11 #include <vector>
12 #include <string>
13 
14 #include "fwCore/macros.hpp"
15 #include "fwCom/config.hpp"
16 
17 namespace fwThread
18 {
19 class Worker;
20 }
21 
22 namespace fwCom
23 {
24 
25 struct SlotBase;
26 
27 template< typename F >
28 class Slot;
29 
33 class FWCOM_CLASS_API Slots
34 {
35 public:
36 
37  typedef std::string SlotKeyType;
38  typedef std::map< SlotKeyType, SPTR( SlotBase ) > SlotMapType;
39  typedef std::vector < SlotKeyType > SlotKeyContainerType;
40 
42  FWCOM_API Slots();
43 
45  FWCOM_API virtual ~Slots();
46 
48  FWCOM_API Slots& operator()( const SlotKeyType& key, const SPTR( SlotBase )& slot );
49 
51  template<typename R, typename ... A>
52  Slots& operator()( const SlotKeyType& key, SPTR(Slot< R (A ...) >)slot )
53  {
54  SPTR( SlotBase ) slotBase = std::dynamic_pointer_cast< SlotBase >( slot );
55  return this->operator()(key, slotBase);
56  }
57 
59  template<typename F, typename ... A>
60  Slots& operator()( const SlotKeyType& key, F f, A ... a );
61 
63  FWCOM_API SPTR( SlotBase ) operator[]( const SlotKeyType &key ) const;
64 
66  FWCOM_API void setWorker( const SPTR(::fwThread::Worker)& worker );
67 
69  FWCOM_API SlotKeyContainerType getSlotKeys() const;
70 
71 protected:
72 
74  Slots( const Slots& );
75 
77  Slots& operator=( const Slots& );
78 
80  SlotMapType m_slots;
81 };
82 
83 } // namespace fwCom
84 
85 #endif //__FWCOM_SLOTS_HPP__
#define SPTR(_cls_)
Namespace containing fw4spl communication tools.
Definition: DumpEditor.hpp:30
Slots & operator()(const SlotKeyType &key, std::shared_ptr< Slot< R(A...) > >slot)
Registers Slot in m_slots (defined here to avoid compiler error C2244)
Definition: Slots.hpp:52
SlotMapType m_slots
Association < key , SPTR( SlotBase ) >
Definition: Slots.hpp:80
This file defines fwCore base macros.
This class proposes a mapping between a SlotKeyType and a SlotBase.
Definition: Slots.hpp:33
Base class for Slot implementations.
Definition: SlotBase.hpp:46
This class creates and manages a task loop. The default implementation create a loop in a new thread...
Definition: Worker.hpp:32
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...