3DiVi Face SDK  3.28.0
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Свойства Группы
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 
104  void save(const std::string& filePath, bool allowOverwrite) const;
105 
123  std::string getMethodName() const;
124 
126 
127  private:
128  DynamicTemplateIndex(const DHPtr& dll_handle, void* impl, bool weak = false);
129 
130  private:
131  const DHPtr _dll_handle;
132  void* const _impl;
133  int32_t refcounter4light_shared_ptr;
134  bool weak;
135 
136  friend class object_with_ref_counter<DynamicTemplateIndex>;
137  friend class Context;
138  };
139 }
140 
144 
145 namespace pbio
146 {
147  inline DynamicTemplateIndex::DynamicTemplateIndex(const DHPtr& dll_handle, void* impl, bool weak) :
148  _dll_handle(dll_handle),
149  _impl(impl),
150  weak(weak)
151  {
152 
153  }
154 
155  inline std::string DynamicTemplateIndex::getMethodName() const
156  {
157  std::ostringstream name_stream;
158  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
159 
160  void* exception = nullptr;
161 
162  _dll_handle->DynamicTemplateIndex_getMethodName(
163  _impl,
164  &name_stream_wrap,
165  pbio::stl_wraps::WrapOStream::write_func,
166  &exception);
167 
168  checkException(exception, *_dll_handle);
169 
170  return name_stream.str();
171  }
172 
173  inline size_t DynamicTemplateIndex::size() const
174  {
175  void* exception = nullptr;
176 
177  const size_t size = _dll_handle->DynamicTemplateIndex_size(
178  _impl,
179  &exception);
180 
181  checkException(exception, *_dll_handle);
182 
183  return size;
184  }
185 
186  inline size_t DynamicTemplateIndex::capacity() const
187  {
188  void* exception = nullptr;
189 
190  size_t capacity = _dll_handle->DynamicTemplateIndex_capacity(
191  _impl,
192  &exception
193  );
194 
195  checkException(exception, *_dll_handle);
196 
197  return capacity;
198  }
199 
200  inline std::string DynamicTemplateIndex::getUUID(size_t index) const
201  {
202  void* exception = nullptr;
203  std::ostringstream name_stream;
204  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
205 
206  _dll_handle->DynamicTemplateIndex_at_by_index(
207  _impl,
208  index,
209  &name_stream_wrap,
210  pbio::stl_wraps::WrapOStream::write_func,
211  &exception);
212 
213  checkException(exception, *_dll_handle);
214 
215  return name_stream.str();
216  }
217 
218  inline ContextTemplate::Ptr DynamicTemplateIndex::at(const std::string& uuid) const
219  {
220  void* exception = nullptr;
221 
222  void* implementation = _dll_handle->DynamicTemplateIndex_at_by_uuid(
223  _impl,
224  uuid.data(),
225  &exception);
226 
227  checkException(exception, *_dll_handle);
228 
229  return ContextTemplate::Ptr::make(_dll_handle, implementation);
230  }
231 
232  inline ContextTemplate::Ptr DynamicTemplateIndex::get(int64_t index) const
233  {
234  void* exception = nullptr;
235 
236  void* implementation = _dll_handle->DynamicTemplateIndex_get(
237  _impl,
238  index,
239  &exception);
240 
241  checkException(exception, *_dll_handle);
242 
243  return ContextTemplate::Ptr::make(_dll_handle, implementation);
244  }
245 
246  inline void DynamicTemplateIndex::add(pbio::Template::Ptr templ, const std::string& uuid)
247  {
248  void* exception = nullptr;
249 
250  _dll_handle->DynamicTemplateIndex_add_1(_impl, static_cast<pbio::facerec::TemplateImpl*>(templ->_impl), uuid.data(), &exception);
251 
252  checkException(exception, *_dll_handle);
253  }
254 
255  inline void DynamicTemplateIndex::add(const std::vector<pbio::Template::Ptr>& templates, const std::vector<std::string>& uuids)
256  {
257  void* exception = nullptr;
258 
259  std::vector<pbio::facerec::TemplateImpl*> tempTemplates;
260  std::vector<const char*> tempUuids;
261 
262  tempTemplates.reserve(templates.size());
263  tempUuids.reserve(uuids.size());
264 
265  std::transform
266  (
267  templates.begin(), templates.end(), std::back_inserter(tempTemplates),
268  [](pbio::Template::Ptr templ) { return reinterpret_cast<pbio::facerec::TemplateImpl*>(templ->_impl); }
269  );
270  std::transform(uuids.begin(), uuids.end(), std::back_inserter(tempUuids), [](const std::string& uuid) { return uuid.data(); });
271 
272  _dll_handle->DynamicTemplateIndex_add_2(_impl, tempTemplates.data(), tempUuids.data(), templates.size(), &exception);
273 
274  checkException(exception, *_dll_handle);
275  }
276 
277  inline void DynamicTemplateIndex::add(pbio::ContextTemplate::Ptr templ, const std::string& uuid)
278  {
279  void* exception = nullptr;
280 
281  _dll_handle->DynamicTemplateIndex_add_3(_impl, templ->_impl, uuid.data(), &exception);
282 
283  checkException(exception, *_dll_handle);
284  }
285 
286  inline void DynamicTemplateIndex::add(const std::vector<pbio::ContextTemplate::Ptr>& templates, const std::vector<std::string>& uuids)
287  {
288  void* exception = nullptr;
289 
290  std::vector<const void*> tempTemplates;
291  std::vector<const char*> tempUuids;
292 
293  tempTemplates.reserve(templates.size());
294  tempUuids.reserve(uuids.size());
295 
296  std::transform
297  (
298  templates.begin(), templates.end(), std::back_inserter(tempTemplates),
299  [](pbio::ContextTemplate::Ptr templ) { return templ->_impl; }
300  );
301  std::transform(uuids.begin(), uuids.end(), std::back_inserter(tempUuids), [](const std::string& uuid) { return uuid.data(); });
302 
303  _dll_handle->DynamicTemplateIndex_add_4(_impl, tempTemplates.data(), tempUuids.data(), templates.size(), &exception);
304 
305  checkException(exception, *_dll_handle);
306  }
307 
308  inline void DynamicTemplateIndex::remove(const std::string& uuid)
309  {
310  void* exception = nullptr;
311 
312  _dll_handle->DynamicTemplateIndex_remove_1(_impl, uuid.data(), &exception);
313 
314  checkException(exception, *_dll_handle);
315  }
316 
317  inline void DynamicTemplateIndex::remove(const std::vector<std::string>& uuids)
318  {
319  void* exception = nullptr;
320  std::vector<const char*> data;
321 
322  data.reserve(uuids.size());
323 
324  std::transform(uuids.begin(), uuids.end(), std::back_inserter(data), [](const std::string& uuid) { return uuid.data(); });
325 
326  _dll_handle->DynamicTemplateIndex_remove_2(_impl, data.data(), uuids.size(), &exception);
327 
328  checkException(exception, *_dll_handle);
329  }
330 
331  inline void DynamicTemplateIndex::concat(DynamicTemplateIndex::Ptr otherIndex)
332  {
333  void* exception = nullptr;
334 
335  _dll_handle->DynamicTemplateIndex_concatenate(_impl, otherIndex->_impl, &exception);
336 
337  checkException(exception, *_dll_handle);
338  }
339 
340  inline void DynamicTemplateIndex::clear()
341  {
342  void* exception = nullptr;
343 
344  _dll_handle->DynamicTemplateIndex_clear(_impl, &exception);
345 
346  checkException(exception, *_dll_handle);
347  }
348 
349  inline void DynamicTemplateIndex::save(const std::string& filePath, bool allowOverwrite) const
350  {
351  void* exception = nullptr;
352 
353  _dll_handle->DynamicTemplateIndex_save(_impl, filePath.data(), allowOverwrite, &exception);
354 
355  checkException(exception, *_dll_handle);
356  }
357 
358  inline DynamicTemplateIndex::~DynamicTemplateIndex()
359  {
360  if (_impl && !weak)
361  {
362  _dll_handle->DynamicTemplateIndex_destructor(_impl);
363  }
364  }
365 }
366 #endif
size_t size() const
Получить количество шаблонов в индексе. Потокобезопасный.
Definition: DynamicTemplateIndex.h:173
LightSmartPtr< Template >::tPtr Ptr
Псевдоним для типа умного указателя на Template.
Definition: Template.h:46
Error - класс исключений, выбрасываемых при возникновении ошибок.
std::string getUUID(size_t index) const
Получить uuid i-го шаблона. Потокобезопасный.
Definition: DynamicTemplateIndex.h:200
Definition: SmartPtr.h:84
LightSmartPtr< DynamicTemplateIndex >::tPtr Ptr
Псевдоним для типа умного указателя на DynamicTemplateIndex.
Definition: DynamicTemplateIndex.h:34
std::string getMethodName() const
Получить имя метода. Потокобезопасный.
Definition: DynamicTemplateIndex.h:155
Context - интерфейсный объект для хранения данных и взаимодействия с методами из Processing Block API...
Definition: Context.h:48
SmartPtr.
LightSmartPtr< ContextTemplate >::tPtr Ptr
Псевдоним для типа умного указателя на ContextTemplate.
Definition: ContextTemplate.h:47
Интерфейсный объект для работы с индексом шаблонов.
Definition: DynamicTemplateIndex.h:26