Revert "use Cast() throughout"

This reverts commit 8b1e9f45ad.
This commit is contained in:
Hieu Hoang 2016-08-03 21:34:47 +01:00
parent 2abc631251
commit 32b9efd775
11 changed files with 31 additions and 34 deletions

View File

@ -35,8 +35,8 @@ HypothesisBase::HypothesisBase(MemPool &pool, const System &system)
m_ffStates = (FFState **) pool.Allocate(sizeof(FFState*) * numStatefulFFs);
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs){
size_t statefulInd = sfff->GetStatefulInd();
FFState *state = sfff->BlankState(pool, system);
size_t statefulInd = sfff->GetStatefulInd();
FFState *state = sfff->BlankState(pool, system);
m_ffStates[statefulInd] = state;
}
}

View File

@ -33,10 +33,6 @@ public:
const T &Cast() const
{ return static_cast<const T&>(*this); }
template<typename T>
T &Cast()
{ return static_cast<T&>(*this); }
const Scores &GetScores() const
{ return *m_scores; }
Scores &GetScores()

View File

@ -79,7 +79,7 @@ void Search::Decode(size_t stackInd)
BOOST_FOREACH(const InputPathBase *path, paths){
BOOST_FOREACH(const HypothesisBase *hypo, hypos) {
Extend(hypo->Cast<Hypothesis>(), *static_cast<const InputPath*>(path));
Extend(*static_cast<const Hypothesis*>(hypo), *static_cast<const InputPath*>(path));
}
}
@ -156,7 +156,7 @@ const Hypothesis *Search::GetBestHypothesis() const
const Hypothesis *best = NULL;
if (sortedHypos.size()) {
best = &sortedHypos[0]->Cast<Hypothesis>();
best = static_cast<const Hypothesis*>(sortedHypos[0]);
}
return best;
}
@ -165,8 +165,8 @@ void Search::AddInitialTrellisPaths(TrellisPaths<TrellisPath> &paths) const
{
const Stack &lastStack = m_stacks.Back();
BOOST_FOREACH(const HypothesisBase *hypoBase, lastStack){
const Hypothesis &hypo = hypoBase->Cast<Hypothesis>();
TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists);
const Hypothesis *hypo = static_cast<const Hypothesis*>(hypoBase);
TrellisPath *path = new TrellisPath(hypo, mgr.arcLists);
paths.Add(path);
}
}

View File

@ -65,7 +65,8 @@ void QueueItem::Init(Manager &mgr, CubeEdge &edge, size_t hypoIndex,
void QueueItem::CreateHypothesis(Manager &mgr)
{
const Hypothesis &prevHypo = edge->hypos[hypoIndex]->Cast<Hypothesis>();
const Hypothesis *prevHypo =
static_cast<const Hypothesis*>(edge->hypos[hypoIndex]);
const TargetPhraseImpl &tp = edge->tps[tpIndex];
//cerr << "hypoIndex=" << hypoIndex << endl;
@ -74,7 +75,7 @@ void QueueItem::CreateHypothesis(Manager &mgr)
//cerr << *prevHypo << endl;
hypo = Hypothesis::Create(mgr.GetSystemPool(), mgr);
hypo->Init(mgr, prevHypo, edge->path, tp, edge->newBitmap,
hypo->Init(mgr, *prevHypo, edge->path, tp, edge->newBitmap,
edge->estimatedScore);
if (!mgr.system.options.cube.lazy_scoring) {

View File

@ -236,8 +236,8 @@ void Search::AddInitialTrellisPaths(TrellisPaths<TrellisPath> &paths) const
BOOST_FOREACH(const Stack::Coll::value_type &val, coll){
const Moses2::HypothesisColl &hypos = *val.second;
BOOST_FOREACH(const HypothesisBase *hypoBase, hypos) {
const Hypothesis &hypo = hypoBase->Cast<Hypothesis>();
TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists);
const Hypothesis *hypo = static_cast<const Hypothesis*>(hypoBase);
TrellisPath *path = new TrellisPath(hypo, mgr.arcLists);
paths.Add(path);
}
}

View File

@ -71,7 +71,7 @@ std::vector<const Hypothesis*> Stack::GetBestHypos(size_t num) const
ret.reserve(ret.size() + hypos.size());
BOOST_FOREACH(const HypothesisBase *hypo, hypos) {
ret.push_back(&hypo->Cast<Hypothesis>());
ret.push_back(static_cast<const Hypothesis*>(hypo));
}
}

View File

@ -27,7 +27,7 @@ Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr)
Hypothesis *ret;
Recycler<HypothesisBase*> &recycler = mgr.GetHypoRecycle();
ret = &recycler.Get()->Cast<Hypothesis>();
ret = static_cast<Hypothesis*>(recycler.Get());
if (ret) {
// got new hypo from recycler. Do nothing
}

View File

@ -78,7 +78,7 @@ void Search::Decode(size_t stackInd)
BOOST_FOREACH(const InputPathBase *path, paths){
BOOST_FOREACH(const HypothesisBase *hypo, hypos) {
Extend(hypo->Cast<Hypothesis>(), *static_cast<const InputPath*>(path));
Extend(*static_cast<const Hypothesis*>(hypo), *static_cast<const InputPath*>(path));
}
}
}
@ -143,7 +143,7 @@ const Hypothesis *Search::GetBestHypothesis() const
const Hypothesis *best = NULL;
if (sortedHypos.size()) {
best = &sortedHypos[0]->Cast<Hypothesis>();
best = static_cast<const Hypothesis*>(sortedHypos[0]);
}
return best;
}
@ -152,10 +152,10 @@ void Search::AddInitialTrellisPaths(TrellisPaths<TrellisPath> &paths) const
{
const Stack &lastStack = m_stacks.Back();
BOOST_FOREACH(const HypothesisBase *hypoBase, lastStack){
const Hypothesis &hypo = hypoBase->Cast<Hypothesis>();
TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists);
paths.Add(path);
}
const Hypothesis *hypo = static_cast<const Hypothesis*>(hypoBase);
TrellisPath *path = new TrellisPath(hypo, mgr.arcLists);
paths.Add(path);
}
}
} // namespace

