CommRaT 2.0.0
C++20 Real-Time Messaging Framework
Loading...
Searching...
No Matches
input_metadata_accessors.hpp
Go to the documentation of this file.
1
9#pragma once
10
12#include <cstddef>
13#include <tuple>
14#include <type_traits>
15
16namespace commrat {
17
28template<typename ModuleType>
30protected:
31 // CRTP accessor to get derived module instance
32 ModuleType& module() { return static_cast<ModuleType&>(*this); }
33 const ModuleType& module() const { return static_cast<const ModuleType&>(*this); }
34
35public:
44 template<typename T>
46 uint64_t timestamp;
47 uint32_t sequence_number;
48 uint32_t message_id;
50 bool is_valid;
51
52 // Helper to get input type (for debugging/logging)
53 static constexpr const char* type_name() { return typeid(T).name(); }
54 };
55
77 template<std::size_t Index>
78 auto get_input_metadata() const {
79 constexpr std::size_t num_inputs = ModuleType::num_inputs;
80 static_assert(Index < num_inputs, "Input index out of bounds");
81
82 using InputType = std::conditional_t<
83 (num_inputs == 1),
84 typename ModuleType::InputData, // Single input: use InputData directly
85 std::tuple_element_t<Index, typename ModuleType::InputTypesTuple> // Multi-input: extract from tuple
86 >;
87
88 const auto& storage = module().input_metadata_[Index];
90 .timestamp = storage.timestamp,
91 .sequence_number = storage.sequence_number,
92 .message_id = storage.message_id,
93 .is_new_data = storage.is_new_data,
94 .is_valid = storage.is_valid
95 };
96 }
97
104 template<std::size_t Index>
105 uint64_t get_input_timestamp() const {
106 constexpr std::size_t num_inputs = ModuleType::num_inputs;
107 static_assert(Index < num_inputs, "Input index out of bounds");
108 return module().input_metadata_[Index].timestamp;
109 }
110
121 template<std::size_t Index>
122 bool has_new_data() const {
123 constexpr std::size_t num_inputs = ModuleType::num_inputs;
124 static_assert(Index < num_inputs, "Input index out of bounds");
125 return module().input_metadata_[Index].is_new_data;
126 }
127
137 template<std::size_t Index>
138 bool is_input_valid() const {
139 constexpr std::size_t num_inputs = ModuleType::num_inputs;
140 static_assert(Index < num_inputs, "Input index out of bounds");
141 return module().input_metadata_[Index].is_valid;
142 }
143
144 // ========================================================================
145 // Phase 6.10: Type-Based Metadata Accessors
146 // ========================================================================
147
165 template<typename T>
167 requires (ModuleType::num_inputs > 1) // Only for multi-input
168 {
169 constexpr std::size_t index = find_type_index<T,
170 typename std::tuple_element<0, typename ModuleType::InputTypesTuple>::type,
171 typename std::tuple_element<1, typename ModuleType::InputTypesTuple>::type
172 // TODO: Need to unpack full tuple, not just first 2 elements
173 >();
174 return get_input_metadata<index>();
175 }
176
180 template<typename T>
181 uint64_t get_input_timestamp() const
182 requires (ModuleType::num_inputs > 1)
183 {
184 constexpr std::size_t index = find_type_index<T,
185 typename std::tuple_element<0, typename ModuleType::InputTypesTuple>::type,
186 typename std::tuple_element<1, typename ModuleType::InputTypesTuple>::type
187 // TODO: Need to unpack full tuple
188 >();
189 return get_input_timestamp<index>();
190 }
191
195 template<typename T>
196 bool has_new_data() const
197 requires (ModuleType::num_inputs > 1)
198 {
199 constexpr std::size_t index = find_type_index<T,
200 typename std::tuple_element<0, typename ModuleType::InputTypesTuple>::type,
201 typename std::tuple_element<1, typename ModuleType::InputTypesTuple>::type
202 >();
203 return has_new_data<index>();
204 }
205
209 template<typename T>
210 bool is_input_valid() const
211 requires (ModuleType::num_inputs > 1)
212 {
213 constexpr std::size_t index = find_type_index<T,
214 typename std::tuple_element<0, typename ModuleType::InputTypesTuple>::type,
215 typename std::tuple_element<1, typename ModuleType::InputTypesTuple>::type
216 >();
217 return is_input_valid<index>();
218 }
219};
220
221} // namespace commrat
Mixin providing input metadata accessor methods.
uint64_t get_input_timestamp() const
Get input timestamp by index (convenience method)
uint64_t get_input_timestamp() const
Get input timestamp by type (convenience method)
bool is_input_valid() const
Check if input is valid by type.
bool has_new_data() const
Check if input has new data by type.
bool has_new_data() const
Check if input has new data by index.
bool is_input_valid() const
Check if input is valid by index.
CommRaT - Modern C++ Real-Time Communication Framework.
static constexpr std::size_t find_type_index()
Find index of type T in input tuple.
Input metadata structure returned by accessor methods.
bool is_new_data
True if freshly received, false if stale/reused.
uint64_t timestamp
Message timestamp (from TimsHeader)
bool is_valid
True if getData succeeded, false if failed.