GCC Code Coverage Report


./
File: libs/__/core/com/slots.hpp
Date: 2025-01-21 16:21:04
Lines:
6/6
100.0%
Functions:
49/59
83.1%
Branches:
5/10
50.0%

Line Branch Exec Source
1 /************************************************************************
2 *
3 * Copyright (C) 2009-2024 IRCAD France
4 * Copyright (C) 2012-2019 IHU Strasbourg
5 *
6 * This file is part of Sight.
7 *
8 * Sight is free software: you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Sight is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
20 *
21 ***********************************************************************/
22
23 #pragma once
24
25 #define FWCOM_SLOTS_HPP
26
27 #include <sight/core/config.hpp>
28
29 #include "core/macros.hpp"
30 #include "core/thread/worker.hpp"
31
32 #include <map>
33 #include <string>
34 #include <vector>
35
36 namespace sight::core::thread
37 {
38
39 class worker;
40
41 } // namespace sight::core::thread
42
43 namespace sight::core::com
44 {
45
46 struct slot_base;
47
48 template<typename F>
49 class slot;
50
51 /**
52 * @brief This class proposes a storage for slots.
53 */
54 class SIGHT_CORE_CLASS_API slots : public std::map<std::string,
55 SPTR(slot_base)>
56 {
57 public:
58
59 using key_t = std::string;
60 using slot_key_type = key_t;
61 using slot_key_container_t = std::vector<key_t>;
62
63
3/6
✓ Branch 1 taken 3575 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
3577 SIGHT_CORE_API slots() = default;
64 3576 SIGHT_CORE_API virtual ~slots() = default;
65
66 /// Copy constructor forbidden
67 slots(const slots& /*unused*/) = delete;
68
69 /// Registers SlotBase in m_slots
70 SIGHT_CORE_API slots& operator()(const key_t& _key, const SPTR(slot_base)& _slot);
71
72 /// Registers Slot in m_slots (defined here to avoid compiler error C2244)
73 template<typename R, typename ... A>
74 33745 slots& operator()(const key_t& _key, SPTR(slot<R(A ...)>)_slot)
75 {
76 33745 SPTR(slot_base) base = std::dynamic_pointer_cast<slot_base>(_slot);
77
2/4
✓ Branch 1 taken 18429 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18429 times.
✗ Branch 4 not taken.
33745 return this->operator()(_key, base);
78 33745 }
79
80 /// Returns the SlotBase associated to the key, if key does not exist, the ptr is null
81 SIGHT_CORE_API SPTR(slot_base) operator[](const key_t& _key) const;
82
83 /// Assigns the worker to all slots stored in m_slots
84 SIGHT_CORE_API void set_worker(const SPTR(core::thread::worker)& _worker);
85
86 /// Returns all key_t registered in m_slots
87 [[nodiscard]] SIGHT_CORE_API slot_key_container_t get_slot_keys() const;
88 };
89
90 } // namespace sight::core::com
91