summaryrefslogtreecommitdiff
path: root/rst_parser
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-04-15 17:32:51 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-04-15 17:32:51 -0400
commitebf49f78a6b88dcea9110df24a65e54eb8c39a37 (patch)
treea60ba909b3029c65720d7b7fada268c390ee0708 /rst_parser
parentad068c70c8d608dd0dca7e9c7a94b51b2d6a28ba (diff)
forgotten file
Diffstat (limited to 'rst_parser')
-rw-r--r--rst_parser/arc_ff_factory.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/rst_parser/arc_ff_factory.h b/rst_parser/arc_ff_factory.h
new file mode 100644
index 00000000..4237fd5d
--- /dev/null
+++ b/rst_parser/arc_ff_factory.h
@@ -0,0 +1,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