31#ifndef DW_FRAMEWORK_PORTDESCRIPTOR_HPP_
32#define DW_FRAMEWORK_PORTDESCRIPTOR_HPP_
34#include <dwshared/dwfoundation/dw/core/container/StringView.hpp>
36#include <dwshared/dwfoundation/dw/core/language/cxx20.hpp>
37#include <dwshared/dwfoundation/dw/core/language/Tuple.hpp>
51template <
typename... Args>
55 return dw::core::make_tuple<Args...>(std::forward<Args>(args)...);
83#define DW_PORT_TYPE_NAME_STRING_VIEW(TYPE_NAME_STR) TYPE_NAME_STR##_sv
84#define DW_DESCRIBE_PORT(TYPE_NAME, args...) dw::framework::describePort<TYPE_NAME>(DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
86template <
typename PortType>
89 dw::core::StringView typeName, dw::core::StringView name,
PortBinding binding =
PortBinding::OPTIONAL, dw::core::StringView comment =
""_sv) -> std::tuple<dw::core::StringView, dw::core::StringView, PortType*, size_t, PortBinding, dw::core::StringView>
91 return std::make_tuple(
94 static_cast<PortType*
>(
nullptr),
95 static_cast<size_t>(0),
100template <
typename PortType>
104 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
106 return describePort<PortType>(
113#define DW_DESCRIBE_PORT_ARRAY(TYPE_NAME, ARRAYSIZE, args...) dw::framework::describePortArray<TYPE_NAME, ARRAYSIZE>(DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
118 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
121 dw::core::StringView typeName, dw::core::StringView name,
PortBinding binding =
PortBinding::OPTIONAL, dw::core::StringView comment =
""_sv) -> std::tuple<dw::core::StringView, dw::core::StringView, PortType*, size_t, PortBinding, dw::core::StringView>
123 return std::make_tuple(
126 static_cast<PortType*
>(
nullptr),
135 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
138 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
140 return describePortArray<PortType, ArraySize>(
149template <
typename Node>
157template <
typename Node>
168 typename std::enable_if_t<Direction == PortDirection::INPUT, void>* =
nullptr>
173 return describeInputPorts<Node>();
179 typename std::enable_if_t<Direction == PortDirection::OUTPUT, void>* =
nullptr>
184 return describeOutputPorts<Node>();
190template <
typename Node, PortDirection Direction>
194 return dw::core::tuple_size<decltype(describePorts<Node, Direction>())>::value;
198template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
201 constexpr size_t array_length = std::get<dw::framework::PORT_ARRAY_SIZE>(
202 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
203 return array_length > 0;
208template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
212 constexpr size_t array_length{std::get<dw::framework::PORT_ARRAY_SIZE>(
213 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()))};
215 if (array_length == 0U)
224template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
227 constexpr PortBinding port_binding = std::get<dw::framework::PORT_BINDING>(
228 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
233template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
236 constexpr dw::core::StringView port_comment = std::get<dw::framework::PORT_COMMENT>(
237 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
242template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
249 return std::remove_pointer_t<
250 typename std::tuple_element_t<
252 typename dw::core::tuple_element_t<
254 decltype(describePorts<Node, Direction>())>>>();
262 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
263 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
265constexpr std::size_t portSize_()
272 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
273 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
275 constexpr std::size_t portSize_()
277 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portSize_<Node, Direction, DescriptorIndex + 1>();
282template <
typename Node, PortDirection Direction>
286 return detail::portSize_<Node, Direction, 0>();
294 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
295 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
297constexpr std::size_t descriptorIndex_()
304 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
305 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
307 constexpr std::size_t descriptorIndex_()
310 if (RemainingPortIndex < descriptorPortSize<Node, Direction, DescriptorIndex>())
318 constexpr size_t remainingPortIndex{RemainingPortIndex - descriptorPortSize<Node, Direction, DescriptorIndex>()};
320 return 1U + descriptorIndex_<Node, Direction, DescriptorIndex + 1, remainingPortIndex>();
325template <
typename Node, PortDirection Direction,
size_t PortIndex>
331 return detail::descriptorIndex_<
Node, Direction, 0, PortIndex - portSize<Node, PortDirection::INPUT>()>();
333 return detail::descriptorIndex_<Node, Direction, 0, PortIndex>();
337template <
typename Node, PortDirection Direction,
size_t PortIndex>
344 constexpr size_t index{descriptorIndex<Node, Direction, PortIndex>()};
345 return portDescriptorType<Node, Direction, index>();
349template <
typename Node, PortDirection Direction>
356 return portID >= portSize<Node, PortDirection::INPUT>() && portID < portSize<Node, PortDirection::INPUT>() + portSize<Node, Direction>();
358 return portID < portSize<Node, Direction>();
366 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
367 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
368constexpr std::size_t portArraySize_(StringView identifier)
375 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
376 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
378 constexpr std::size_t portArraySize_(StringView identifier)
380 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
381 if (descriptorName == identifier)
383 return descriptorPortSize<Node, Direction, DescriptorIndex>();
385 return portArraySize_<Node, Direction, DescriptorIndex + 1>(identifier);
390template <
typename Node, PortDirection Direction>
393 return detail::portArraySize_<Node, Direction, 0>(identifier);
401 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
402 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
404constexpr std::size_t portIndex_(StringView identifier)
406 static_cast<void>(identifier);
412 return dw::framework::portSize<Node, PortDirection::OUTPUT>();
419 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
420 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
422 constexpr std::size_t portIndex_(StringView identifier)
424 constexpr StringView descriptorName{std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()))};
425 if (descriptorName == identifier)
430 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portIndex_<Node, Direction, DescriptorIndex + 1>(identifier);
435template <
typename Node, PortDirection Direction>
443 return portSize<Node, PortDirection::INPUT>() + detail::portIndex_<Node, Direction, 0>(identifier);
445 return detail::portIndex_<Node, Direction, 0>(identifier);
449template <
typename Node, PortDirection Direction>
452 constexpr size_t index = portIndex<Node, Direction>(identifier);
453 return isValidPortIndex<Node, Direction>(index);
461 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
462 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
463constexpr std::size_t portDescriptorIndex_(StringView identifier)
470 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
471 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
473 constexpr std::size_t portDescriptorIndex_(StringView identifier)
475 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
476 if (descriptorName == identifier)
480 return 1 + portDescriptorIndex_<Node, Direction, DescriptorIndex + 1>(identifier);
485template <
typename Node, PortDirection Direction>
488 return detail::portDescriptorIndex_<Node, Direction, 0>(identifier);
constexpr auto describePorts()
constexpr bool descriptorPortArray()
constexpr size_t portIndex(StringView identifier)
constexpr size_t descriptorPortSize()
constexpr auto describePortArray(dw::core::StringView typeName, dw::core::StringView name, PortBinding binding=PortBinding::OPTIONAL, dw::core::StringView comment=""_sv) -> std::tuple< dw::core::StringView, dw::core::StringView, PortType *, size_t, PortBinding, dw::core::StringView >
constexpr size_t portDescriptorIndex(StringView identifier)
static constexpr const size_t PORT_TYPE
static constexpr const size_t PORT_COMMENT
constexpr auto portDescriptorType()
constexpr size_t portArraySize(StringView identifier)
constexpr std::size_t portDescriptorSize()
constexpr auto describeOutputPorts()
constexpr auto describePort(dw::core::StringView typeName, dw::core::StringView name, PortBinding binding=PortBinding::OPTIONAL, dw::core::StringView comment=""_sv) -> std::tuple< dw::core::StringView, dw::core::StringView, PortType *, size_t, PortBinding, dw::core::StringView >
constexpr auto describePortCollection(Args &&... args) -> dw::core::Tuple< Args... >
constexpr bool isValidPortIndex(std::size_t portID)
constexpr std::size_t portSize()
constexpr PortBinding descriptorPortBinding()
constexpr auto describeInputPorts()
static constexpr const size_t PORT_ARRAY_SIZE
static constexpr const size_t PORT_BINDING
constexpr bool isValidPortIdentifier(StringView identifier)
constexpr dw::core::StringView descriptorPortComment()
constexpr auto portType()
constexpr size_t descriptorIndex()
static constexpr const size_t PORT_TYPE_NAME
static constexpr const size_t PORT_NAME