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