11 #include <nx/vms_server_plugins/analytics/stub/object_detection/objects/vector2d.h> 12 #include <nx/vms_server_plugins/analytics/stub/object_detection/objects/abstract_object.h> 15 namespace vms_server_plugins {
21 float randomFloat(
float min = 0,
float max = 1);
23 Vector2D randomTrajectory();
28 using ObjectFactory = std::function<std::unique_ptr<AbstractObject>()>;
31 struct ObjectFactoryContext
33 ObjectFactoryContext(std::type_index key, ObjectFactory factory):
35 factory(std::move(factory))
40 ObjectFactory factory;
44 template<
typename ObjectType>
45 void registerObjectFactory(ObjectFactory objectFactory)
47 std::lock_guard<std::mutex> lock(m_mutex);
49 auto it = std::find_if(
52 [](
const ObjectFactoryContext& value)
54 return std::type_index(
typeid(ObjectType)) == value.key;
57 if (it == m_registry.cend())
58 m_registry.emplace_back(
typeid(ObjectType), objectFactory);
60 *it = ObjectFactoryContext{std::type_index(
typeid(ObjectType)), objectFactory};
63 template<
typename ObjectType>
64 void unregisterObjectFactory()
66 std::lock_guard<std::mutex> lock(m_mutex);
68 auto it = std::find_if(
71 [](
const ObjectFactoryContext& value)
73 return std::type_index(
typeid(ObjectType)) == value.key;
76 if (it == m_registry.cend())
82 std::unique_ptr<AbstractObject> generate()
const;
85 mutable std::mutex m_mutex;
86 std::vector<ObjectFactoryContext> m_registry;
Definition: apple_utils.h:6