View File

@ -46,9 +46,9 @@ TrellisPath::TrellisPath(const TrellisPath &origPath, size_t edgeIndex,
nodes.push_back(newNode);
// rest of path comes from following best path backwards
const Hypothesis &arc = newNode.GetHypo()->Cast<Hypothesis>();
const Hypothesis *arc = static_cast<const Hypothesis*>(newNode.GetHypo());
const Hypothesis *prevHypo = arc.GetPrevHypo();
const Hypothesis *prevHypo = arc->GetPrevHypo();
while (prevHypo != NULL) {
const ArcList &arcList = arcLists.GetArcList(prevHypo);
assert(arcList);
@ -108,9 +108,9 @@ std::string TrellisPath::OutputTargetPhrase(const System &system) const
std::stringstream out;
for (int i = nodes.size() - 1; i >= 0; --i) {
const TrellisNode &node = nodes[i];
const Hypothesis &hypo = node.GetHypo()->Cast<Hypothesis>();
const Hypothesis *hypo = static_cast<const Hypothesis*>(node.GetHypo());
//cerr << "hypo=" << hypo << " " << *hypo << endl;
hypo.GetTargetPhrase().OutputToStream(out);
hypo->GetTargetPhrase().OutputToStream(out);
out << " ";
}
return out.str();

View File

@ -18,11 +18,11 @@ namespace SCFG
Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr)
{
// ++g_numHypos;
SCFG::Hypothesis *ret;
Hypothesis *ret;
//ret = new (pool.Allocate<Hypothesis>()) Hypothesis(pool, mgr.system);
Recycler<HypothesisBase*> &recycler = mgr.GetHypoRecycle();
ret = &recycler.Get()->Cast<SCFG::Hypothesis>();
ret = static_cast<Hypothesis*>(recycler.Get());
if (ret) {
// got new hypo from recycler. Do nothing
}
@ -71,10 +71,10 @@ void Hypothesis::Init(SCFG::Manager &mgr,
size_t prevHyposInd = prevHyposIndices[currInd];
assert(prevHyposInd < sortedHypos.size());
const Hypothesis &prevHypo = sortedHypos[prevHyposInd]->Cast<SCFG::Hypothesis>();
m_prevHypos[currInd] = &prevHypo;
const Hypothesis *prevHypo = static_cast<const SCFG::Hypothesis*>(sortedHypos[prevHyposInd]);
m_prevHypos[currInd] = prevHypo;
m_scores->PlusEquals(mgr.system, prevHypo.GetScores());
m_scores->PlusEquals(mgr.system, prevHypo->GetScores());
++currInd;
}

View File

@ -94,10 +94,10 @@ const Hypothesis *Stack::GetBestHypo(
BOOST_FOREACH (const Coll::value_type &valPair, m_coll) {
Moses2::HypothesisColl &hypos = *valPair.second;
const Hypotheses &sortedHypos = hypos.GetSortedAndPruneHypos(mgr, arcLists);
const Hypothesis &bestHypoColl = sortedHypos[0]->Cast<SCFG::Hypothesis>();
const Hypothesis *bestHypoColl = static_cast<const Hypothesis*>(sortedHypos[0]);
if (ret == NULL || ret->GetFutureScore() < bestHypoColl.GetFutureScore()) {
ret = &bestHypoColl;
if (ret == NULL || ret->GetFutureScore() < bestHypoColl->GetFutureScore()) {
ret = bestHypoColl;
}
}