From 32b9efd775a96371c559fca7d5e074e87a65870b Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 3 Aug 2016 21:34:47 +0100 Subject: [PATCH] Revert "use Cast() throughout" This reverts commit 8b1e9f45adefbfa4d426bc1d9b3b7aa28e89d04e. --- contrib/other-builds/moses2/HypothesisBase.cpp | 4 ++-- contrib/other-builds/moses2/HypothesisBase.h | 4 ---- .../other-builds/moses2/PhraseBased/Batch/Search.cpp | 8 ++++---- .../moses2/PhraseBased/CubePruningMiniStack/Misc.cpp | 5 +++-- .../PhraseBased/CubePruningMiniStack/Search.cpp | 4 ++-- .../PhraseBased/CubePruningMiniStack/Stack.cpp | 2 +- .../other-builds/moses2/PhraseBased/Hypothesis.cpp | 2 +- .../moses2/PhraseBased/Normal/Search.cpp | 12 ++++++------ .../other-builds/moses2/PhraseBased/TrellisPath.cpp | 8 ++++---- contrib/other-builds/moses2/SCFG/Hypothesis.cpp | 10 +++++----- contrib/other-builds/moses2/SCFG/Stack.cpp | 6 +++--- 11 files changed, 31 insertions(+), 34 deletions(-) diff --git a/contrib/other-builds/moses2/HypothesisBase.cpp b/contrib/other-builds/moses2/HypothesisBase.cpp index 2a4d7003f..5b19a73da 100644 --- a/contrib/other-builds/moses2/HypothesisBase.cpp +++ b/contrib/other-builds/moses2/HypothesisBase.cpp @@ -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; } } diff --git a/contrib/other-builds/moses2/HypothesisBase.h b/contrib/other-builds/moses2/HypothesisBase.h index 024dc575f..23f5c6474 100644 --- a/contrib/other-builds/moses2/HypothesisBase.h +++ b/contrib/other-builds/moses2/HypothesisBase.h @@ -33,10 +33,6 @@ public: const T &Cast() const { return static_cast(*this); } - template - T &Cast() - { return static_cast(*this); } - const Scores &GetScores() const { return *m_scores; } Scores &GetScores() diff --git a/contrib/other-builds/moses2/PhraseBased/Batch/Search.cpp b/contrib/other-builds/moses2/PhraseBased/Batch/Search.cpp index 8e8af2ab4..9f5bd4f95 100644 --- a/contrib/other-builds/moses2/PhraseBased/Batch/Search.cpp +++ b/contrib/other-builds/moses2/PhraseBased/Batch/Search.cpp @@ -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(), *static_cast(path)); + Extend(*static_cast(hypo), *static_cast(path)); } } @@ -156,7 +156,7 @@ const Hypothesis *Search::GetBestHypothesis() const const Hypothesis *best = NULL; if (sortedHypos.size()) { - best = &sortedHypos[0]->Cast(); + best = static_cast(sortedHypos[0]); } return best; } @@ -165,8 +165,8 @@ void Search::AddInitialTrellisPaths(TrellisPaths &paths) const { const Stack &lastStack = m_stacks.Back(); BOOST_FOREACH(const HypothesisBase *hypoBase, lastStack){ - const Hypothesis &hypo = hypoBase->Cast(); - TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists); + const Hypothesis *hypo = static_cast(hypoBase); + TrellisPath *path = new TrellisPath(hypo, mgr.arcLists); paths.Add(path); } } diff --git a/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Misc.cpp b/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Misc.cpp index 2e0227626..2af2b35f0 100644 --- a/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Misc.cpp +++ b/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Misc.cpp @@ -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(); + const Hypothesis *prevHypo = + static_cast(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) { diff --git a/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Search.cpp b/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Search.cpp index 197ebfaed..564b6186a 100644 --- a/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Search.cpp +++ b/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Search.cpp @@ -236,8 +236,8 @@ void Search::AddInitialTrellisPaths(TrellisPaths &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(); - TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists); + const Hypothesis *hypo = static_cast(hypoBase); + TrellisPath *path = new TrellisPath(hypo, mgr.arcLists); paths.Add(path); } } diff --git a/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Stack.cpp b/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Stack.cpp index 54e9d212e..03c2a823f 100644 --- a/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Stack.cpp +++ b/contrib/other-builds/moses2/PhraseBased/CubePruningMiniStack/Stack.cpp @@ -71,7 +71,7 @@ std::vector Stack::GetBestHypos(size_t num) const ret.reserve(ret.size() + hypos.size()); BOOST_FOREACH(const HypothesisBase *hypo, hypos) { - ret.push_back(&hypo->Cast()); + ret.push_back(static_cast(hypo)); } } diff --git a/contrib/other-builds/moses2/PhraseBased/Hypothesis.cpp b/contrib/other-builds/moses2/PhraseBased/Hypothesis.cpp index 2d57cafa1..13a33d3a2 100644 --- a/contrib/other-builds/moses2/PhraseBased/Hypothesis.cpp +++ b/contrib/other-builds/moses2/PhraseBased/Hypothesis.cpp @@ -27,7 +27,7 @@ Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr) Hypothesis *ret; Recycler &recycler = mgr.GetHypoRecycle(); - ret = &recycler.Get()->Cast(); + ret = static_cast(recycler.Get()); if (ret) { // got new hypo from recycler. Do nothing } diff --git a/contrib/other-builds/moses2/PhraseBased/Normal/Search.cpp b/contrib/other-builds/moses2/PhraseBased/Normal/Search.cpp index fa28cc042..66505a56e 100644 --- a/contrib/other-builds/moses2/PhraseBased/Normal/Search.cpp +++ b/contrib/other-builds/moses2/PhraseBased/Normal/Search.cpp @@ -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(), *static_cast(path)); + Extend(*static_cast(hypo), *static_cast(path)); } } } @@ -143,7 +143,7 @@ const Hypothesis *Search::GetBestHypothesis() const const Hypothesis *best = NULL; if (sortedHypos.size()) { - best = &sortedHypos[0]->Cast(); + best = static_cast(sortedHypos[0]); } return best; } @@ -152,10 +152,10 @@ void Search::AddInitialTrellisPaths(TrellisPaths &paths) const { const Stack &lastStack = m_stacks.Back(); BOOST_FOREACH(const HypothesisBase *hypoBase, lastStack){ - const Hypothesis &hypo = hypoBase->Cast(); - TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists); - paths.Add(path); - } + const Hypothesis *hypo = static_cast(hypoBase); + TrellisPath *path = new TrellisPath(hypo, mgr.arcLists); + paths.Add(path); +} } } // namespace diff --git a/contrib/other-builds/moses2/PhraseBased/TrellisPath.cpp b/contrib/other-builds/moses2/PhraseBased/TrellisPath.cpp index bec12e843..6addfcae1 100644 --- a/contrib/other-builds/moses2/PhraseBased/TrellisPath.cpp +++ b/contrib/other-builds/moses2/PhraseBased/TrellisPath.cpp @@ -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(); + const Hypothesis *arc = static_cast(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(); + const Hypothesis *hypo = static_cast(node.GetHypo()); //cerr << "hypo=" << hypo << " " << *hypo << endl; - hypo.GetTargetPhrase().OutputToStream(out); + hypo->GetTargetPhrase().OutputToStream(out); out << " "; } return out.str(); diff --git a/contrib/other-builds/moses2/SCFG/Hypothesis.cpp b/contrib/other-builds/moses2/SCFG/Hypothesis.cpp index aa0358d5d..27e412aea 100644 --- a/contrib/other-builds/moses2/SCFG/Hypothesis.cpp +++ b/contrib/other-builds/moses2/SCFG/Hypothesis.cpp @@ -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(pool, mgr.system); Recycler &recycler = mgr.GetHypoRecycle(); - ret = &recycler.Get()->Cast(); + ret = static_cast(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(); - m_prevHypos[currInd] = &prevHypo; + const Hypothesis *prevHypo = static_cast(sortedHypos[prevHyposInd]); + m_prevHypos[currInd] = prevHypo; - m_scores->PlusEquals(mgr.system, prevHypo.GetScores()); + m_scores->PlusEquals(mgr.system, prevHypo->GetScores()); ++currInd; } diff --git a/contrib/other-builds/moses2/SCFG/Stack.cpp b/contrib/other-builds/moses2/SCFG/Stack.cpp index 927f8e061..b1bc58c74 100644 --- a/contrib/other-builds/moses2/SCFG/Stack.cpp +++ b/contrib/other-builds/moses2/SCFG/Stack.cpp @@ -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(); + const Hypothesis *bestHypoColl = static_cast(sortedHypos[0]); - if (ret == NULL || ret->GetFutureScore() < bestHypoColl.GetFutureScore()) { - ret = &bestHypoColl; + if (ret == NULL || ret->GetFutureScore() < bestHypoColl->GetFutureScore()) { + ret = bestHypoColl; } }