CommRaT 2.0.0
C++20 Real-Time Messaging Framework
Loading...
Searching...
No Matches
module_types.hpp
Go to the documentation of this file.
1#pragma once
2
9#include <tuple>
10#include <type_traits>
11
12namespace commrat {
13namespace module_traits {
14
15// ============================================================================
16// Phase 1: Type Computation Helpers (Extracted from registry_module.hpp)
17// ============================================================================
18
24template<typename...>
25struct HasPrimaryInputHelper : std::false_type {};
26
27template<typename T, typename... Rest>
28struct HasPrimaryInputHelper<PrimaryInput<T>, Rest...> : std::true_type {};
29
30template<typename First, typename... Rest>
31struct HasPrimaryInputHelper<First, Rest...> : HasPrimaryInputHelper<Rest...> {};
32
36template<typename...>
38 using type = void;
39};
40
41template<typename T, typename... Rest>
43 using type = T;
44};
45
46template<typename First, typename... Rest>
47struct ExtractPrimaryPayloadHelper<First, Rest...> : ExtractPrimaryPayloadHelper<Rest...> {};
48
52template<typename UserRegistry, typename OutputTypesTuple, typename... CommandTypes>
54
55template<typename UserRegistry, typename... OutputTypes, typename... CommandTypes>
56struct MakeMailboxSetTuple<UserRegistry, std::tuple<OutputTypes...>, CommandTypes...> {
57 using type = std::tuple<MailboxSet<UserRegistry, OutputTypes, CommandTypes...>...>;
58};
59
63template<typename UserRegistry, typename... Ts>
65
66template<typename UserRegistry, typename... Ts>
67struct MakeTypedCmdMailbox<UserRegistry, std::tuple<Ts...>> {
68 using type = std::conditional_t<
69 sizeof...(Ts) == 0,
70 RegistryMailbox<UserRegistry>, // No types → regular mailbox
71 TypedMailbox<UserRegistry, Ts...> // Has types → restrict
72 >;
73};
74
81template<typename UserRegistry, typename CommandTuple, typename OutputTuple>
83
84template<typename UserRegistry, typename... Commands, typename... Outputs>
85struct MakeTypedCmdMailboxWithSend<UserRegistry, std::tuple<Commands...>, std::tuple<Outputs...>> {
86 using type = std::conditional_t<
87 sizeof...(Commands) == 0 && sizeof...(Outputs) == 0,
88 TypedMailbox<UserRegistry>, // No types → empty TypedMailbox (shouldn't happen)
89 std::conditional_t<
90 sizeof...(Commands) == 0,
91 TypedMailbox<UserRegistry, SendOnlyTypes<Outputs...>>, // No commands, only send outputs
92 std::conditional_t<
93 sizeof...(Outputs) == 0,
94 TypedMailbox<UserRegistry, Commands...>, // Commands only, no send-only types needed
95 TypedMailbox<UserRegistry, ReceiveTypes<Commands...>, SendOnlyTypes<Outputs...>> // Commands receive, Outputs send-only
96 >
97 >
98 >;
99};
100
104template<typename T>
106 using type = std::tuple<>;
107};
108
109template<typename T>
111 using type = std::tuple<T>;
112};
113
114template<typename... Ts>
115struct ExtractDataTypes<Inputs<Ts...>> {
116 using type = std::tuple<Ts...>;
117};
118
122template<typename UserRegistry, typename Tuple>
124
125template<typename UserRegistry, typename... Ts>
126struct MakeTypedDataMailbox<UserRegistry, std::tuple<Ts...>> {
127 using type = std::conditional_t<
128 sizeof...(Ts) == 0,
129 RegistryMailbox<UserRegistry>, // No inputs → regular mailbox
130 TypedMailbox<UserRegistry, Ts...> // Has inputs → restrict to input types
131 >;
132};
133
134// ============================================================================
135// ModuleTypes: Central Type Computation
136// ============================================================================
137
149template<typename UserRegistry,
150 typename OutputSpec_,
151 typename InputSpec_,
152 typename... CommandTypes>
154 // Normalize specs: raw type T -> Output<T>, ContinuousInput<T> -> Input<T>
157
158 // Input type analysis
160 static constexpr size_t InputCount = std::tuple_size_v<InputTypesTuple>;
161 static constexpr bool has_multi_input = InputCount > 1;
162
163 // Primary input handling
164 static constexpr bool has_primary_input_spec = HasPrimaryInputHelper<CommandTypes...>::value;
165 using PrimaryPayloadType = typename ExtractPrimaryPayloadHelper<CommandTypes...>::type;
166
167 // Output type analysis
168 using OutputTypesTuple = typename ::commrat::OutputTypesTuple<OutputSpec>::type;
169 static constexpr size_t num_output_types = std::tuple_size_v<OutputTypesTuple>;
170 static constexpr bool has_multi_output = OutputCount_v<OutputSpec> > 1;
171
172 // Command type analysis
173 using CommandTuple = std::tuple<CommandTypes...>;
174 static constexpr size_t num_command_types = sizeof...(CommandTypes);
175
176 // Mailbox structure selection
177 static constexpr bool use_mailbox_sets = (num_output_types > 1);
178
179 // Generate MailboxSet tuple for multi-output
180 using MailboxSetTuple = typename MakeMailboxSetTuple<UserRegistry, OutputTypesTuple, CommandTypes...>::type;
181
182 // Mailbox types
183 using CombinedCmdTypes = decltype(std::tuple_cat(
184 std::declval<CommandTuple>(),
185 std::declval<OutputTypesTuple>()
186 ));
187
188 // CMD mailbox: Buffer sized for commands, can send commands + outputs
189 // Uses SendOnly<...> to mark output types as send-only (no buffer impact)
193
196
197 // Public type aliases (user-visible)
200
201 // Input mode flags
203 static constexpr bool has_periodic_input = std::is_same_v<InputSpec, PeriodicInput>;
204 static constexpr bool has_loop_input = std::is_same_v<InputSpec, LoopInput>;
205};
206
207} // namespace module_traits
208} // namespace commrat
Mailbox that takes a MessageRegistry and exposes payload-only interface.
Type-restricted mailbox with optimized buffer sizing.
Input/Output specifications for multi-I/O modules.
CommRaT - Modern C++ Real-Time Communication Framework.
typename NormalizeInput< T >::Type NormalizeInput_t
Definition io_spec.hpp:406
typename NormalizeOutput< T >::Type NormalizeOutput_t
Definition io_spec.hpp:425
@ Commands
Command messages.
Get the number of inputs in an InputSpec.
Definition io_spec.hpp:376
Single continuous input specification.
Definition io_spec.hpp:143
Multiple continuous inputs specification.
Definition io_spec.hpp:205
Complete set of mailboxes for one output type.
Multiple outputs specification.
Definition io_spec.hpp:94
Primary input designation for multi-input synchronization (Phase 6)
Definition io_spec.hpp:240
Tag type to mark send-only types in template parameter.
Extract data types from InputSpec for DATA mailbox.
Helper to extract primary payload type from CommandTypes.
Helper to check if there's an explicit PrimaryInput in CommandTypes.
std::tuple< MailboxSet< UserRegistry, OutputTypes, CommandTypes... >... > type
Generate MailboxSet tuple for each output type (Phase 7.4)
std::conditional_t< sizeof...(Commands)==0 &&sizeof...(Outputs)==0, TypedMailbox< UserRegistry >, std::conditional_t< sizeof...(Commands)==0, TypedMailbox< UserRegistry, SendOnlyTypes< Outputs... > >, std::conditional_t< sizeof...(Outputs)==0, TypedMailbox< UserRegistry, Commands... >, TypedMailbox< UserRegistry, ReceiveTypes< Commands... >, SendOnlyTypes< Outputs... > > > > > type
Create CMD mailbox with receive/send separation.
std::conditional_t< sizeof...(Ts)==0, RegistryMailbox< UserRegistry >, TypedMailbox< UserRegistry, Ts... > > type
Create typed CMD mailbox (Commands + Outputs)
std::conditional_t< sizeof...(Ts)==0, RegistryMailbox< UserRegistry >, TypedMailbox< UserRegistry, Ts... > > type
Create typed DATA mailbox (Input data types only)
Centralized type computation for Module class.
NormalizeOutput_t< OutputSpec_ > OutputSpec
static constexpr bool has_multi_output
typename ExtractInputTypes< InputSpec >::type InputTypesTuple
NormalizeInput_t< InputSpec_ > InputSpec
static constexpr size_t num_command_types
static constexpr bool has_periodic_input
typename ExtractPrimaryPayloadHelper< CommandTypes... >::type PrimaryPayloadType
typename MakeTypedCmdMailbox< UserRegistry, OutputTypesTuple >::type PublishMailbox
typename MakeTypedCmdMailboxWithSend< UserRegistry, CommandTuple, OutputTypesTuple >::type CmdMailbox
static constexpr bool has_continuous_input
typename ExtractDataTypes< InputSpec >::type DataTypesTuple
static constexpr bool has_primary_input_spec
static constexpr bool use_mailbox_sets
typename ExtractInputPayload< InputSpec >::type InputData
typename MakeTypedDataMailbox< UserRegistry, DataTypesTuple >::type DataMailbox
std::tuple< CommandTypes... > CommandTuple
typename MakeMailboxSetTuple< UserRegistry, OutputTypesTuple, CommandTypes... >::type MailboxSetTuple
static constexpr size_t num_output_types
typename ::commrat::OutputTypesTuple< OutputSpec >::type OutputTypesTuple
static constexpr bool has_multi_input
decltype(std::tuple_cat(std::declval< CommandTuple >(), std::declval< OutputTypesTuple >())) CombinedCmdTypes
typename ExtractOutputPayload< OutputSpec >::type OutputData
Type-restricted mailbox with optimized buffer sizing (Phase 7)