From f80891a7c4a2834efc476ce4d29cc6c438e567f0 Mon Sep 17 00:00:00 2001 From: graehl Date: Wed, 21 Jul 2010 20:12:44 +0000 Subject: Score::Clone() via CRTP git-svn-id: https://ws10smt.googlecode.com/svn/trunk@360 ec762483-ff6d-05da-a07a-a48fb63a330f --- vest/aer_scorer.cc | 2 +- vest/comb_scorer.cc | 2 +- vest/scorer.cc | 4 ++-- vest/scorer.h | 12 ++++++++++++ vest/ter.cc | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) (limited to 'vest') diff --git a/vest/aer_scorer.cc b/vest/aer_scorer.cc index 81ffae76..25b58b5e 100644 --- a/vest/aer_scorer.cc +++ b/vest/aer_scorer.cc @@ -9,7 +9,7 @@ using namespace std; -class AERScore : public Score { +class AERScore : public ScoreBase { friend class AERScorer; public: AERScore() : num_matches(), num_predicted(), num_in_ref() {} diff --git a/vest/comb_scorer.cc b/vest/comb_scorer.cc index a921aa4d..9fc37868 100644 --- a/vest/comb_scorer.cc +++ b/vest/comb_scorer.cc @@ -4,7 +4,7 @@ using namespace std; -class BLEUTERCombinationScore : public Score { +class BLEUTERCombinationScore : public ScoreBase { friend class BLEUTERCombinationScorer; public: ~BLEUTERCombinationScore(); diff --git a/vest/scorer.cc b/vest/scorer.cc index 05269a3b..5671de38 100644 --- a/vest/scorer.cc +++ b/vest/scorer.cc @@ -87,7 +87,7 @@ float SentenceScorer::ComputeRefLength(const Sentence &hyp) const { const std::string* SentenceScorer::GetSource() const { return NULL; } -class SERScore : public Score { +class SERScore : public ScoreBase { friend class SERScorer; public: SERScore() : correct(0), total(0) {} @@ -151,7 +151,7 @@ class SERScorer : public SentenceScorer { vector > refs_; }; -class BLEUScore : public Score { +class BLEUScore : public ScoreBase { friend class BLEUScorerBase; public: BLEUScore(int n) : correct_ngram_hit_counts(float(0),n), hyp_ngram_counts(float(0),n) { diff --git a/vest/scorer.h b/vest/scorer.h index 0d90f378..0c8b380f 100644 --- a/vest/scorer.h +++ b/vest/scorer.h @@ -46,6 +46,18 @@ class Score : public boost::intrusive_refcount { virtual void Encode(std::string* out) const = 0; static ScoreP GetZero(ScoreType type); static ScoreP GetOne(ScoreType type); + virtual ScoreP Clone() const = 0; +protected: + Score() { } // we define these explicitly because refcount is noncopyable + Score(Score const& o) { } +}; + +//TODO: make sure default copy ctors for score types do what we want. +template +struct ScoreBase : public Score { + ScoreP Clone() const { + return ScoreP(new Derived(dynamic_cast(*this))); + } }; class SentenceScorer { diff --git a/vest/ter.cc b/vest/ter.cc index 8c8494ad..cacc5b00 100644 --- a/vest/ter.cc +++ b/vest/ter.cc @@ -412,7 +412,7 @@ class TERScorerImpl { } }; -class TERScore : public Score { +class TERScore : public ScoreBase { friend class TERScorer; public: -- cgit v1.2.3