Compute Graph Framework SDK Reference  5.6
PortCollectionDescriptor.hpp
Go to the documentation of this file.
1
2//
3// Notice
4// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
5// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
6// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
7// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8//
9// NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
10// information or for any infringement of patents or other rights of third parties that may
11// result from its use. No license is granted by implication or otherwise under any patent
12// or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
13// expressly authorized by NVIDIA. Details are subject to change without notice.
14// This code supersedes and replaces all information previously supplied.
15// NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
16// components in life support devices or systems without express written approval of
17// NVIDIA CORPORATION & AFFILIATES.
18//
19// SPDX-FileCopyrightText: Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
20// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
21//
22// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
23// property and proprietary rights in and to this material, related
24// documentation and any modifications thereto. Any use, reproduction,
25// disclosure or distribution of this material and related documentation
26// without an express license agreement from NVIDIA CORPORATION or
27// its affiliates is strictly prohibited.
28//
30
31#ifndef DW_FRAMEWORK_PORTCOLLECTIONDESCRIPTOR_HPP_
32#define DW_FRAMEWORK_PORTCOLLECTIONDESCRIPTOR_HPP_
33
34#include <dwcgf/port/Port.hpp>
36
37#include <dw/core/container/BaseString.hpp>
38#include <dw/core/container/StringView.hpp>
39#include <dw/core/container/VectorFixed.hpp>
40#include <dw/core/language/Tuple.hpp>
41
42#include <string>
43#include <typeinfo>
44
46#define NODE_GET_INPUT_PORT_INDEX_EXTERNAL(NodeT, identifier) dw::framework::portIndex<NodeT, dw::framework::PortDirection::INPUT>(identifier)
48#define NODE_GET_OUTPUT_PORT_INDEX_EXTERNAL(NodeT, identifier) dw::framework::portIndex<NodeT, dw::framework::PortDirection::OUTPUT>(identifier)
49
50namespace dw
51{
52namespace framework
53{
54
56{
57public:
59 PortDirection direction, dw::core::StringView name,
60 dw::core::StringView typeName, size_t arraySize, bool bindingRequired,
61 dw::core::StringView comment);
63
64 const dw::core::StringView& getName() const;
65
66 const dw::core::StringView& getTypeName() const;
67
68 bool isArray() const;
69
70 size_t getArraySize() const;
71
72 bool isBindingRequired() const;
73
74 const dw::core::StringView& getComment() const;
75
76private:
77 PortDirection m_direction;
78 dw::core::StringView m_name;
79 dw::core::StringView m_typeName;
80 size_t m_arraySize;
81 bool m_bindingRequired;
82 dw::core::StringView m_comment;
83};
84
85static constexpr size_t MAX_PORT_DESCRIPTOR_PER_COLLECTION = 256U;
86
88{
89public:
90 PortCollectionDescriptor(PortDirection direction, size_t portOffset = 0);
91
93
94 size_t getDescriptorSize() const;
95
96 size_t getPortSize() const;
97
98 const PortDescriptor& getDescriptor(size_t index) const;
99
100 size_t getDescriptorIndex(const char* identifier) const;
101
102 const PortDescriptor& getDescriptor(const char* identifier) const;
103
104 size_t getPortIndex(const char* identifier) const;
105
106 bool isValid(size_t portIndex) const;
107
108 bool isValid(const char* identifier) const;
109
110 void addDescriptor(PortDescriptor&& descriptor);
111
112protected:
115 dw::core::VectorFixed<PortDescriptor, MAX_PORT_DESCRIPTOR_PER_COLLECTION> m_descriptors;
116};
117
118namespace detail
119{
120
121template <
122 typename NodeT, PortDirection Direction, size_t Index,
123 typename std::enable_if_t<Index == dw::core::tuple_size<decltype(describePorts<NodeT, Direction>())>::value, void>* = nullptr>
124void addDescriptors(PortCollectionDescriptor& d)
125{
126 (void)d;
127 return;
128}
129
130template <
131 typename NodeT, PortDirection Direction, size_t Index,
132 typename std::enable_if_t<Index<dw::core::tuple_size<decltype(describePorts<NodeT, Direction>())>::value, void>* = nullptr> void addDescriptors(PortCollectionDescriptor& d)
133{
134 constexpr auto t = dw::core::get<Index>(describePorts<NodeT, Direction>());
135 d.addDescriptor(PortDescriptor(
136 Direction,
137 std::get<PORT_NAME>(t).data(),
138 std::get<PORT_TYPE_NAME>(t).data(),
139 std::get<PORT_ARRAY_SIZE>(t),
140 std::get<PORT_BINDING>(t) == PortBinding::REQUIRED,
141 std::get<PORT_COMMENT>(t).data()));
142 addDescriptors<NodeT, Direction, Index + 1>(d);
143}
144
145} // namespace detail
146
147template <
148 typename NodeT, PortDirection Direction,
149 typename std::enable_if_t<Direction == PortDirection::INPUT, void>* = nullptr>
151{
152 PortCollectionDescriptor d(Direction);
153 detail::addDescriptors<NodeT, Direction, 0>(d);
154 return d;
155}
156
157template <
158 typename NodeT, PortDirection Direction,
159 typename std::enable_if_t<Direction == PortDirection::OUTPUT, void>* = nullptr>
160static PortCollectionDescriptor createPortCollectionDescriptor()
161{
162 PortCollectionDescriptor d(Direction, portSize<NodeT, PortDirection::INPUT>());
163 detail::addDescriptors<NodeT, Direction, 0>(d);
164 return d;
165}
166
167} // namespace framework
168} // namespace dw
169
170#endif // DW_FRAMEWORK_PORTCOLLECTIONDESCRIPTOR_HPP_
bool isValid(const char *identifier) const
PortCollectionDescriptor(PortDirection direction, size_t portOffset=0)
dw::core::VectorFixed< PortDescriptor, MAX_PORT_DESCRIPTOR_PER_COLLECTION > m_descriptors
const PortDescriptor & getDescriptor(const char *identifier) const
const PortDescriptor & getDescriptor(size_t index) const
void addDescriptor(PortDescriptor &&descriptor)
size_t getDescriptorIndex(const char *identifier) const
bool isValid(size_t portIndex) const
size_t getPortIndex(const char *identifier) const
PortDescriptor(PortDirection direction, dw::core::StringView name, dw::core::StringView typeName, size_t arraySize, bool bindingRequired, dw::core::StringView comment)
PortDirection getDirection() const
const dw::core::StringView & getName() const
const dw::core::StringView & getTypeName() const
const dw::core::StringView & getComment() const
constexpr size_t portIndex(StringView identifier)
static PortCollectionDescriptor createPortCollectionDescriptor()
static constexpr size_t MAX_PORT_DESCRIPTOR_PER_COLLECTION
Definition: Exception.hpp:47