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
25template <typename... TOptions>
26class MsgIdLayerOptionsParser;
27
28template <>
29class MsgIdLayerOptionsParser<>
30{
31public:
32 static const bool HasExtendingClass = false;
33 static const bool HasMsgFactory = false;
34
35 using ExtendingClass = void;
36 using FactoryOptions = std::tuple<>;
37
38 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
39 using MsgFactory = comms::MsgFactory<TInterface, TAllMessages, TExtraOptions...>;
40
41 template <typename TLayer>
42 using DefineExtendingClass = TLayer;
43};
44
45template <typename T, typename... TOptions>
46class MsgIdLayerOptionsParser<comms::option::def::ExtendingClass<T>, TOptions...> :
47 public MsgIdLayerOptionsParser<TOptions...>
48{
49public:
50 static const bool HasExtendingClass = true;
51 using ExtendingClass = T;
52
53 template <typename TLayer>
54 using DefineExtendingClass = ExtendingClass;
55};
56
57template <typename TFactory, typename... TOptions>
58class MsgIdLayerOptionsParser<comms::option::app::MsgFactory<TFactory>, TOptions...> :
59 public MsgIdLayerOptionsParser<TOptions...>
60{
61public:
62 static const bool HasMsgFactory = true;
63
64 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
65 using MsgFactory = TFactory;
66};
67
68template <template<typename, typename, typename...> class TFactory, typename... TOptions>
69class MsgIdLayerOptionsParser<comms::option::app::MsgFactoryTempl<TFactory>, TOptions...> :
70 public MsgIdLayerOptionsParser<TOptions...>
71{
72 using BaseImpl = MsgIdLayerOptionsParser<TOptions...>;
73public:
74
75 static const bool HasMsgFactory = true;
76
77 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
78 using MsgFactory = TFactory<TInterface, TAllMessages, typename BaseImpl::FactoryOptions, TExtraOptions...>;
79};
80
81template <typename... TOptions>
82class MsgIdLayerOptionsParser<
83 comms::option::app::EmptyOption,
84 TOptions...> : public MsgIdLayerOptionsParser<TOptions...>
85{
86};
87
88template <typename... TBundledOptions, typename... TOptions>
89class MsgIdLayerOptionsParser<
90 std::tuple<TBundledOptions...>,
91 TOptions...> : public MsgIdLayerOptionsParser<TBundledOptions..., TOptions...>
92{
93};
94
95template <typename T, typename... TOptions>
96class MsgIdLayerOptionsParser<T, TOptions...> : public MsgIdLayerOptionsParser<TOptions...>
97{
98 using BaseImpl = MsgIdLayerOptionsParser<TOptions...>;
99public:
100 using FactoryOptions =
101 typename std::decay<
102 decltype(
103 std::tuple_cat(
104 std::declval<std::tuple<T> >(),
105 std::declval<typename BaseImpl::FactoryOptions>()
106 )
107 )
108 >::type;
109
110 // Ignoring all the options if MsgFactory is overriden
111 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
112 using MsgFactory =
114 BaseImpl::HasMsgFactory
115 >::template Type<
116 typename BaseImpl::template MsgFactory<TInterface, TAllMessages, FactoryOptions, TExtraOptions...>,
117 comms::MsgFactory<TInterface, TAllMessages, FactoryOptions, TExtraOptions...>
118 >;
119};
120
121} // namespace details
122
123} // namespace frame
124
125} // 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:1960
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.