blob: 4237fd5dbc35c3a2f70cca570c518675babc2169 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#ifndef _ARC_FF_FACTORY_H_
#define _ARC_FF_FACTORY_H_
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
struct ArcFFFactoryBase {
virtual boost::shared_ptr<ArcFeatureFunction> Create(const std::string& param) const = 0;
};
template<class FF>
struct ArcFFFactory : public ArcFFFactoryBase {
boost::shared_ptr<ArcFeatureFunction> Create(const std::string& param) const {
return boost::shared_ptr<ArcFeatureFunction>(new FF(param));
}
};
struct ArcFFRegistry {
boost::shared_ptr<ArcFeatureFunction> Create(const std::string& name, const std::string& param) const {
std::map<std::string, ArcFFFactoryBase*>::const_iterator it = facts.find(name);
assert(it != facts.end());
return it->second->Create(param);
}
void Register(const std::string& name, ArcFFFactoryBase* fact) {
ArcFFFactoryBase*& f = facts[name];
assert(f == NULL);
f = fact;
}
std::map<std::string, ArcFFFactoryBase*> facts;
};
std::ostream& operator<<(std::ostream& os, const ArcFFRegistry& reg) {
for (std::map<std::string, ArcFFFactoryBase*>::const_iterator it = reg.facts.begin();
it != reg.facts.end(); ++it) {
os << " " << it->first << std::endl;
}
return os;
}
#endif
|