COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
MsgIdLayerOptionsParser.h
1//
2// Copyright 2019 - 2024 (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 <tuple>
12#include "comms/MsgFactory.h"
13#include "comms/options.h"
14
15namespace comms
16{
17
18namespace protocol
19{
20
21namespace details
22{
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
81
82template <typename... TOptions>
83class MsgIdLayerOptionsParser<
84 comms::option::app::EmptyOption,
85 TOptions...> : public MsgIdLayerOptionsParser<TOptions...>
86{
87};
88
89template <typename... TBundledOptions, typename... TOptions>
90class MsgIdLayerOptionsParser<
91 std::tuple<TBundledOptions...>,
92 TOptions...> : public MsgIdLayerOptionsParser<TBundledOptions..., TOptions...>
93{
94};
95
96template <typename T, typename... TOptions>
97class MsgIdLayerOptionsParser<T, TOptions...> : public MsgIdLayerOptionsParser<TOptions...>
98{
99 using BaseImpl = MsgIdLayerOptionsParser<TOptions...>;
100public:
101 using FactoryOptions =
102 typename std::decay<
103 decltype(
104 std::tuple_cat(
105 std::declval<std::tuple<T> >(),
106 std::declval<typename BaseImpl::FactoryOptions>()
107 )
108 )
109 >::type;
110
111 // Ignoring all the options if MsgFactory is overriden
112 template <typename TInterface, typename TAllMessages, typename... TExtraOptions>
113 using MsgFactory =
115 BaseImpl::HasMsgFactory
116 >::template Type<
117 typename BaseImpl::template MsgFactory<TInterface, TAllMessages, FactoryOptions, TExtraOptions...>,
118 comms::MsgFactory<TInterface, TAllMessages, FactoryOptions, TExtraOptions...>
119 >;
120};
121
122} // namespace details
123
124} // namespace protocol
125
126} // 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:1822
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:28
Replacement to some types from standard type_traits.