NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
StringMapParameterNode.h
Go to the documentation of this file.
1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23 
25 
26 #ifndef NVNEURAL_STRINGMAPPARAMETERNODE_H
27 #define NVNEURAL_STRINGMAPPARAMETERNODE_H
28 
29 #include <nvneural/CoreTypes.h>
30 #include <nvneural/RefObject.h>
31 #include <functional>
32 #include <map>
33 #include <string>
34 
35 namespace nvneural
36 {
37 
43 class StringMapParameterNode final : public refobj::RefObjectBase<refobj::Implements<IParameterNode>>
44 {
45 public:
47  using StringMap = std::map<std::string, std::string>;
48 
50  explicit StringMapParameterNode(const StringMap& stringMap);
51 
53  explicit StringMapParameterNode(StringMap&& stringMap);
54 
55  // IParameterNode members
57  NeuralResult getInteger(const char* pParameterName, int32_t* pIntOut) const noexcept override;
59  NeuralResult getSize(const char* pParameterName, size_t* pSizeOut) const noexcept override;
61  NeuralResult getFloat(const char* pParameterName, float* pFloatOut) const noexcept override;
63  NeuralResult getString(const char* pParameterName, const char** pStringOut) const noexcept override;
65  NeuralResult getDimension(const char* pParameterName, TensorDimension* pDimOut) const noexcept override;
66 
68  NeuralResult setInteger(const char* pParameterName, int32_t value) noexcept override;
70  NeuralResult setSize(const char* pParameterName, size_t value) noexcept override;
72  NeuralResult setFloat(const char* pParameterName, float value) noexcept override;
74  NeuralResult setString(const char* pParameterName, const char* pString) noexcept override;
76  NeuralResult setDimension(const char* pParameterName, TensorDimension value) noexcept override;
77 
78 private:
80  using GetFunctionEpilogue = std::function<NeuralResult(const std::string&)>;
81 
91  NeuralResult getGeneric(const char* pParameterName, const GetFunctionEpilogue& epilogue) const noexcept;
92 
94  NeuralResult setGeneric(const char* pParameterName, const std::string& value) noexcept;
95 
97  StringMap m_parameters;
98 };
99 
100 } // namespace nvneural
101 
102 #endif // NVNEURAL_STRINGMAPPARAMETERNODE_H
Fundamental NvNeural data types are declared here.
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
Standard implementation for IRefObject-derived objects.
IParameterNode implementation designed to demonstrate loading parameters outside the standard nv-neur...
Definition: StringMapParameterNode.h:44
NeuralResult getSize(const char *pParameterName, size_t *pSizeOut) const noexcept
Retrieves an unsigned integer value that can represent the result of sizeof().
Definition: StringMapParameterNode.cpp:95
NeuralResult getFloat(const char *pParameterName, float *pFloatOut) const noexcept
Retrieves a floating-point value.
Definition: StringMapParameterNode.cpp:105
NeuralResult setFloat(const char *pParameterName, float value) noexcept
Saves a floating-point value.
Definition: StringMapParameterNode.cpp:166
NeuralResult setString(const char *pParameterName, const char *pString) noexcept
Saves a UTF-8 string value.
Definition: StringMapParameterNode.cpp:172
NeuralResult getInteger(const char *pParameterName, int32_t *pIntOut) const noexcept
Retrieves a signed integer value.
Definition: StringMapParameterNode.cpp:85
NeuralResult setSize(const char *pParameterName, size_t value) noexcept
Saves an unsigned integer that can represent the result of sizeof().
Definition: StringMapParameterNode.cpp:160
NeuralResult setDimension(const char *pParameterName, TensorDimension value) noexcept
Saves a tensor dimension.
Definition: StringMapParameterNode.cpp:177
StringMapParameterNode(const StringMap &stringMap)
Creates a StringMapParameterNode from a map of <parameterName, parameterValue> pairs.
Definition: StringMapParameterNode.cpp:56
std::map< std::string, std::string > StringMap
Shorthand typedef for string->string maps.
Definition: StringMapParameterNode.h:47
NeuralResult getString(const char *pParameterName, const char **pStringOut) const noexcept
Retrieves a UTF-8 string value.
Definition: StringMapParameterNode.cpp:115
NeuralResult getDimension(const char *pParameterName, TensorDimension *pDimOut) const noexcept
Retrieves a tensor dimension.
Definition: StringMapParameterNode.cpp:125
NeuralResult setInteger(const char *pParameterName, int32_t value) noexcept
Saves an integer.
Definition: StringMapParameterNode.cpp:154
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:136
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336