• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.22
    All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    ParameterCollectionDescriptor.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-2024 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_PARAMETERCOLLECTIONDESCRIPTOR_HPP_
    32#define DW_FRAMEWORK_PARAMETERCOLLECTIONDESCRIPTOR_HPP_
    33
    35
    36#include <dwshared/dwfoundation/dw/core/container/VectorFixed.hpp>
    37
    38#include <modern-json/json.hpp>
    39
    40#include <memory>
    41
    42namespace dw
    43{
    44namespace framework
    45{
    46
    49{
    50public:
    53 dw::core::StringView const& name,
    54 dw::core::StringView const& typeName,
    55 const bool isIndex,
    56 size_t const arraySize) noexcept;
    58 virtual ~ParameterDescriptor() = default;
    68 dw::core::StringView const& getName() const noexcept;
    70 dw::core::StringView const& getTypeName() const noexcept;
    72 bool isIndex() const noexcept;
    74 size_t getArraySize() const noexcept;
    76 virtual void addDefault(nlohmann::ordered_json& object) const;
    77
    78private:
    80 dw::core::StringView m_name;
    82 dw::core::StringView m_typeName;
    84 bool m_isIndex;
    86 size_t m_arraySize;
    87};
    88
    89namespace detail
    90{
    91
    93template <
    94 typename DefaultType,
    95 std::enable_if_t<
    96 !std::is_enum<DefaultType>::value>* = nullptr>
    97// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    98nlohmann::json getDefaultValueForJson(DefaultType defaultValue)
    99{
    100 return nlohmann::json(defaultValue);
    101}
    102
    104template <
    105 typename DefaultType,
    106 std::enable_if_t<
    107 std::is_enum<DefaultType>::value>* = nullptr>
    108// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    109nlohmann::json getDefaultValueForJson(DefaultType defaultValue)
    110{
    111 StringView name{mapEnumValueToName<DefaultType>(defaultValue)};
    112 std::string nameStr{name.data(), name.size()};
    113 return nlohmann::json(nameStr);
    114}
    115
    117template <
    118 typename DefaultType, size_t N,
    119 std::enable_if_t<
    120 std::is_enum<DefaultType>::value>* = nullptr>
    121// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    122nlohmann::json getDefaultValueForJson(const std::array<DefaultType, N>& defaultValues)
    123{
    124 std::array<std::string, N> nameStrings{};
    125 // coverity[autosar_cpp14_a5_1_1_violation] RFD Accepted: TID-2056
    126 for (size_t i{0U}; i < N; ++i)
    127 {
    128 StringView name{mapEnumValueToName<DefaultType>(defaultValues[i])};
    129 std::string nameStr{name.data(), name.size()};
    130 nameStrings[i] = std::move(nameStr);
    131 }
    132 return nlohmann::json(nameStrings);
    133}
    134
    135} // namespace detail
    136
    138// static_assert needed covering all possible type accepted by nlohmann::json()
    139// beside enums and std::arrays of such types
    140template <typename DefaultType>
    142{
    143 static_assert(std::is_trivially_copy_constructible<DefaultType>(), "DefaultType must be trivially copy constructible");
    144
    145public:
    148 dw::core::StringView name,
    149 dw::core::StringView typeName,
    150 bool isIndex,
    151 size_t arraySize,
    152 DefaultType defaultValue)
    153 : ParameterDescriptor(name, typeName, isIndex, arraySize)
    154 , m_defaultValue(defaultValue)
    155 {
    156 }
    168 void addDefault(nlohmann::ordered_json& object) const override
    169 {
    170 const char* DEFAULT_KEY{"default"};
    171 object[DEFAULT_KEY] = detail::getDefaultValueForJson(m_defaultValue);
    172 }
    173
    174private:
    176 DefaultType m_defaultValue;
    177};
    178
    181{
    182public:
    184 explicit ParameterCollectionDescriptor(size_t const capacity);
    185
    187 size_t getSize() const;
    188
    190 const std::shared_ptr<const ParameterDescriptor>& getDescriptor(size_t const index) const;
    191
    197 size_t getIndex(dw::core::StringView const& identifier) const;
    198
    204 const std::shared_ptr<const ParameterDescriptor>& getDescriptor(dw::core::StringView const& identifier) const;
    205
    207 bool isValid(size_t const index) const;
    208
    210 bool isValid(dw::core::StringView const& identifier) const noexcept;
    211
    217 void addDescriptor(const std::shared_ptr<const ParameterDescriptor>& descriptor);
    218
    220 // coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    221 void addDescriptors(const std::tuple<>& t)
    222 {
    223 static_cast<void>(t);
    224 }
    225
    227 template <typename THead>
    228 // coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    229 void addDescriptors(const std::tuple<THead>& t)
    230 {
    231 // coverity[autosar_cpp14_a8_5_2_violation] FP: nvbugs/3904083
    232 auto params = std::get<0>(t).parameterDescriptors;
    233 // all parameters of this constructor argument
    234 addDescriptors(params);
    235 }
    236
    238 template <
    239 typename THead, typename... TTail,
    240 typename std::enable_if_t<sizeof...(TTail) != 0>* = nullptr>
    241 // coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    242 void addDescriptors(const std::tuple<THead, TTail...>& t)
    243 {
    244 // coverity[autosar_cpp14_a8_5_2_violation] FP: nvbugs/3904083
    245 auto params = std::get<0>(t).parameterDescriptors;
    246 // all parameters of the first constructor argument
    247 addDescriptors(params);
    248 // remaining constructor arguments
    249 addDescriptors(tail_impl(std::make_index_sequence<sizeof...(TTail)>(), t));
    250 }
    251
    252private:
    253 template <size_t... Ns, typename... Ts>
    254 auto tail_impl(std::index_sequence<Ns...>, const std::tuple<Ts...>& t) -> decltype(std::make_tuple(std::get<Ns + 1U>(t)...))
    255 {
    256 return std::make_tuple(std::get<Ns + 1U>(t)...);
    257 }
    258
    259 // LCOV_EXCL_START end of template recursion is never reached
    261 // coverity[autosar_cpp14_a0_1_3_violation]
    262 // coverity[autosar_cpp14_a2_10_5_violation]
    263 void addDescriptors(const dw::core::Tuple<>& t)
    264 {
    265 static_cast<void>(t);
    266 }
    267 // LCOV_EXCL_STOP
    268
    270 template <typename THead>
    271 // coverity[autosar_cpp14_a2_10_5_violation]
    272 void addDescriptors(const dw::core::Tuple<THead>& t)
    273 {
    274 addDescriptor(t.m_head);
    275 }
    276
    278 template <
    279 typename THead, typename... TTail,
    280 typename std::enable_if_t<sizeof...(TTail) != 0>* = nullptr>
    281 // coverity[autosar_cpp14_a2_10_5_violation]
    282 void addDescriptors(const dw::core::Tuple<THead, TTail...>& t)
    283 {
    284 addDescriptor(t.m_head);
    285 addDescriptors(t.m_tail);
    286 }
    287
    289 template <
    290 typename ParamT,
    291 typename std::enable_if_t<!ParamT::HAS_DEFAULT, void>* = nullptr>
    292 void addDescriptor(const ParamT& param)
    293 {
    294 addDescriptor(std::make_shared<const ParameterDescriptor>(
    295 param.parameterName,
    296 param.typeName,
    297 ParamT::IS_INDEX,
    298 ParamT::ARRAY_SIZE));
    299 }
    300
    302 template <
    303 typename ParamT,
    304 typename std::enable_if_t<ParamT::HAS_DEFAULT, void>* = nullptr>
    305 void addDescriptor(const ParamT& param)
    306 {
    307 addDescriptor(std::make_shared<const ParameterDescriptorWithDefault<decltype(ParamT::defaultValue)>>(
    308 param.parameterName,
    309 param.typeName,
    310 ParamT::IS_INDEX,
    311 ParamT::ARRAY_SIZE,
    312 param.defaultValue));
    313 }
    314
    316 dw::core::VectorFixed<std::shared_ptr<const ParameterDescriptor>> m_descriptors;
    317};
    318
    320template <typename NodeT>
    321// coverity[autosar_cpp14_a2_10_4_violation] FP: nvbugs/4040101
    322// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    324{
    325 ParameterCollectionDescriptor d{parameterSize<NodeT>()};
    326 d.addDescriptors(describeNodeParameters<NodeT>());
    327 return d;
    328}
    329
    330} // namespace framework
    331} // namespace dw
    332
    333#endif // DW_FRAMEWORK_PARAMETERCOLLECTIONDESCRIPTOR_HPP_
    const std::shared_ptr< const ParameterDescriptor > & getDescriptor(size_t const index) const
    Get the parameter descriptor for the passed index.
    size_t getSize() const
    Get the number of parameter descriptors.
    void addDescriptors(const std::tuple< THead > &t)
    Terminate recursion to add parameter descriptors for each node constructor argument to the collection...
    bool isValid(dw::core::StringView const &identifier) const noexcept
    Check if the passed parameter name matches a parameter descriptor in the collection.
    void addDescriptor(const std::shared_ptr< const ParameterDescriptor > &descriptor)
    bool isValid(size_t const index) const
    Check if the passed index is valid, which mean is within [0, size()).
    const std::shared_ptr< const ParameterDescriptor > & getDescriptor(dw::core::StringView const &identifier) const
    void addDescriptors(const std::tuple< THead, TTail... > &t)
    Recursion to add parameter descriptors for each node constructor argument to the collection.
    ParameterCollectionDescriptor(size_t const capacity)
    Constructor.
    size_t getIndex(dw::core::StringView const &identifier) const
    void addDescriptors(const std::tuple<> &t)
    Terminate recursion to add parameter descriptors for each node constructor argument to the collection...
    The description of a parameter with a default value.
    auto operator=(ParameterDescriptorWithDefault &&) -> ParameterDescriptorWithDefault &=delete
    Move assignment operator.
    ~ParameterDescriptorWithDefault() override=default
    Destructor.
    auto operator=(ParameterDescriptorWithDefault const &) -> ParameterDescriptorWithDefault &=delete
    Copy assignment operator.
    ParameterDescriptorWithDefault(dw::core::StringView name, dw::core::StringView typeName, bool isIndex, size_t arraySize, DefaultType defaultValue)
    Constructor.
    void addDefault(nlohmann::ordered_json &object) const override
    Add the default value to the passed JSON object.
    ParameterDescriptorWithDefault(ParameterDescriptorWithDefault &&)=delete
    Move constructor.
    ParameterDescriptorWithDefault(ParameterDescriptorWithDefault const &)=delete
    Copy constructor.
    dw::core::StringView const & getTypeName() const noexcept
    Get the C++ type name of the parameter.
    ParameterDescriptor & operator=(ParameterDescriptor const &) &=delete
    Copy assignment operator.
    virtual ~ParameterDescriptor()=default
    Destructor.
    ParameterDescriptor(dw::core::StringView const &name, dw::core::StringView const &typeName, const bool isIndex, size_t const arraySize) noexcept
    Constructor.
    ParameterDescriptor(ParameterDescriptor const &)=delete
    Copy constructor.
    dw::core::StringView const & getName() const noexcept
    Get the parameter name, can be empty for unnamed parameters.
    virtual void addDefault(nlohmann::ordered_json &object) const
    Add the default value to the passed JSON object (only used by ParameterDescriptorWithDefault()).
    ParameterDescriptor(ParameterDescriptor &&)=delete
    Move constructor.
    ParameterDescriptor & operator=(ParameterDescriptor &&) &=delete
    Move assignment operator.
    bool isIndex() const noexcept
    Check if parameter is an index.
    size_t getArraySize() const noexcept
    Get the array size, 0 for non-array parameters.
    static ParameterCollectionDescriptor createParameterCollectionDescriptor()
    Create a parameter collection descriptor for a give node.
    Definition: Buffer.hpp:41
    人人超碰97caoporen国产