17 #ifndef __NVDSINFERSERVER_OPTIONS_H__
18 #define __NVDSINFERSERVER_OPTIONS_H__
24 #include <unordered_map>
38 #define safeStr(str) str.c_str()
63 *((V*)(
void*)&
value) = v;
67 std::vector<BasicValue> vArray;
73 const auto i = m_Fields.find(key);
76 bool hasValue(
const std::string& key)
const override
78 const auto i = m_Fields.find(key);
79 return (i == m_Fields.end() ?
false :
true);
81 uint32_t
getCount() const final {
return (uint32_t)m_Fields.size(); }
82 std::string
getKey(uint32_t idx)
const final
84 assert(idx < m_Fields.size());
85 auto i = m_Fields.cbegin();
94 auto d = getValueD(key, t);
98 ptr = (
void*)&(d->vHead.vStr);
100 ptr = (
void*)&(d->vHead.value);
105 NvDsInferStatus getArraySize(
const std::string& key, uint32_t& size)
const override
109 size = d->vArray.size();
114 const std::string& key,
OptionType ot,
void** ptrBase, uint32_t size)
const override
119 assert(size <= d->vArray.size());
120 for (uint32_t i = 0; i < size; ++i) {
121 auto& each = d->vArray[i];
125 "query value type:%d doesn't match exact type:%d in array.", (
int)ot,
128 ptrBase[i] = (
void*)&(each.vStr);
130 ptrBase[i] = (
void*)&(each.value);
136 template <
typename In>
141 template <
typename T>
142 inline void setValue(
const std::string& key,
const T& v)
144 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
145 auto& field = m_Fields[key];
149 template <
typename T>
150 inline void setValueArray(
const std::string& key,
const std::vector<T>& values)
152 if (values.empty()) {
155 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
156 auto& field = m_Fields[key];
158 field.vArray = std::vector<D::BasicValue>(values.size());
159 for (
size_t i = 0; i < values.size(); ++i) {
160 auto& data = field.vArray[i];
166 const D* getValueD(
const std::string& key,
OptionType t)
const
168 const auto i = m_Fields.find(key);
169 if (i == m_Fields.end()) {
173 if (i->second.vHead.type != t) {
175 "BufOptions: get option:%s but type is not matched.",
182 std::unordered_map<std::string, D> m_Fields;
187 BufOptions::D::BasicValue::setV<std::string>(
const std::string& v,
OptionType t)
194 template <
typename T>
195 struct BufOptions::convertType<T*> {
196 typedef std::remove_const_t<T>*
t;
199 struct BufOptions::convertType<int64_t> {
203 struct BufOptions::convertType<int32_t> {
207 struct BufOptions::convertType<int16_t> {
211 struct BufOptions::convertType<int8_t> {
215 struct BufOptions::convertType<uint64_t> {
219 struct BufOptions::convertType<uint32_t> {
223 struct BufOptions::convertType<uint16_t> {
227 struct BufOptions::convertType<uint8_t> {
231 struct BufOptions::convertType<double> {
235 struct BufOptions::convertType<float> {
239 struct BufOptions::convertType<bool> {
243 struct BufOptions::convertType<std::string> {
244 typedef std::string
t;
247 template <
typename T>
248 struct BufOptions::convertType<std::vector<T>> {
251 template <
typename T>
252 struct BufOptions::convertType<std::vector<T*>> {
257 #endif //__NVDSINFERSERVER_OPTIONS_H__