COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
MsgIdLayerOptionsParser.h
1//
2// Copyright 2019 - 2025 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8#pragma once
9
10#include "comms/MsgFactory.h"
11#include "comms/options.h"
13
14#include <tuple>
15
16namespace comms
17{
18
19namespace frame
20{
21
22namespace details
23{
24
25
26template <typename... TOptions>
27class MsgIdLayerOptionsParser;
28
29template <>
30class MsgIdLayerOptionsParser<>
31{
32public:
33 static const bool HasExtendingClass = false;
34 static const bool HasMsgFactory = false;
35
36 using ExtendingClass = void;
37 using FactoryOptions = std::tuple<>;
38
39 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
40 using MsgFactory = comms::MsgFactory<TInterface, TAllMessages, TExtraOptions...>;
41
42 template <typename TLayer>
43 using DefineExtendingClass = TLayer;
44};
45
46template <typename T, typename... TOptions>
47class MsgIdLayerOptionsParser<comms::option::def::ExtendingClass<T>, TOptions...> :
48 public MsgIdLayerOptionsParser<TOptions...>
49{
50public:
51 static const bool HasExtendingClass = true;
52 using ExtendingClass = T;
53
54 template <typename TLayer>
55 using DefineExtendingClass = ExtendingClass;
56};
57
58template <typename TFactory, typename... TOptions>
59class MsgIdLayerOptionsParser<comms::option::app::MsgFactory<TFactory>, TOptions...> :
60 public MsgIdLayerOptionsParser<TOptions...>
61{
62public:
63 static const bool HasMsgFactory = true;
64
65 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
66 using MsgFactory = TFactory;
67};
68
69template <template<typename, typename, typename...> class TFactory, typename... TOptions>
70class MsgIdLayerOptionsParser<comms::option::app::MsgFactoryTempl<TFactory>, TOptions...> :
71 public MsgIdLayerOptionsParser<TOptions...>
72{
73 using BaseImpl = MsgIdLayerOptionsParser<TOptions...>;
74public:
75
76 static const bool HasMsgFactory = true;
77
78 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
79 using MsgFactory = TFactory<TInterface, TAllMessages, typename BaseImpl::FactoryOptions, TExtraOptions...>;
80};
81
82
83template <typename... TOptions>
84class MsgIdLayerOptionsParser<
85 comms::option::app::EmptyOption,
86 TOptions...> : public MsgIdLayerOptionsParser<TOptions...>
87{
88};
89
90template <typename... TBundledOptions, typename... TOptions>
91class MsgIdLayerOptionsParser<
92 std::tuple<TBundledOptions...>,
93 TOptions...> : public MsgIdLayerOptionsParser<TBundledOptions..., TOptions...>
94{
95};
96
97template <typename T, typename... TOptions>
98class MsgIdLayerOptionsParser<T, TOptions...> : public MsgIdLayerOptionsParser<TOptions...>
99{
100 using BaseImpl = MsgIdLayerOptionsParser<TOptions...>;
101public:
102 using FactoryOptions =
103 typename std::decay<
104 decltype(
105 std::tuple_cat(
106 std::declval<std::tuple<T> >(),
107 std::declval<typename BaseImpl::FactoryOptions>()
108 )
109 )
110 >::type;
111
112 // Ignoring all the options if MsgFactory is overriden
113 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
114 using MsgFactory =
116 BaseImpl::HasMsgFactory
117 >::template Type<
118 typename BaseImpl::template MsgFactory<TInterface, TAllMessages, FactoryOptions, TExtraOptions...>,
119 comms::MsgFactory<TInterface, TAllMessages, FactoryOptions, TExtraOptions...>
120 >;
121};
122
123} // namespace details
124
125} // namespace frame
126
127} // namespace comms
Contains definition of comms::MsgFactory class.
Message factory class.
Definition MsgFactory.h:87
comms::option::def::ExtendingClass< T > ExtendingClass
Same as comms::option::def::ExtendingClass.
Definition options.h:1949
Main namespace for all classes / functions of COMMS library.
STL namespace.
Contains definition of all the options used by the COMMS library.
Replacement to std::conditional.
Definition type_traits.h:29
Replacement to some types from standard type_traits.