12 #ifndef __NVDSINFERSERVER_OPTIONS_H__
13 #define __NVDSINFERSERVER_OPTIONS_H__
19 #include <unordered_map>
33 #define safeStr(str) str.c_str()
58 *((V*)(
void*)&
value) = v;
62 std::vector<BasicValue> vArray;
68 const auto i = m_Fields.find(key);
71 bool hasValue(
const std::string& key)
const override
73 const auto i = m_Fields.find(key);
74 return (i == m_Fields.end() ?
false :
true);
76 uint32_t
getCount() const final {
return (uint32_t)m_Fields.size(); }
77 std::string
getKey(uint32_t idx)
const final
79 assert(idx < m_Fields.size());
80 auto i = m_Fields.cbegin();
89 auto d = getValueD(key, t);
93 ptr = (
void*)&(d->vHead.vStr);
95 ptr = (
void*)&(d->vHead.value);
100 NvDsInferStatus getArraySize(
const std::string& key, uint32_t& size)
const override
104 size = d->vArray.size();
109 const std::string& key,
OptionType ot,
void** ptrBase, uint32_t size)
const override
114 assert(size <= d->vArray.size());
115 for (uint32_t i = 0; i < size; ++i) {
116 auto& each = d->vArray[i];
120 "query value type:%d doesn't match exact type:%d in array.", (
int)ot,
123 ptrBase[i] = (
void*)&(each.vStr);
125 ptrBase[i] = (
void*)&(each.value);
131 template <
typename In>
136 template <
typename T>
137 inline void setValue(
const std::string& key,
const T& v)
139 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
140 auto& field = m_Fields[key];
144 template <
typename T>
145 inline void setValueArray(
const std::string& key,
const std::vector<T>& values)
147 if (values.empty()) {
150 using t =
typename convertType<std::remove_const_t<std::remove_reference_t<T>>>::t;
151 auto& field = m_Fields[key];
153 field.vArray = std::vector<D::BasicValue>(values.size());
154 for (
size_t i = 0; i < values.size(); ++i) {
155 auto& data = field.vArray[i];
161 const D* getValueD(
const std::string& key,
OptionType t)
const
163 const auto i = m_Fields.find(key);
164 if (i == m_Fields.end()) {
168 if (i->second.vHead.type != t) {
170 "BufOptions: get option:%s but type is not matched.",
177 std::unordered_map<std::string, D> m_Fields;
182 BufOptions::D::BasicValue::setV<std::string>(
const std::string& v,
OptionType t)
189 template <
typename T>
190 struct BufOptions::convertType<T*> {
191 typedef std::remove_const_t<T>*
t;
194 struct BufOptions::convertType<int64_t> {
198 struct BufOptions::convertType<int32_t> {
202 struct BufOptions::convertType<int16_t> {
206 struct BufOptions::convertType<int8_t> {
210 struct BufOptions::convertType<uint64_t> {
214 struct BufOptions::convertType<uint32_t> {
218 struct BufOptions::convertType<uint16_t> {
222 struct BufOptions::convertType<uint8_t> {
226 struct BufOptions::convertType<double> {
230 struct BufOptions::convertType<float> {
234 struct BufOptions::convertType<bool> {
238 struct BufOptions::convertType<std::string> {
239 typedef std::string
t;
242 template <
typename T>
243 struct BufOptions::convertType<std::vector<T>> {
246 template <
typename T>
247 struct BufOptions::convertType<std::vector<T*>> {
252 #endif //__NVDSINFERSERVER_OPTIONS_H__