Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
ModuleFactory.h
1#pragma once
2#include "TypeFactory.h"
3class Module;
5{
6 TypeFactory<Module*, size_t, boost::function<Module*()> > factory;
7 using id_and_hash = std::pair<int, size_t>;
8 boost::container::flat_map<id_and_hash, Module*> modules_map;
9public:
10 Module *removeModule(int id, size_t type_id);
11 void registerType(size_t type_id, boost::function<Module*()> make);
12 template<class ...args>
13 Module *createModule(int id, size_t type_id, args&&... a) {
14 auto idnhash = std::make_pair(id, type_id);
15 auto it = modules_map.find(idnhash);
16 if (it != modules_map.end())
17 return it->second;
18 Module* module = factory.create(type_id, a...);
19 if (module)
20 modules_map.insert(std::make_pair(idnhash, module));
21 return module;
22 }
23};
Definition ModuleFactory.h:5
Module * removeModule(int id, size_t type_id)
boost::container::flat_map< id_and_hash, Module * > modules_map
Definition ModuleFactory.h:8
std::pair< int, size_t > id_and_hash
Definition ModuleFactory.h:7
TypeFactory< Module *, size_t, boost::function< Module *()> > factory
Definition ModuleFactory.h:6
Module * createModule(int id, size_t type_id, args &&... a)
Definition ModuleFactory.h:13
void registerType(size_t type_id, boost::function< Module *()> make)
Definition Module.h:151