mosesdecoder/search/context.hh

50 lines
1.1 KiB
C++
Raw Normal View History

2012-10-15 16:58:33 +04:00
#ifndef SEARCH_CONTEXT__
#define SEARCH_CONTEXT__
#include "search/config.hh"
#include "search/vertex.hh"
#include <boost/pool/object_pool.hpp>
namespace search {
class ContextBase {
public:
2012-11-15 22:04:07 +04:00
explicit ContextBase(const Config &config) : config_(config) {}
2012-10-15 16:58:33 +04:00
VertexNode *NewVertexNode() {
VertexNode *ret = vertex_node_pool_.construct();
assert(ret);
return ret;
}
void DeleteVertexNode(VertexNode *node) {
vertex_node_pool_.destroy(node);
}
2012-11-15 22:04:07 +04:00
unsigned int PopLimit() const { return config_.PopLimit(); }
2012-10-15 16:58:33 +04:00
2012-11-15 22:04:07 +04:00
Score LMWeight() const { return config_.LMWeight(); }
2012-10-15 16:58:33 +04:00
2012-11-15 22:04:07 +04:00
const Config &GetConfig() const { return config_; }
2012-11-15 22:04:07 +04:00
private:
2012-10-15 16:58:33 +04:00
boost::object_pool<VertexNode> vertex_node_pool_;
2012-11-15 22:04:07 +04:00
Config config_;
2012-10-15 16:58:33 +04:00
};
template <class Model> class Context : public ContextBase {
public:
Context(const Config &config, const Model &model) : ContextBase(config), model_(model) {}
const Model &LanguageModel() const { return model_; }
private:
const Model &model_;
};
} // namespace search
#endif // SEARCH_CONTEXT__