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>
50template <
typename... Args>
54 return dw::core::make_tuple<Args...>(std::forward<Args>(args)...);
64template <
typename PortType,
size_t ArraySize>
77 ,
name{std::move(name_)}
84#define DW_PORT_TYPE_NAME_STRING_VIEW(TYPE_NAME_STR) TYPE_NAME_STR##_sv
85#define DW_DESCRIBE_PORT(TYPE_NAME, args...) dw::framework::describePort<TYPE_NAME>(DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
87template <
typename PortType>
99template <
typename PortType>
103 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
105 return describePort<PortType>(
112#define DW_DESCRIBE_PORT_ARRAY(TYPE_NAME, ARRAYSIZE, args...) dw::framework::describePortArray<TYPE_NAME, ARRAYSIZE>(DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
117 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
132 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
135 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
137 return describePortArray<PortType, ArraySize>(
146template <
typename Node>
154template <
typename Node>
165 typename std::enable_if_t<Direction == PortDirection::INPUT, void>* =
nullptr>
170 return describeInputPorts<Node>();
176 typename std::enable_if_t<Direction == PortDirection::OUTPUT, void>* =
nullptr>
181 return describeOutputPorts<Node>();
187template <
typename Node, PortDirection Direction>
191 return dw::core::tuple_size<decltype(describePorts<Node, Direction>())>::value;
195template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
198 constexpr size_t array_length{dw::core::tuple_element_t<
200 decltype(describePorts<Node, Direction>())>::arraySize};
201 return array_length > 0;
206template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
210 constexpr size_t array_length{dw::core::tuple_element_t<
212 decltype(describePorts<Node, Direction>())>::arraySize};
214 if (array_length == 0U)
223template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
226 constexpr PortBinding port_binding = dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()).binding;
231template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
234 constexpr dw::core::StringView port_comment = dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()).comment;
239template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
244 return typename dw::core::tuple_element_t<
246 decltype(describePorts<Node, Direction>())>::Type();
254 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
255 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
257constexpr std::size_t portSize_()
264 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
265 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
267 constexpr std::size_t portSize_()
269 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portSize_<Node, Direction, DescriptorIndex + 1>();
274template <
typename Node, PortDirection Direction>
278 return detail::portSize_<Node, Direction, 0>();
286 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
287 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
289constexpr std::size_t descriptorIndex_()
296 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
297 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
299 constexpr std::size_t descriptorIndex_()
302 if (RemainingPortIndex < descriptorPortSize<Node, Direction, DescriptorIndex>())
310 constexpr size_t remainingPortIndex{RemainingPortIndex - descriptorPortSize<Node, Direction, DescriptorIndex>()};
312 return 1U + descriptorIndex_<Node, Direction, DescriptorIndex + 1, remainingPortIndex>();
317template <
typename Node, PortDirection Direction,
size_t PortIndex>
323 return detail::descriptorIndex_<
Node, Direction, 0, PortIndex - portSize<Node, PortDirection::INPUT>()>();
325 return detail::descriptorIndex_<Node, Direction, 0, PortIndex>();
328template <
typename Node, PortDirection Direction,
size_t PortIndex>
334 constexpr size_t index{descriptorIndex<Node, Direction, PortIndex>()};
335 return dw::core::get<index>(describePorts<Node, Direction>()).name;
339template <
typename Node, PortDirection Direction,
size_t PortIndex>
346 constexpr size_t index{descriptorIndex<Node, Direction, PortIndex>()};
347 return portDescriptorType<Node, Direction, index>();
351template <
typename Node, PortDirection Direction>
358 return portID >= portSize<Node, PortDirection::INPUT>() && portID < portSize<Node, PortDirection::INPUT>() + portSize<Node, Direction>();
360 return portID < portSize<Node, Direction>();
368 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
369 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
370constexpr std::size_t portArraySize_(StringView identifier)
377 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
378 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
380 constexpr std::size_t portArraySize_(StringView identifier)
382 constexpr auto descriptorName = dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()).name;
383 if (descriptorName == identifier)
385 return descriptorPortSize<Node, Direction, DescriptorIndex>();
387 return portArraySize_<Node, Direction, DescriptorIndex + 1>(identifier);
392template <
typename Node, PortDirection Direction>
395 return detail::portArraySize_<Node, Direction, 0>(identifier);
403 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
404 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
406constexpr std::size_t portIndex_(StringView identifier)
408 static_cast<void>(identifier);
414 return dw::framework::portSize<Node, PortDirection::OUTPUT>();
421 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
422 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
424 constexpr std::size_t portIndex_(StringView identifier)
426 constexpr StringView descriptorName{dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()).name};
427 if (descriptorName == identifier)
432 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portIndex_<Node, Direction, DescriptorIndex + 1>(identifier);
437template <
typename Node, PortDirection Direction>
445 return portSize<Node, PortDirection::INPUT>() + detail::portIndex_<Node, Direction, 0>(identifier);
447 return detail::portIndex_<Node, Direction, 0>(identifier);
451template <
typename Node, PortDirection Direction>
454 constexpr size_t index = portIndex<Node, Direction>(identifier);
455 return isValidPortIndex<Node, Direction>(index);
463 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
464 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
465constexpr std::size_t portDescriptorIndex_(StringView identifier)
472 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
473 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
475 constexpr std::size_t portDescriptorIndex_(StringView identifier)
477 constexpr auto descriptorName = dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()).name;
478 if (descriptorName == identifier)
482 return 1 + portDescriptorIndex_<Node, Direction, DescriptorIndex + 1>(identifier);
487template <
typename Node, PortDirection Direction>
490 return detail::portDescriptorIndex_<Node, Direction, 0>(identifier);
constexpr auto describePort(dw::core::StringView typeName, dw::core::StringView name, PortBinding binding=PortBinding::OPTIONAL, dw::core::StringView comment=""_sv) -> PortDescriptorT< PortType, 0 >
constexpr auto describePorts()
constexpr auto describePortArray(dw::core::StringView typeName, dw::core::StringView name, PortBinding binding=PortBinding::OPTIONAL, dw::core::StringView comment=""_sv) -> PortDescriptorT< PortType, ArraySize >
constexpr bool descriptorPortArray()
constexpr size_t portIndex(StringView identifier)
constexpr size_t descriptorPortSize()
constexpr size_t portDescriptorIndex(StringView identifier)
constexpr auto portDescriptorType()
constexpr size_t portArraySize(StringView identifier)
constexpr std::size_t portDescriptorSize()
constexpr auto describeOutputPorts()
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 dw::core::StringView portName()
constexpr auto describeInputPorts()
constexpr bool isValidPortIdentifier(StringView identifier)
constexpr dw::core::StringView descriptorPortComment()
constexpr auto portType()
constexpr size_t descriptorIndex()
static constexpr size_t arraySize
dw::core::StringView typeName
dw::core::StringView comment
dw::core::StringView name
constexpr PortDescriptorT(dw::core::StringView const &&typeName_, dw::core::StringView const &&name_, PortBinding binding_=PortBinding::OPTIONAL, dw::core::StringView comment_=""_sv)