From ebf49f78a6b88dcea9110df24a65e54eb8c39a37 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sun, 15 Apr 2012 17:32:51 -0400 Subject: forgotten file --- rst_parser/arc_ff_factory.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 rst_parser/arc_ff_factory.h (limited to 'rst_parser') 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 +#include +#include + +struct ArcFFFactoryBase { + virtual boost::shared_ptr Create(const std::string& param) const = 0; +}; + +template +struct ArcFFFactory : public ArcFFFactoryBase { + boost::shared_ptr Create(const std::string& param) const { + return boost::shared_ptr(new FF(param)); + } +}; + +struct ArcFFRegistry { + boost::shared_ptr Create(const std::string& name, const std::string& param) const { + std::map::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 facts; +}; + +std::ostream& operator<<(std::ostream& os, const ArcFFRegistry& reg) { + for (std::map::const_iterator it = reg.facts.begin(); + it != reg.facts.end(); ++it) { + os << " " << it->first << std::endl; + } + return os; +} + +#endif -- cgit v1.2.3