NVIDIA DeepStream SDK API Reference

6.4 Release
datamap.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 #ifndef _DS3D_COMMON_HPP_DATAMAP_HPP
13 #define _DS3D_COMMON_HPP_DATAMAP_HPP
14 
15 #include <ds3d/common/func_utils.h>
16 
17 #include <ds3d/common/hpp/obj.hpp>
18 
19 namespace ds3d {
20 
21 class GuardDataMap : public GuardDataT<abiDataMap> {
23 
24 public:
25  using KeyName = std::string;
26  GuardDataMap() = default;
27 
28  template <typename... Args /*, _EnableIfConstructible<_Base, Args&&...> = true*/>
29  GuardDataMap(Args&&... args) : _Base(std::forward<Args>(args)...)
30  {
31  }
32 
33  ~GuardDataMap() = default;
34 
35  bool hasData(const KeyName& name)
36  {
37  DS_ASSERT(ptr());
38  return ptr()->has_i(name.c_str());
39  }
40 
41  template <class T, _EnableIfValidIdType<T> = true>
42  inline ErrCode setData(const KeyName& name, const T& value); // copy T
43 
44  template <class T>
45  inline ErrCode setGuardData(const KeyName& name, const GuardDataT<T>& value);
46 
47  template <class T>
48  inline ErrCode setRefData(const KeyName& name, const abiRefT<T>& value);
49 
50  template <class T>
51  inline ErrCode setPtrData(const KeyName& name, ShrdPtr<T> value);
52 
53  template <class T>
54  inline ErrCode setPtrData(const KeyName& name, UniqPtr<T> value)
55  {
56  return this->setPtrData(ShrdPtr<T>(std::move(value)));
57  }
58 
59  template <class T>
60  inline ErrCode getPtrData(const KeyName& name, ShrdPtr<T>& value);
61 
62  template <class T>
63  inline ErrCode getRefData(const KeyName& name, abiRefT<T>*& value);
64 
65  template <class T>
66  inline ErrCode getGuardData(const KeyName& name, GuardDataT<T>& value);
67 
68  template <class T, _EnableIfValidIdType<T> = true>
69  inline ErrCode getData(const KeyName& name, T& value);
70 
71  inline ErrCode removeData(const KeyName& name)
72  {
73  DS_ASSERT(ptr());
74  return ptr()->removeBuf_i(name.c_str());
75  }
76  inline ErrCode clear()
77  {
78  DS_ASSERT(ptr());
79  return ptr()->clear_i();
80  }
81  inline ErrCode copy(
82  GuardDataMap input, DataMapPolicy policy = DataMapPolicy::kCopyPolicyNone, char* policyData = nullptr)
83  {
84  DS_ASSERT(ptr());
85  DS_ASSERT(input.ptr());
86  return ptr()->copy_i(input.ptr(), policy, policyData);
87  }
88  inline ErrCode copy(
90  char* policyData = nullptr)
91  {
92  DS_ASSERT(ptr());
93  DS_ASSERT(input.ptr());
94  return ptr()->copy_i(input.ptr(), key.empty() ? nullptr : key.c_str(), policy, policyData);
95  }
96 
97  inline int32_t getSize()
98  {
99  DS_ASSERT(ptr());
100  return ptr()->getSize_i();
101  }
102 
103  void printDebug() const
104  {
105  DS_ASSERT(ptr());
106  ptr()->printDebug_i();
107  }
108 };
109 
110 template <class T>
111 ErrCode
113 {
114  if (!value.abiRef()) {
115  return ErrCode::kNullPtr;
116  }
117  return this->setRefData(name, *value.abiRef());
118 }
119 
120 template <class T>
121 ErrCode
123 {
124  using t = std::remove_const_t<T>;
125  TIdType tyid = TpId<t>::__typeid();
126  abiRefAny* u = new abiRefCast<T, void>(value);
127  DS_ASSERT(u && u->data());
128  DS_ASSERT(ptr());
129  ErrCode code = ptr()->setBuf_i(name.c_str(), tyid, u);
130  if (!isGood(code)) {
131  u->destroy();
132  }
133  return code;
134 }
135 
136 template <class T, _EnableIfValidIdType<T> = true>
137 ErrCode
138 GuardDataMap::setData(const GuardDataMap::KeyName& name, const T& value)
139 {
140  using t = std::remove_const_t<std::remove_reference_t<T>>;
141  // TIdType tyid = TpId<t>::__typeid();
142  ShrdPtr<t> data(new t(value));
143  return this->setPtrData(name, std::move(data));
144 }
145 
146 template <class T>
147 ErrCode
149 {
150  using t = std::remove_const_t<T>;
151  TIdType tyid = TpId<t>::__typeid();
152  abiRefAny* u = PtrToAbiRef<T, void>(std::move(value));
153  DS_ASSERT(u && u->data());
154  DS_ASSERT(ptr());
155  ErrCode code = ptr()->setBuf_i(name.c_str(), tyid, u);
156  if (!isGood(code)) {
157  u->destroy();
158  }
159  return code;
160 }
161 
162 template <class T>
163 ErrCode
165 {
166  abiRefT<T>* refData = nullptr;
167  ErrCode code = getRefData(name, refData);
168  guardData.reset(refData);
169  return code;
170 }
171 
172 template <class T>
173 ErrCode
175 {
176  using t = std::remove_const_t<T>;
177  TIdType tyid = TpId<t>::__typeid();
178  const abiRefAny* ud = nullptr;
179  DS_ASSERT(ptr());
180  ErrCode code = ptr()->getBuf_i(name.c_str(), tyid, ud);
181  if (!isGood(code)) {
182  return code;
183  }
184  abiRefT<T>* u = new abiRefCast<void, T>(const_cast<abiRefAny*>(ud), false);
185  DS_ASSERT(u && u->data());
186  value = u;
187  DS_ASSERT(value);
188  return code;
189 }
190 
191 template <class T>
192 ErrCode
194 {
195  using t = std::remove_const_t<T>;
196  TIdType tyid = TpId<t>::__typeid();
197  const abiRefAny* ud = nullptr;
198  DS_ASSERT(ptr());
199  ErrCode code = ptr()->getBuf_i(name.c_str(), tyid, ud);
200  if (!isGood(code)) {
201  return code;
202  }
203  DS_ASSERT(ud && ud->data());
204  value = AbiRefToPtr<void, T>(*ud);
205  DS_ASSERT(value);
206  return code;
207 }
208 
209 template <class T, _EnableIfValidIdType<T> = true>
210 ErrCode
212 {
213  using t = std::remove_const_t<T>;
214  TIdType tyid = TpId<t>::__typeid();
215  const abiRefAny* ud = nullptr;
216  DS_ASSERT(ptr());
217  ErrCode code = ptr()->getBuf_i(name.c_str(), tyid, ud);
218  if (!isGood(code)) {
219  return code;
220  }
221  DS_ASSERT(ud && ud->data());
222  value = *(static_cast<T*>(ud->data()));
223  return code;
224 }
225 
226 } // namespace ds3d
227 
228 #endif // _DS3D_COMMON_HPP_DATAMAP_HPP
ds3d::isGood
bool isGood(ErrCode c)
Definition: func_utils.h:28
ds3d::GuardDataMap::setGuardData
ErrCode setGuardData(const KeyName &name, const GuardDataT< T > &value)
Definition: datamap.hpp:112
ds3d::UniqPtr
std::unique_ptr< T, std::function< void(T *)> > UniqPtr
Definition: obj.hpp:31
DS_ASSERT
#define DS_ASSERT(...)
Definition: defines.h:31
ds3d::TpId::__typeid
static constexpr TIdType __typeid()
Definition: type_trait.h:28
ds3d::GuardDataMap::getSize
int32_t getSize()
Definition: datamap.hpp:97
ds3d::abiRefCast
Definition: obj.hpp:95
ds3d::GuardDataMap::clear
ErrCode clear()
Definition: datamap.hpp:76
ds3d::GuardDataMap::GuardDataMap
GuardDataMap()=default
ds3d::GuardDataMap::KeyName
std::string KeyName
Definition: datamap.hpp:25
ds3d::abiDataMap::clear_i
virtual ErrCode clear_i()=0
ds3d::ErrCode::kNullPtr
@ kNullPtr
ds3d::GuardRef< abiRefT< Tp > >::abiRef
abiRefT< Tp > * abiRef() const
Definition: obj.hpp:269
ds3d::abiDataMap::printDebug_i
virtual void printDebug_i() const =0
ds3d::GuardDataMap::getPtrData
ErrCode getPtrData(const KeyName &name, ShrdPtr< T > &value)
Definition: datamap.hpp:193
ds3d::GuardDataMap::setPtrData
ErrCode setPtrData(const KeyName &name, ShrdPtr< T > value)
Definition: datamap.hpp:148
ds3d::GuardDataMap::printDebug
void printDebug() const
Definition: datamap.hpp:103
ds3d::abiDataMap::getSize_i
virtual int32_t getSize_i()=0
ds3d::abiDataMap::copy_i
virtual ErrCode copy_i(abiDataMap *input, DataMapPolicy policy, char *policyData)=0
ds3d::abiRefT
Definition: abi_obj.h:39
ds3d::GuardDataMap::removeData
ErrCode removeData(const KeyName &name)
Definition: datamap.hpp:71
ds3d::abiDataMap::has_i
virtual bool has_i(const char *key) const =0
ds3d::ErrCode
ErrCode
Definition: common.h:43
ds3d::DataMapPolicy
DataMapPolicy
Definition: abi_obj.h:29
ds3d::GuardDataMap::setRefData
ErrCode setRefData(const KeyName &name, const abiRefT< T > &value)
Definition: datamap.hpp:122
ds3d::abiDataMap::removeBuf_i
virtual ErrCode removeBuf_i(const char *key)=0
obj.hpp
ds3d::GuardDataT
Definition: obj.hpp:331
ds3d::abiRefObj::destroy
virtual void destroy()=0
ds3d::GuardDataMap::getRefData
ErrCode getRefData(const KeyName &name, abiRefT< T > *&value)
Definition: datamap.hpp:174
ds3d::GuardDataMap::hasData
bool hasData(const KeyName &name)
Definition: datamap.hpp:35
ds3d::abiDataMap::setBuf_i
virtual ErrCode setBuf_i(const char *key, TIdType tid, abiRefAny *data)=0
ds3d::GuardRef< abiRefT< Tp > >::reset
void reset(abiRefT< Tp > *abiref=nullptr)
Definition: obj.hpp:260
ds3d::GuardDataMap::getGuardData
ErrCode getGuardData(const KeyName &name, GuardDataT< T > &value)
Definition: datamap.hpp:164
ds3d::GuardDataMap::getData
ErrCode getData(const KeyName &name, T &value)
Definition: datamap.hpp:211
ds3d::GuardDataMap::setData
ErrCode setData(const KeyName &name, const T &value)
Definition: datamap.hpp:138
ds3d::GuardDataT< abiDataMap >::ptr
abiDataMap * ptr() const
Definition: obj.hpp:361
ds3d::GuardDataMap::copy
ErrCode copy(GuardDataMap input, DataMapPolicy policy=DataMapPolicy::kCopyPolicyNone, char *policyData=nullptr)
Definition: datamap.hpp:81
ds3d::ShrdPtr
std::shared_ptr< T > ShrdPtr
Definition: obj.hpp:29
ds3d::abiDataMap::getBuf_i
virtual ErrCode getBuf_i(const char *key, TIdType tid, const abiRefAny *&data) const =0
ds3d::GuardDataMap::GuardDataMap
GuardDataMap(Args &&... args)
Definition: datamap.hpp:29
func_utils.h
ds3d::GuardDataMap
Definition: datamap.hpp:21
ds3d::TIdType
uint64_t TIdType
Definition: common.h:69
ds3d::abiRefT::data
virtual T * data() const =0
ds3d::GuardDataMap::copy
ErrCode copy(GuardDataMap input, const KeyName key, DataMapPolicy policy=DataMapPolicy::kCopyPolicyNone, char *policyData=nullptr)
Definition: datamap.hpp:88
ds3d
Definition: lidar_3d_datatype.h:33
ds3d::GuardDataMap::setPtrData
ErrCode setPtrData(const KeyName &name, UniqPtr< T > value)
Definition: datamap.hpp:54
ds3d::DataMapPolicy::kCopyPolicyNone
@ kCopyPolicyNone
ds3d::GuardDataMap::~GuardDataMap
~GuardDataMap()=default