18 #ifndef __NVDSINFERSERVER_OPTIONS_H__
19 #define __NVDSINFERSERVER_OPTIONS_H__
25 #include <unordered_map>
28 #include "infer_common.h"
29 #include "infer_utils.h"
39 #define safeStr(str) str.c_str()
64 *((V*)(
void*)&
value) = v;
68 std::vector<BasicValue> vArray;
74 const auto i = m_Fields.find(key);
77 bool hasValue(
const std::string& key)
const override
79 const auto i = m_Fields.find(key);
80 return (i == m_Fields.end() ?
false :
true);
82 uint32_t
getCount() const final {
return (uint32_t)m_Fields.size(); }
83 std::string
getKey(uint32_t idx)
const final
85 assert(idx < m_Fields.size());
86 auto i = m_Fields.cbegin();
95 auto d = getValueD(key, t);
99 ptr = (
void*)&(d->vHead.vStr);
101 ptr = (
void*)&(d->vHead.value);
106 NvDsInferStatus getArraySize(
const std::string& key, uint32_t& size)
const override
110 size = d->vArray.size();
115 const std::string& key,
OptionType ot,
void** ptrBase, uint32_t size)
const override
120 assert(size <= d->vArray.size());
121 for (uint32_t i = 0; i < size; ++i) {
122 auto& each = d->vArray[i];
126 "query value type:%d doesn't match exact type:%d in array.", (
int)ot,
129 ptrBase[i] = (
void*)&(each.vStr);
131 ptrBase[i] = (
void*)&(each.value);
137 template <
typename In>
142 template <
typename T>
143 inline void setValue(
const std::string& key,
const T& v)
145 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
146 auto& field = m_Fields[key];
150 template <
typename T>
151 inline void setValueArray(
const std::string& key,
const std::vector<T>& values)
153 if (values.empty()) {
156 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
157 auto& field = m_Fields[key];
159 field.vArray = std::vector<D::BasicValue>(values.size());
160 for (
size_t i = 0; i < values.size(); ++i) {
161 auto& data = field.vArray[i];
167 const D* getValueD(
const std::string& key,
OptionType t)
const
169 const auto i = m_Fields.find(key);
170 if (i == m_Fields.end()) {
174 if (i->second.vHead.type != t) {
176 "BufOptions: get option:%s but type is not matched.",
183 std::unordered_map<std::string, D> m_Fields;
188 BufOptions::D::BasicValue::setV<std::string>(
const std::string& v,
OptionType t)
195 template <
typename T>
196 struct BufOptions::convertType<T*> {
197 typedef std::remove_const_t<T>*
t;
200 struct BufOptions::convertType<int64_t> {
204 struct BufOptions::convertType<int32_t> {
208 struct BufOptions::convertType<int16_t> {
212 struct BufOptions::convertType<int8_t> {
216 struct BufOptions::convertType<uint64_t> {
220 struct BufOptions::convertType<uint32_t> {
224 struct BufOptions::convertType<uint16_t> {
228 struct BufOptions::convertType<uint8_t> {
232 struct BufOptions::convertType<double> {
236 struct BufOptions::convertType<float> {
240 struct BufOptions::convertType<bool> {
244 struct BufOptions::convertType<std::string> {
245 typedef std::string
t;
248 template <
typename T>
249 struct BufOptions::convertType<std::vector<T>> {
252 template <
typename T>
253 struct BufOptions::convertType<std::vector<T*>> {
258 #endif //__NVDSINFERSERVER_OPTIONS_H__