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)...);
70#define _DW_PORT_TYPE_NAME_STRING_VIEW(TYPE_NAME_STR) TYPE_NAME_STR##_sv
71#define DW_DESCRIBE_PORT(TYPE_NAME, args...) dw::framework::describePort<TYPE_NAME>(_DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
73template <
typename PortType>
77 return std::make_tuple(
80 static_cast<PortType*
>(
nullptr),
81 static_cast<size_t>(0),
86template <
typename PortType>
88 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
90 return describePort<PortType>(
97#define DW_DESCRIBE_PORT_ARRAY(TYPE_NAME, ARRAYSIZE, args...) dw::framework::describePortArray<TYPE_NAME, ARRAYSIZE>(_DW_PORT_TYPE_NAME_STRING_VIEW(#TYPE_NAME), ##args)
102 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
106 return std::make_tuple(
109 static_cast<PortType*
>(
nullptr),
118 typename std::enable_if_t<ArraySize != 0, void>* =
nullptr>
120 dw::core::StringView typeName, dw::core::StringView name, dw::core::StringView comment)
122 return describePortArray<PortType, ArraySize>(
131template <
typename Node>
137template <
typename Node>
146 typename std::enable_if_t<Direction == PortDirection::INPUT, void>* =
nullptr>
149 return describeInputPorts<Node>();
155 typename std::enable_if_t<Direction == PortDirection::OUTPUT, void>* =
nullptr>
158 return describeOutputPorts<Node>();
164template <
typename Node, PortDirection Direction>
167 return dw::core::tuple_size<decltype(describePorts<Node, Direction>())>::value;
171template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
174 constexpr size_t array_length = std::get<dw::framework::PORT_ARRAY_SIZE>(
175 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
176 return array_length > 0;
181template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
184 constexpr size_t array_length = std::get<dw::framework::PORT_ARRAY_SIZE>(
185 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
186 if (array_length == 0)
194template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
197 constexpr PortBinding port_binding = std::get<dw::framework::PORT_BINDING>(
198 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
203template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
206 constexpr dw::core::StringView port_comment = std::get<dw::framework::PORT_COMMENT>(
207 dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
212template <
typename Node, PortDirection Direction,
size_t DescriptorIndex>
217 return std::remove_pointer_t<
218 typename std::tuple_element_t<
220 typename dw::core::tuple_element_t<
222 decltype(describePorts<Node, Direction>())>>>();
230 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
231 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
238 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
239 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
constexpr std::size_t
portSize()
241 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portSize<Node, Direction, DescriptorIndex + 1>();
246template <
typename Node, PortDirection Direction>
249 return detail::portSize<Node, Direction, 0>();
257 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
258 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
265 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
size_t RemainingPortIndex,
266 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
constexpr std::size_t
descriptorIndex()
268 if (RemainingPortIndex < descriptorPortSize<Node, Direction, DescriptorIndex>())
272 constexpr size_t remainingPortIndex = RemainingPortIndex - descriptorPortSize<Node, Direction, DescriptorIndex>();
273 return 1 + descriptorIndex<Node, Direction, DescriptorIndex + 1, remainingPortIndex>();
278template <
typename Node, PortDirection Direction,
size_t PortIndex>
285 return detail::descriptorIndex<Node, Direction, 0, PortIndex>();
289template <
typename Node, PortDirection Direction,
size_t PortIndex>
292 constexpr size_t index = descriptorIndex<Node, Direction, PortIndex>();
293 return portDescriptorType<Node, Direction, index>();
297template <
typename Node, PortDirection Direction>
304 return portID >= portSize<Node, PortDirection::INPUT>() && portID < portSize<Node, PortDirection::INPUT>() + portSize<Node, Direction>();
306 return portID < portSize<Node, Direction>();
314 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
315 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
323 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
324 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
constexpr std::size_t
portArraySize(StringView identifier)
326 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
327 if (descriptorName == identifier)
329 return descriptorPortSize<Node, Direction, DescriptorIndex>();
331 return portArraySize<Node, Direction, DescriptorIndex + 1>(identifier);
336template <
typename Node, PortDirection Direction>
339 return detail::portArraySize<Node, Direction, 0>(identifier);
347 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
348 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
349constexpr std::size_t
portIndex(StringView identifier)
357 return dw::framework::portSize<Node, PortDirection::OUTPUT>();
363 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
364 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
constexpr std::size_t
portIndex(StringView identifier)
366 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
367 if (descriptorName == identifier)
371 return descriptorPortSize<Node, Direction, DescriptorIndex>() + portIndex<Node, Direction, DescriptorIndex + 1>(identifier);
376template <
typename Node, PortDirection Direction>
383 return portSize<Node, PortDirection::INPUT>() + detail::portIndex<Node, Direction, 0>(identifier);
385 return detail::portIndex<Node, Direction, 0>(identifier);
389template <
typename Node, PortDirection Direction>
392 constexpr size_t index = portIndex<Node, Direction>(identifier);
393 return isValidPort<Node, Direction>(index);
401 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
402 typename std::enable_if_t<DescriptorIndex == portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
410 typename Node,
PortDirection Direction,
size_t DescriptorIndex,
411 typename std::enable_if_t<DescriptorIndex<portDescriptorSize<Node, Direction>(),
void>* =
nullptr>
constexpr std::size_t
portDescriptorIndex(StringView identifier)
413 constexpr auto descriptorName = std::get<dw::framework::PORT_NAME>(dw::core::get<DescriptorIndex>(describePorts<Node, Direction>()));
414 if (descriptorName == identifier)
418 return 1 + portDescriptorIndex<Node, Direction, DescriptorIndex + 1>(identifier);
423template <
typename Node, PortDirection Direction>
426 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 bool isValidPort(std::size_t portID)
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 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 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)