templatize SubPhrase class

This commit is contained in:
Hieu Hoang 2016-04-27 00:44:15 +04:00
parent 5ed6fe1434
commit d06bdecbd3
2 changed files with 21 additions and 26 deletions

View File

@ -11,28 +11,7 @@ using namespace std;
namespace Moses2
{
const Word &SubPhrase::operator[](size_t pos) const
{
return (*m_origPhrase)[pos + m_start];
}
std::ostream& operator<<(std::ostream &out, const SubPhrase &obj)
{
if (obj.GetSize()) {
out << obj[0];
for (size_t i = 1; i < obj.GetSize(); ++i) {
const Word &word = obj[i];
out << " " << word;
}
}
return out;
}
SubPhrase SubPhrase::GetSubPhrase(size_t start, size_t size) const
{
SubPhrase ret(*m_origPhrase, m_start + start, m_size);
return ret;
}
}

View File

@ -14,19 +14,35 @@ public:
,m_size(size)
{}
virtual const Word& operator[](size_t pos) const;
virtual const Word& operator[](size_t pos) const
{ return (*m_origPhrase)[pos + m_start]; }
virtual size_t GetSize() const
{
return m_size;
}
{ return m_size; }
SubPhrase GetSubPhrase(size_t start, size_t size) const;
SubPhrase GetSubPhrase(size_t start, size_t size) const
{
SubPhrase ret(*m_origPhrase, m_start + start, m_size);
return ret;
}
protected:
const Phrase *m_origPhrase;
size_t m_start, m_size;
};
///////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream &out, const SubPhrase &obj)
{
if (obj.GetSize()) {
out << obj[0];
for (size_t i = 1; i < obj.GetSize(); ++i) {
const Word &word = obj[i];
out << " " << word;
}
}
return out;
}
}