diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-07 00:07:45 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-07 00:07:45 +0000 |
commit | 9db822ad9f2e25d88520e1c61b20052e7dfca6ca (patch) | |
tree | e5375c12fc748af98f871cdb453ba48e95379a55 /decoder/ff_factory.cc | |
parent | f87b2add497d9033ef468233ea3ec0f33cc97944 (diff) |
dynamic fsa ff, factory for fsa and ff shares code, factory moved to ff_factory.cc
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@483 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/ff_factory.cc')
-rw-r--r-- | decoder/ff_factory.cc | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/decoder/ff_factory.cc b/decoder/ff_factory.cc index 88991fbf..b3aeeac1 100644 --- a/decoder/ff_factory.cc +++ b/decoder/ff_factory.cc @@ -6,49 +6,42 @@ using boost::shared_ptr; using namespace std; -FFFactoryBase::~FFFactoryBase() {} +UntypedFactory::~UntypedFactory() { } -void FFRegistry::DisplayList() const { - for (map<string, shared_ptr<FFFactoryBase> >::const_iterator it = reg_.begin(); +namespace { +std::string const& debug_pre="debug"; +} + +void UntypedFactoryRegistry::clear() { + reg_.clear(); +} + +bool UntypedFactoryRegistry::parse_debug(std::string & param) { + int pl=debug_pre.size(); + bool space=false; + std::string p=param; + bool debug=match_begin(p,debug_pre)&& + (p.size()==pl || (space=(p[pl]==' '))); + if (debug) + p.erase(0,debug_pre.size()+space); + return debug; +} + +void UntypedFactoryRegistry::DisplayList() const { + for (Factmap::const_iterator it = reg_.begin(); it != reg_.end(); ++it) { cerr << " " << it->first << endl; } } -string FFRegistry::usage(string const& ffname,bool params,bool verbose) const { - map<string, shared_ptr<FFFactoryBase> >::const_iterator it = reg_.find(ffname); +string UntypedFactoryRegistry::usage(string const& ffname,bool params,bool verbose) const { + Factmap::const_iterator it = reg_.find(ffname); return it == reg_.end() ? "Unknown feature " + ffname : it->second->usage(params,verbose); } -namespace { -std::string const& debug_pre="debug"; -} - -shared_ptr<FeatureFunction> FFRegistry::Create(const string& ffname, const string& param) const { - map<string, shared_ptr<FFFactoryBase> >::const_iterator it = reg_.find(ffname); - shared_ptr<FeatureFunction> res; - if (it == reg_.end()) { - cerr << "I don't know how to create feature " << ffname << endl; - } else { - int pl=debug_pre.size(); - bool space=false; - std::string p=param; - bool debug=match_begin(p,debug_pre)&& - (p.size()==pl || (space=(p[pl]==' '))); - if (debug) { - p.erase(0,debug_pre.size()+space); - cerr<<"debug enabled for "<<ffname<< " - remaining options: '"<<p<<"'\n"; - } - res = it->second->Create(p); - res->name=ffname; - res->debug_=debug; - } - return res; -} - -void FFRegistry::Register(const string& ffname, FFFactoryBase* factory) { +void UntypedFactoryRegistry::Register(const string& ffname, UntypedFactory* factory) { if (reg_.find(ffname) != reg_.end()) { cerr << "Duplicate registration of FeatureFunction with name " << ffname << "!\n"; abort(); @@ -57,7 +50,28 @@ void FFRegistry::Register(const string& ffname, FFFactoryBase* factory) { } -void FFRegistry::Register(FFFactoryBase* factory) +void UntypedFactoryRegistry::Register(UntypedFactory* factory) { Register(factory->usage(false,false),factory); } + + +/*FIXME: I want these to go in ff_factory.cc, but extern etc. isn't workign right: + ../decoder/libcdec.a(ff_factory.o): In function `~UntypedFactory': +/nfs/topaz/graehl/ws10smt/decoder/ff_factory.cc:9: multiple definition of `global_ff_registry' +mr_vest_generate_mapper_input.o:/nfs/topaz/graehl/ws10smt/vest/mr_vest_generate_mapper_input.cc:307: first defined here +*/ +FsaFFRegistry fsa_ff_registry; +FFRegistry ff_registry; + +/* +namespace { +struct null_deleter +{ + template <class F> + void operator()(F const& f) const { } +}; + +boost::shared_ptr<FsaFFRegistry> global_fsa_ff_registry(&fsa_ff_registry,null_deleter()); +boost::shared_ptr<FFRegistry> global_ff_registry(&ff_registry,null_deleter()); +*/ |