NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
StringList.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 #ifndef NVNEURAL_STRINGLIST_H
26 #define NVNEURAL_STRINGLIST_H
27 
28 #include <nvneural/CoreTypes.h>
29 #include <nvneural/RefPtr.h>
30 #include <nvneural/RefObject.h>
31 
32 #include <algorithm>
33 #include <vector>
34 #include <string>
35 
36 namespace nvneural {
37 
39 class StringList : public refobj::RefObjectBase<refobj::Implements<IStringList>>
40 {
41 public:
44  explicit StringList(const std::vector<std::string>& stringList)
45  : m_stringList(stringList)
46  {
47  }
48 
52  explicit StringList(std::vector<std::string>&& stringList)
53  : m_stringList(std::move(stringList))
54  {
55  }
56 
58  size_t stringCount() const noexcept override
59  {
60  return m_stringList.size();
61  }
62 
64  const char* getStringByIndex(size_t stringIndex) const noexcept override
65  {
66  if (stringIndex < m_stringList.size())
67  {
68  return m_stringList[stringIndex].c_str();
69  }
70  else
71  {
72  return nullptr;
73  }
74  }
75 
77  size_t getStringSizeByIndex(size_t stringIndex) const noexcept override
78  {
79  if (stringIndex < m_stringList.size())
80  {
81  return m_stringList[stringIndex].size();
82  }
83  else
84  {
85  return 0;
86  }
87  }
88 
89 private:
90  std::vector<std::string> m_stringList;
91 };
92 
93 } // namespace nvneural
94 #endif // NVNEURAL_STRINGLIST_H
Fundamental NvNeural data types are declared here.
Standard implementation for IRefObject-derived objects.
Smart pointer class for tracking IRefObject instances.
Standard implementation of IStringList that can represent a vector<string> type.
Definition: StringList.h:40
size_t stringCount() const noexcept
Definition: StringList.h:58
size_t getStringSizeByIndex(size_t stringIndex) const noexcept
Returns the Nth string's size in the collection.
Definition: StringList.h:77
const char * getStringByIndex(size_t stringIndex) const noexcept
Returns the Nth string in the collection.
Definition: StringList.h:64
StringList(std::vector< std::string > &&stringList)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: StringList.h:52
StringList(const std::vector< std::string > &stringList)
Creates a StringList from a const reference.
Definition: StringList.h:44
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336