This commit is contained in:
Kenneth Heafield 2013-08-22 10:16:24 +01:00
parent 6b5c1a09e4
commit c4dc57f8a3
5 changed files with 36 additions and 1 deletions

View File

@ -264,6 +264,7 @@ public:
#endif
private:
friend void swap(FVector &first, FVector &second);
/** Internal get and set. */
const FValue& get(const FName& name) const;
@ -310,6 +311,11 @@ private:
};
inline void swap(FVector &first, FVector &second) {
swap(first.m_features, second.m_features);
swap(first.m_coreFeatures, second.m_coreFeatures);
}
std::ostream& operator<<( std::ostream& out, const FVector& fv);
//Element-wise operations
const FVector operator+(const FVector& lhs, const FVector& rhs);

View File

@ -63,6 +63,13 @@ public:
/** create phrase from vectors of words */
explicit Phrase(const std::vector< const Word* > &mergeWords);
/* This isn't a swap function because classes inherit from Phrase and might
* not override swap, which would be bad.
*/
void SwapWords(Phrase &other) {
swap(m_words, other.m_words);
}
/** destructor */
virtual ~Phrase();

View File

@ -63,8 +63,11 @@ namespace Moses
class ScoreComponentCollection
{
friend std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection& rhs);
friend void swap(ScoreComponentCollection &first, ScoreComponentCollection &second);
private:
FVector m_scores;
typedef std::pair<size_t,size_t> IndexPair;
typedef std::map<const FeatureFunction*,IndexPair> ScoreIndexMap;
static ScoreIndexMap s_scoreIndexes;
@ -414,5 +417,9 @@ struct SCCPlus {
}
};
inline void swap(ScoreComponentCollection &first, ScoreComponentCollection &second) {
swap(first.m_scores, second.m_scores);
}
}
#endif

View File

@ -201,6 +201,16 @@ void TargetPhrase::Merge(const TargetPhrase &copy, const std::vector<FactorType>
m_fullScore += copy.m_fullScore;
}
void swap(TargetPhrase &first, TargetPhrase &second) {
first.SwapWords(second);
std::swap(first.m_fullScore, second.m_fullScore);
std::swap(first.m_futureScore, second.m_futureScore);
swap(first.m_scoreBreakdown, second.m_scoreBreakdown);
std::swap(first.m_alignTerm, second.m_alignTerm);
std::swap(first.m_alignNonTerm, second.m_alignNonTerm);
std::swap(first.m_lhsTarget, second.m_lhsTarget);
}
TO_STRING_BODY(TargetPhrase);
std::ostream& operator<<(std::ostream& os, const TargetPhrase& tp)

View File

@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef moses_TargetPhrase_h
#define moses_TargetPhrase_h
#include <algorithm>
#include <vector>
#include "TypeDef.h"
#include "Phrase.h"
@ -43,8 +44,10 @@ class InputPath;
*/
class TargetPhrase: public Phrase
{
private:
friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
protected:
friend void swap(TargetPhrase &first, TargetPhrase &second);
float m_fullScore, m_futureScore;
ScoreComponentCollection m_scoreBreakdown;
@ -124,6 +127,8 @@ public:
TO_STRING();
};
void swap(TargetPhrase &first, TargetPhrase &second);
std::ostream& operator<<(std::ostream&, const TargetPhrase&);
/**