• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.14
    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-2023 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
    140// coverity[autosar_cpp14_a14_1_1_violation]
    141template <typename DefaultType>
    143{
    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 // coverity[autosar_cpp14_a5_1_1_violation]
    171 object["default"] = 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 template <
    221 typename NodeT, size_t ConstructorArgumentIndex,
    222 typename std::enable_if_t<ConstructorArgumentIndex == std::tuple_size<decltype(describeParameters<NodeT>())>::value, void>* = nullptr>
    223 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
    224 // coverity[autosar_cpp14_m0_1_8_violation]
    226 {
    227 }
    228
    230 template <
    231 typename NodeT, size_t ConstructorArgumentIndex,
    232 typename std::enable_if_t<ConstructorArgumentIndex<std::tuple_size<decltype(describeParameters<NodeT>())>::value, void>* = nullptr>
    233 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
    234 void addDescriptors()
    235 {
    236 // coverity[autosar_cpp14_a8_5_2_violation]
    237 auto t = std::get<ConstructorArgumentIndex>(describeParameters<NodeT>());
    238 // coverity[autosar_cpp14_a8_5_2_violation]
    239 const auto& t2 = std::get<PARAMETER_CONSTRUCTOR_ARGUMENT_DESCRIPTOR>(t);
    240 // all parameters of this constructor argument
    241 addDescriptors(t2);
    242 // next constructor argument
    243 addDescriptors<NodeT, ConstructorArgumentIndex + 1>();
    244 }
    245
    246private:
    248 // coverity[autosar_cpp14_a0_1_3_violation]
    249 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
    250 void addDescriptors(const dw::core::Tuple<>& t)
    251 {
    252 static_cast<void>(t);
    253 }
    254
    256 template <typename THead>
    257 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
    258 void addDescriptors(const dw::core::Tuple<THead>& t)
    259 {
    260 addDescriptor(t.m_head);
    261 }
    262
    264 template <
    265 typename THead, typename... TTail,
    266 typename std::enable_if_t<sizeof...(TTail) != 0>* = nullptr>
    267 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
    268 void addDescriptors(const dw::core::Tuple<THead, TTail...>& t)
    269 {
    270 addDescriptor(t.m_head);
    271 addDescriptors(t.m_tail);
    272 }
    273
    275 template <
    276 typename ParamT,
    277 typename std::enable_if_t<!ParamT::HAS_DEFAULT, void>* = nullptr>
    278 void addDescriptor(const ParamT& param)
    279 {
    280 addDescriptor(std::make_shared<const ParameterDescriptor>(
    281 param.parameterName,
    282 param.typeName,
    283 ParamT::IS_INDEX,
    284 ParamT::ARRAY_SIZE));
    285 }
    286
    288 template <
    289 typename ParamT,
    290 typename std::enable_if_t<ParamT::HAS_DEFAULT, void>* = nullptr>
    291 void addDescriptor(const ParamT& param)
    292 {
    293 addDescriptor(std::make_shared<const ParameterDescriptorWithDefault<decltype(ParamT::defaultValue)>>(
    294 param.parameterName,
    295 param.typeName,
    296 ParamT::IS_INDEX,
    297 ParamT::ARRAY_SIZE,
    298 param.defaultValue));
    299 }
    300
    302 dw::core::VectorFixed<std::shared_ptr<const ParameterDescriptor>> m_descriptors;
    303};
    304
    306template <typename NodeT>
    307// coverity[autosar_cpp14_a2_10_4_violation] FP: nvbugs/4040101
    308// coverity[autosar_cpp14_a2_10_5_violation] FP: nvbugs/3907242
    310{
    311 ParameterCollectionDescriptor d{parameterSize<NodeT>()};
    312 d.addDescriptors<NodeT, 0>();
    313 return d;
    314}
    315
    316} // namespace framework
    317} // namespace dw
    318
    319#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()
    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
    ParameterCollectionDescriptor(size_t const capacity)
    Constructor.
    size_t getIndex(dw::core::StringView const &identifier) const
    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:40
    人人超碰97caoporen国产