3DiVi Face SDK  3.26.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 
102  void clear();
103 
121  std::string getMethodName() const;
122 
124 
125  private:
126  DynamicTemplateIndex(const DHPtr& dll_handle, void* impl, bool weak = false);
127 
128  private:
129  const DHPtr _dll_handle;
130  void* const _impl;
131  int32_t refcounter4light_shared_ptr;
132  bool weak;
133 
134  friend class object_with_ref_counter<DynamicTemplateIndex>;
135  friend class Context;
136  };
137 }
138 
142 
143 namespace pbio
144 {
145  inline DynamicTemplateIndex::DynamicTemplateIndex(const DHPtr& dll_handle, void* impl, bool weak) :
146  _dll_handle(dll_handle),
147  _impl(impl),
148  weak(weak)
149  {
150 
151  }
152 
153  inline std::string DynamicTemplateIndex::getMethodName() const
154  {
155  std::ostringstream name_stream;
156  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
157 
158  void* exception = nullptr;
159 
160  _dll_handle->DynamicTemplateIndex_getMethodName(
161  _impl,
162  &name_stream_wrap,
163  pbio::stl_wraps::WrapOStream::write_func,
164  &exception);
165 
166  checkException(exception, *_dll_handle);
167 
168  return name_stream.str();
169  }
170 
171  inline size_t DynamicTemplateIndex::size() const
172  {
173  void* exception = nullptr;
174 
175  const size_t size = _dll_handle->DynamicTemplateIndex_size(
176  _impl,
177  &exception);
178 
179  checkException(exception, *_dll_handle);
180 
181  return size;
182  }
183 
184  inline size_t DynamicTemplateIndex::capacity() const
185  {
186  void* exception = nullptr;
187 
188  size_t capacity = _dll_handle->DynamicTemplateIndex_capacity(
189  _impl,
190  &exception
191  );
192 
193  checkException(exception, *_dll_handle);
194 
195  return capacity;
196  }
197 
198  inline std::string DynamicTemplateIndex::getUUID(size_t index) const
199  {
200  void* exception = nullptr;
201  std::ostringstream name_stream;
202  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
203 
204  _dll_handle->DynamicTemplateIndex_at_by_index(
205  _impl,
206  index,
207  &name_stream_wrap,
208  pbio::stl_wraps::WrapOStream::write_func,
209  &exception);
210 
211  checkException(exception, *_dll_handle);
212 
213  return name_stream.str();
214  }
215 
216  inline ContextTemplate::Ptr DynamicTemplateIndex::at(const std::string& uuid) const
217  {
218  void* exception = nullptr;
219 
220  void* implementation = _dll_handle->DynamicTemplateIndex_at_by_uuid(
221  _impl,
222  uuid.data(),
223  &exception);
224 
225  checkException(exception, *_dll_handle);
226 
227  return ContextTemplate::Ptr::make(_dll_handle, implementation);
228  }
229 
230  inline ContextTemplate::Ptr DynamicTemplateIndex::get(int64_t index) const
231  {
232  void* exception = nullptr;
233 
234  void* implementation = _dll_handle->DynamicTemplateIndex_get(
235  _impl,
236  index,
237  &exception);
238 
239  checkException(exception, *_dll_handle);
240 
241  return ContextTemplate::Ptr::make(_dll_handle, implementation);
242  }
243 
244  inline void DynamicTemplateIndex::add(pbio::Template::Ptr templ, const std::string& uuid)
245  {
246  void* exception = nullptr;
247 
248  _dll_handle->DynamicTemplateIndex_add_1(_impl, static_cast<pbio::facerec::TemplateImpl*>(templ->_impl), uuid.data(), &exception);
249 
250  checkException(exception, *_dll_handle);
251  }
252 
253  inline void DynamicTemplateIndex::add(const std::vector<pbio::Template::Ptr>& templates, const std::vector<std::string>& uuids)
254  {
255  void* exception = nullptr;
256 
257  std::vector<pbio::facerec::TemplateImpl*> tempTemplates;
258  std::vector<const char*> tempUuids;
259 
260  tempTemplates.reserve(templates.size());
261  tempUuids.reserve(uuids.size());
262 
263  std::transform
264  (
265  templates.begin(), templates.end(), std::back_inserter(tempTemplates),
266  [](pbio::Template::Ptr templ) { return reinterpret_cast<pbio::facerec::TemplateImpl*>(templ->_impl); }
267  );
268  std::transform(uuids.begin(), uuids.end(), std::back_inserter(tempUuids), [](const std::string& uuid) { return uuid.data(); });
269 
270  _dll_handle->DynamicTemplateIndex_add_2(_impl, tempTemplates.data(), tempUuids.data(), templates.size(), &exception);
271 
272  checkException(exception, *_dll_handle);
273  }
274 
275  inline void DynamicTemplateIndex::add(pbio::ContextTemplate::Ptr templ, const std::string& uuid)
276  {
277  void* exception = nullptr;
278 
279  _dll_handle->DynamicTemplateIndex_add_3(_impl, templ->_impl, uuid.data(), &exception);
280 
281  checkException(exception, *_dll_handle);
282  }
283 
284  inline void DynamicTemplateIndex::add(const std::vector<pbio::ContextTemplate::Ptr>& templates, const std::vector<std::string>& uuids)
285  {
286  void* exception = nullptr;
287 
288  std::vector<const void*> tempTemplates;
289  std::vector<const char*> tempUuids;
290 
291  tempTemplates.reserve(templates.size());
292  tempUuids.reserve(uuids.size());
293 
294  std::transform
295  (
296  templates.begin(), templates.end(), std::back_inserter(tempTemplates),
297  [](pbio::ContextTemplate::Ptr templ) { return templ->_impl; }
298  );
299  std::transform(uuids.begin(), uuids.end(), std::back_inserter(tempUuids), [](const std::string& uuid) { return uuid.data(); });
300 
301  _dll_handle->DynamicTemplateIndex_add_4(_impl, tempTemplates.data(), tempUuids.data(), templates.size(), &exception);
302 
303  checkException(exception, *_dll_handle);
304  }
305 
306  inline void DynamicTemplateIndex::remove(const std::string& uuid)
307  {
308  void* exception = nullptr;
309 
310  _dll_handle->DynamicTemplateIndex_remove_1(_impl, uuid.data(), &exception);
311 
312  checkException(exception, *_dll_handle);
313  }
314 
315  inline void DynamicTemplateIndex::remove(const std::vector<std::string>& uuids)
316  {
317  void* exception = nullptr;
318  std::vector<const char*> data;
319 
320  data.reserve(uuids.size());
321 
322  std::transform(uuids.begin(), uuids.end(), std::back_inserter(data), [](const std::string& uuid) { return uuid.data(); });
323 
324  _dll_handle->DynamicTemplateIndex_remove_2(_impl, data.data(), uuids.size(), &exception);
325 
326  checkException(exception, *_dll_handle);
327  }
328 
329  inline void DynamicTemplateIndex::concat(DynamicTemplateIndex::Ptr otherIndex)
330  {
331  void* exception = nullptr;
332 
333  _dll_handle->DynamicTemplateIndex_concatenate(_impl, otherIndex->_impl, &exception);
334 
335  checkException(exception, *_dll_handle);
336  }
337 
338  inline void DynamicTemplateIndex::clear()
339  {
340  void* exception = nullptr;
341 
342  _dll_handle->DynamicTemplateIndex_clear(_impl, &exception);
343 
344  checkException(exception, *_dll_handle);
345  }
346 
347  inline DynamicTemplateIndex::~DynamicTemplateIndex()
348  {
349  if (_impl && !weak)
350  {
351  _dll_handle->DynamicTemplateIndex_destructor(_impl);
352  }
353  }
354 }
355 #endif
size_t size() const
Get a number of templates in the index. Thread-safe.
Definition: DynamicTemplateIndex.h:171
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:198
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:153
Context is an interface object for storing data and interacting with methods from the Processing Bloc...
Definition: Context.h:48
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