31#ifndef DW_FRAMEWORK_PORTDESCRIPTOR_HPP_
32#define DW_FRAMEWORK_PORTDESCRIPTOR_HPP_
34#include <dw/core/container/StringView.hpp>
36#include <dw/core/language/cxx20.hpp>
37#include <dw/core/language/Tuple.hpp>
51template <
typename... Args>
54 return dw::core::make_tuple<Args...>(std::forward<Args>(args)...);
82#define DW_PORT_TYPE_NAME_STRING_VIEW(TYPE_NAME_STR) TYPE_NAME_STR##_sv
83#define DW_DESCRIBE_PORT(TYPE_NAME, args...) dw::framework::describePort<TYPE_NAME>(DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
85template <
typename PortType>
89 return std::make_tuple(
92 static_cast<PortType*
>(
nullptr),
93 static_cast<size_t>(0),
98template <
typename PortType>
102 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
104 return describePort<PortType>(
111#define DW_DESCRIBE_PORT_ARRAY(TYPE_NAME, ARRAYSIZE, args...) dw::framework::describePortArray<TYPE_NAME, ARRAYSIZE>(DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
116 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
120 return std::make_tuple(
123 static_cast<PortType*
>(
nullptr),
132 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
136 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
138 return describePortArray<PortType, ArraySize>(
147template <
typename Node>
153template <
typename Node>
162 typename std::enable_if_t<Direction == PortDirection::INPUT, void>* =
nullptr>
165 return describeInputPorts<Node>();
171 typename std::enable_if_t<Direction == PortDirection::OUTPUT, void>* =
nullptr>
176 return describeOutputPorts<Node>();
182template <
typename Node, PortDirection Direction>
185 return dw::core::tuple_size<decltype(describePorts<Node, Direction>())>::value;
189template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
192 constexpr size_t array_length = std::get<dw::framework::PORT_ARRAY_SIZE>(
193 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
194 return array_length > 0;
199template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
202 constexpr size_t array_length = std::get<dw::framework::PORT_ARRAY_SIZE>(
203 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
204 if (array_length == 0)
212template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
215 constexpr PortBinding port_binding = std::get<dw::framework::PORT_BINDING>(
216 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
221template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
224 constexpr dw::core::StringView port_comment = std::get<dw::framework::PORT_COMMENT>(
225 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
230template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
235 return std::remove_pointer_t<
236 typename std::tuple_element_t<
238 typename dw::core::tuple_element_t<
240 decltype(describePorts<Node, Direction>())>>>();
248 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
249 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
250constexpr std::size_t portSize_()
256 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
257 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
259 constexpr std::size_t portSize_()
261 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portSize_<Node, Direction, DescriptorIndex + 1>();
266template <
typename Node, PortDirection Direction>
269 return detail::portSize_<Node, Direction, 0>();
277 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
278 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
279constexpr std::size_t descriptorIndex_()
285 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
286 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
289 constexpr std::size_t descriptorIndex_()
291 if (RemainingPortIndex < descriptorPortSize<Node, Direction, DescriptorIndex>())
295 constexpr size_t remainingPortIndex = RemainingPortIndex - descriptorPortSize<Node, Direction, DescriptorIndex>();
296 return 1 + descriptorIndex_<Node, Direction, DescriptorIndex + 1, remainingPortIndex>();
301template <
typename Node, PortDirection Direction,
size_t PortIndex>
306 return detail::descriptorIndex_<
Node, Direction, 0, PortIndex - portSize<Node, PortDirection::INPUT>()>();
308 return detail::descriptorIndex_<Node, Direction, 0, PortIndex>();
312template <
typename Node, PortDirection Direction,
size_t PortIndex>
315 constexpr size_t index = descriptorIndex<Node, Direction, PortIndex>();
316 return portDescriptorType<Node, Direction, index>();
320template <
typename Node, PortDirection Direction>
327 return portID >= portSize<Node, PortDirection::INPUT>() && portID < portSize<Node, PortDirection::INPUT>() + portSize<Node, Direction>();
329 return portID < portSize<Node, Direction>();
337 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
338 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
339constexpr std::size_t portArraySize_(StringView identifier)
346 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
347 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
350 constexpr std::size_t portArraySize_(StringView identifier)
352 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
353 if (descriptorName == identifier)
355 return descriptorPortSize<Node, Direction, DescriptorIndex>();
357 return portArraySize_<Node, Direction, DescriptorIndex + 1>(identifier);
362template <
typename Node, PortDirection Direction>
365 return detail::portArraySize_<Node, Direction, 0>(identifier);
373 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
374 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
375constexpr std::size_t portIndex_(StringView identifier)
383 return dw::framework::portSize<Node, PortDirection::OUTPUT>();
389 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
390 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
393 constexpr std::size_t portIndex_(StringView identifier)
395 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
396 if (descriptorName == identifier)
400 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portIndex_<Node, Direction, DescriptorIndex + 1>(identifier);
405template <
typename Node, PortDirection Direction>
412 return portSize<Node, PortDirection::INPUT>() + detail::portIndex_<Node, Direction, 0>(identifier);
414 return detail::portIndex_<Node, Direction, 0>(identifier);
418template <
typename Node, PortDirection Direction>
421 constexpr size_t index = portIndex<Node, Direction>(identifier);
422 return isValidPortIndex<Node, Direction>(index);
430 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
431 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
432constexpr std::size_t portDescriptorIndex_(StringView identifier)
439 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
440 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
443 constexpr std::size_t portDescriptorIndex_(StringView identifier)
445 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
446 if (descriptorName == identifier)
450 return 1 + portDescriptorIndex_<Node, Direction, DescriptorIndex + 1>(identifier);
455template <
typename Node, PortDirection Direction>
458 return detail::portDescriptorIndex_<Node, Direction, 0>(identifier);
constexpr auto describePorts()
constexpr bool descriptorPortArray()
constexpr size_t portIndex(StringView identifier)
constexpr size_t descriptorPortSize()
constexpr size_t portDescriptorIndex(StringView identifier)
static constexpr size_t PORT_BINDING
constexpr auto portDescriptorType()
constexpr auto describePortCollection(Args &&... args)
constexpr size_t portArraySize(StringView identifier)
constexpr std::size_t portDescriptorSize()
constexpr auto describeOutputPorts()
static constexpr size_t PORT_NAME
static constexpr size_t PORT_COMMENT
static constexpr size_t PORT_ARRAY_SIZE
static constexpr size_t PORT_TYPE
constexpr bool isValidPortIndex(std::size_t portID)
constexpr std::size_t portSize()
constexpr PortBinding descriptorPortBinding()
static constexpr size_t PORT_TYPE_NAME
constexpr auto describePort(dw::core::StringView typeName, dw::core::StringView name, PortBinding binding=PortBinding::OPTIONAL, dw::core::StringView comment=""_sv)
constexpr auto describeInputPorts()
constexpr bool isValidPortIdentifier(StringView identifier)
constexpr dw::core::StringView descriptorPortComment()
constexpr auto portType()
constexpr size_t descriptorIndex()
constexpr auto describePortArray(dw::core::StringView typeName, dw::core::StringView name, PortBinding binding=PortBinding::OPTIONAL, dw::core::StringView comment=""_sv)