13 #ifndef __NVDSINFERSERVER_OPTIONS_H__
14 #define __NVDSINFERSERVER_OPTIONS_H__
20 #include <unordered_map>
34 #define safeStr(str) str.c_str()
59 *((V*)(
void*)&
value) = v;
63 std::vector<BasicValue> vArray;
69 const auto i = m_Fields.find(key);
72 bool hasValue(
const std::string& key)
const override
74 const auto i = m_Fields.find(key);
75 return (i == m_Fields.end() ?
false :
true);
77 uint32_t
getCount() const final {
return (uint32_t)m_Fields.size(); }
78 std::string
getKey(uint32_t idx)
const final
80 assert(idx < m_Fields.size());
81 auto i = m_Fields.cbegin();
90 auto d = getValueD(key, t);
94 ptr = (
void*)&(d->vHead.vStr);
96 ptr = (
void*)&(d->vHead.value);
101 NvDsInferStatus getArraySize(
const std::string& key, uint32_t& size)
const override
105 size = d->vArray.size();
110 const std::string& key,
OptionType ot,
void** ptrBase, uint32_t size)
const override
115 assert(size <= d->vArray.size());
116 for (uint32_t i = 0; i < size; ++i) {
117 auto& each = d->vArray[i];
121 "query value type:%d doesn't match exact type:%d in array.", (
int)ot,
124 ptrBase[i] = (
void*)&(each.vStr);
126 ptrBase[i] = (
void*)&(each.value);
132 template <
typename In>
137 template <
typename T>
138 inline void setValue(
const std::string& key,
const T& v)
140 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
141 auto& field = m_Fields[key];
145 template <
typename T>
146 inline void setValueArray(
const std::string& key,
const std::vector<T>& values)
148 if (values.empty()) {
151 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
152 auto& field = m_Fields[key];
154 field.vArray = std::vector<D::BasicValue>(values.size());
155 for (
size_t i = 0; i < values.size(); ++i) {
156 auto& data = field.vArray[i];
162 const D* getValueD(
const std::string& key,
OptionType t)
const
164 const auto i = m_Fields.find(key);
165 if (i == m_Fields.end()) {
169 if (i->second.vHead.type != t) {
171 "BufOptions: get option:%s but type is not matched.",
178 std::unordered_map<std::string, D> m_Fields;
183 BufOptions::D::BasicValue::setV<std::string>(
const std::string& v,
OptionType t)
190 template <
typename T>
191 struct BufOptions::convertType<T*> {
192 typedef std::remove_const_t<T>*
t;
195 struct BufOptions::convertType<int64_t> {
199 struct BufOptions::convertType<int32_t> {
203 struct BufOptions::convertType<int16_t> {
207 struct BufOptions::convertType<int8_t> {
211 struct BufOptions::convertType<uint64_t> {
215 struct BufOptions::convertType<uint32_t> {
219 struct BufOptions::convertType<uint16_t> {
223 struct BufOptions::convertType<uint8_t> {
227 struct BufOptions::convertType<double> {
231 struct BufOptions::convertType<float> {
235 struct BufOptions::convertType<bool> {
239 struct BufOptions::convertType<std::string> {
240 typedef std::string
t;
243 template <
typename T>
244 struct BufOptions::convertType<std::vector<T>> {
247 template <
typename T>
248 struct BufOptions::convertType<std::vector<T*>> {
253 #endif //__NVDSINFERSERVER_OPTIONS_H__