cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsMsgFactoryBase.h
1//
2// Copyright 2024 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7// This file is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "cc_tools_qt/ToolsMsgFactory.h"
23
24#include "comms/util/Tuple.h"
25
26#include <tuple>
27
28namespace cc_tools_qt
29{
30
31namespace details
32{
33
34class TupleMsgFactoryHelper
35{
36public:
37 using MessagesListInternal = std::vector<ToolsMessagePtr>;
38 TupleMsgFactoryHelper(MessagesListInternal& msgs) : m_msgs(msgs) {}
39
40 template <typename TMsg>
41 void operator()()
42 {
43 m_msgs.push_back(cc_tools_qt::ToolsMessagePtr(new TMsg));
44 }
45
46 MessagesListInternal& msgs()
47 {
48 return m_msgs;
49 }
50
51private:
52 MessagesListInternal& m_msgs;
53};
54
55} // namespace details
56
57template <typename TAllMessages>
58class ToolsMsgFactoryBase : public ToolsMsgFactory
59{
60public:
61 using AllMessages = TAllMessages;
62
63protected:
64 virtual MessagesListInternal createAllMessagesImpl() override
65 {
66 MessagesListInternal result;
67 static_assert(comms::util::IsTuple<TAllMessages>::Value, "TAllMessages must be std::tuple");
68 result.reserve(std::tuple_size<TAllMessages>::value);
69 comms::util::tupleForEachType<TAllMessages>(details::TupleMsgFactoryHelper(result));
70 return result;
71 }
72};
73
74} // namespace cc_tools_qt
75
Main namespace for all classes / functions of the shared library.
std::shared_ptr< ToolsMessage > ToolsMessagePtr
Smart pointer to ToolsMessage.
Definition ToolsMessage.h:165