3DiVi Face SDK  3.25.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
DynamicTemplateIndex.h
1 
9 #ifndef __PBIO_API__PBIO__RESIZABLE_TEMPLATE_INDEX_H_
10 #define __PBIO_API__PBIO__RESIZABLE_TEMPLATE_INDEX_H_
11 
12 #include "ComplexObject.h"
13 #include "Error.h"
14 #include "SmartPtr.h"
15 #include "stl_wraps_impls/WrapOStreamImpl.h"
16 #include "Template.h"
17 #include "ContextTemplate.h"
18 
19 namespace pbio
20 {
27  {
28  public:
34  typedef LightSmartPtr<DynamicTemplateIndex>::tPtr Ptr;
36 
37  public:
55  size_t size() const;
56 
57  size_t capacity() const;
58 
82  std::string getUUID(size_t index) const;
83 
84  pbio::ContextTemplate::Ptr at(const std::string& uuid) const;
85 
86  pbio::ContextTemplate::Ptr get(int64_t) const;
87 
88  void add(pbio::Template::Ptr templ, const std::string& uuid);
89 
90  void add(const std::vector<pbio::Template::Ptr>& templates, const std::vector<std::string>& uuids);
91 
92  void add(pbio::ContextTemplate::Ptr templ, const std::string& uuid);
93 
94  void add(const std::vector<pbio::ContextTemplate::Ptr>& templates, const std::vector<std::string>& uuids);
95 
96  void remove(const std::string& uuid);
97 
98  void remove(const std::vector<std::string>& uuids);
99 
100  void concat(DynamicTemplateIndex::Ptr otherIndex);
101 
119  std::string getMethodName() const;
120 
122 
123  private:
124  DynamicTemplateIndex(const DHPtr& dll_handle, void* impl, bool weak = false);
125 
126  private:
127  const DHPtr _dll_handle;
128  void* const _impl;
129  int32_t refcounter4light_shared_ptr;
130  bool weak;
131 
132  friend class object_with_ref_counter<DynamicTemplateIndex>;
133  friend class Context;
134  };
135 }
136 
140 
141 namespace pbio
142 {
143  inline DynamicTemplateIndex::DynamicTemplateIndex(const DHPtr& dll_handle, void* impl, bool weak) :
144  _dll_handle(dll_handle),
145  _impl(impl),
146  weak(weak)
147  {
148 
149  }
150 
151  inline std::string DynamicTemplateIndex::getMethodName() const
152  {
153  std::ostringstream name_stream;
154  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
155 
156  void* exception = nullptr;
157 
158  _dll_handle->DynamicTemplateIndex_getMethodName(
159  _impl,
160  &name_stream_wrap,
161  pbio::stl_wraps::WrapOStream::write_func,
162  &exception);
163 
164  checkException(exception, *_dll_handle);
165 
166  return name_stream.str();
167  }
168 
169  inline size_t DynamicTemplateIndex::size() const
170  {
171  void* exception = nullptr;
172 
173  const size_t size = _dll_handle->DynamicTemplateIndex_size(
174  _impl,
175  &exception);
176 
177  checkException(exception, *_dll_handle);
178 
179  return size;
180  }
181 
182  inline size_t DynamicTemplateIndex::capacity() const
183  {
184  void* exception = nullptr;
185 
186  size_t capacity = _dll_handle->DynamicTemplateIndex_capacity(
187  _impl,
188  &exception
189  );
190 
191  checkException(exception, *_dll_handle);
192 
193  return capacity;
194  }
195 
196  inline std::string DynamicTemplateIndex::getUUID(size_t index) const
197  {
198  void* exception = nullptr;
199  std::ostringstream name_stream;
200  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
201 
202  _dll_handle->DynamicTemplateIndex_at_by_index(
203  _impl,
204  index,
205  &name_stream_wrap,
206  pbio::stl_wraps::WrapOStream::write_func,
207  &exception);
208 
209  checkException(exception, *_dll_handle);
210 
211  return name_stream.str();
212  }
213 
214  inline ContextTemplate::Ptr DynamicTemplateIndex::at(const std::string& uuid) const
215  {
216  void* exception = nullptr;
217 
218  void* implementation = _dll_handle->DynamicTemplateIndex_at_by_uuid(
219  _impl,
220  uuid.data(),
221  &exception);
222 
223  checkException(exception, *_dll_handle);
224 
225  return ContextTemplate::Ptr::make(_dll_handle, implementation);
226  }
227 
228  inline ContextTemplate::Ptr DynamicTemplateIndex::get(int64_t index) const
229  {
230  void* exception = nullptr;
231 
232  void* implementation = _dll_handle->DynamicTemplateIndex_get(
233  _impl,
234  index,
235  &exception);
236 
237  checkException(exception, *_dll_handle);
238 
239  return ContextTemplate::Ptr::make(_dll_handle, implementation);
240  }
241 
242  inline void DynamicTemplateIndex::add(pbio::Template::Ptr templ, const std::string& uuid)
243  {
244  void* exception = nullptr;
245 
246  _dll_handle->DynamicTemplateIndex_add_1(_impl, static_cast<pbio::facerec::TemplateImpl*>(templ->_impl), uuid.data(), &exception);
247 
248  checkException(exception, *_dll_handle);
249  }
250 
251  inline void DynamicTemplateIndex::add(const std::vector<pbio::Template::Ptr>& templates, const std::vector<std::string>& uuids)
252  {
253  void* exception = nullptr;
254 
255  std::vector<pbio::facerec::TemplateImpl*> tempTemplates;
256  std::vector<const char*> tempUuids;
257 
258  tempTemplates.reserve(templates.size());
259  tempUuids.reserve(uuids.size());
260 
261  std::transform
262  (
263  templates.begin(), templates.end(), std::back_inserter(tempTemplates),
264  [](pbio::Template::Ptr templ) { return reinterpret_cast<pbio::facerec::TemplateImpl*>(templ->_impl); }
265  );
266  std::transform(uuids.begin(), uuids.end(), std::back_inserter(tempUuids), [](const std::string& uuid) { return uuid.data(); });
267 
268  _dll_handle->DynamicTemplateIndex_add_2(_impl, tempTemplates.data(), tempUuids.data(), templates.size(), &exception);
269 
270  checkException(exception, *_dll_handle);
271  }
272 
273  inline void DynamicTemplateIndex::add(pbio::ContextTemplate::Ptr templ, const std::string& uuid)
274  {
275  void* exception = nullptr;
276 
277  _dll_handle->DynamicTemplateIndex_add_3(_impl, templ->_impl, uuid.data(), &exception);
278 
279  checkException(exception, *_dll_handle);
280  }
281 
282  inline void DynamicTemplateIndex::add(const std::vector<pbio::ContextTemplate::Ptr>& templates, const std::vector<std::string>& uuids)
283  {
284  void* exception = nullptr;
285 
286  std::vector<const void*> tempTemplates;
287  std::vector<const char*> tempUuids;
288 
289  tempTemplates.reserve(templates.size());
290  tempUuids.reserve(uuids.size());
291 
292  std::transform
293  (
294  templates.begin(), templates.end(), std::back_inserter(tempTemplates),
295  [](pbio::ContextTemplate::Ptr templ) { return templ->_impl; }
296  );
297  std::transform(uuids.begin(), uuids.end(), std::back_inserter(tempUuids), [](const std::string& uuid) { return uuid.data(); });
298 
299  _dll_handle->DynamicTemplateIndex_add_4(_impl, tempTemplates.data(), tempUuids.data(), templates.size(), &exception);
300 
301  checkException(exception, *_dll_handle);
302  }
303 
304  inline void DynamicTemplateIndex::remove(const std::string& uuid)
305  {
306  void* exception = nullptr;
307 
308  _dll_handle->DynamicTemplateIndex_remove_1(_impl, uuid.data(), &exception);
309 
310  checkException(exception, *_dll_handle);
311  }
312 
313  inline void DynamicTemplateIndex::remove(const std::vector<std::string>& uuids)
314  {
315  void* exception = nullptr;
316  std::vector<const char*> data;
317 
318  data.reserve(uuids.size());
319 
320  std::transform(uuids.begin(), uuids.end(), std::back_inserter(data), [](const std::string& uuid) { return uuid.data(); });
321 
322  _dll_handle->DynamicTemplateIndex_remove_2(_impl, data.data(), uuids.size(), &exception);
323 
324  checkException(exception, *_dll_handle);
325  }
326 
327  inline void DynamicTemplateIndex::concat(DynamicTemplateIndex::Ptr otherIndex)
328  {
329  void* exception = nullptr;
330 
331  _dll_handle->DynamicTemplateIndex_concatenate(_impl, otherIndex->_impl, &exception);
332 
333  checkException(exception, *_dll_handle);
334  }
335 
336  inline DynamicTemplateIndex::~DynamicTemplateIndex()
337  {
338  if (_impl && !weak)
339  {
340  _dll_handle->DynamicTemplateIndex_destructor(_impl);
341  }
342  }
343 }
344 #endif
size_t size() const
Get a number of templates in the index. Thread-safe.
Definition: DynamicTemplateIndex.h:169
LightSmartPtr< Template >::tPtr Ptr
Alias for the type of a smart pointer to Template.
Definition: Template.h:46
Error - the class of exceptions thrown when errors occur.
std::string getUUID(size_t index) const
Get the uuid of the i-th template. Thread-safe.
Definition: DynamicTemplateIndex.h:196
Definition: SmartPtr.h:84
LightSmartPtr< DynamicTemplateIndex >::tPtr Ptr
Alias for the type of a smart pointer to DynamicTemplateIndex.
Definition: DynamicTemplateIndex.h:34
std::string getMethodName() const
Get a method name. Thread-safe.
Definition: DynamicTemplateIndex.h:151
Context is an interface object for storing data and interacting with methods from the Processing Bloc...
Definition: Context.h:52
SmartPtr.
LightSmartPtr< ContextTemplate >::tPtr Ptr
Alias for the type of a smart pointer to ContextTemplate.
Definition: ContextTemplate.h:47
Interface object for working with the template index.
Definition: DynamicTemplateIndex.h:26