Source

gpalign-cpp / src / core.cpp

Full commit
//--------------------------------------------------------------------------//
// core.cpp
// Lars Yencken <lars.yencken@gmail.com>
// vim: ts=4 sw=4 sts=4 expandtab:
// Sun Oct  7 02:23:15 EST 2007
//--------------------------------------------------------------------------//

#include "core.hpp"
#include "stringOps.hpp"

#include <boost/functional/hash.hpp>

const wstring gp_sep = L" ";

//--------------------------------------------------------------------------//

Segment::Segment()
{
}

//--------------------------------------------------------------------------//

Segment::Segment(Grapheme gm, Phoneme pm)
    :
g(gm),
p(pm)
{
}

//--------------------------------------------------------------------------//

Segment::Segment(const wchar_t* gm, const wchar_t* pm)
    :
g(gm),
p(pm)
{
}

//--------------------------------------------------------------------------//

Segment Segment::operator+(const Segment& rhs) const
{
    return Segment(g + rhs.g, p + rhs.p);
}

//--------------------------------------------------------------------------//

bool Segment::operator==(const Segment& rhs) const
{
    return g == rhs.g && p == rhs.p;
}

//--------------------------------------------------------------------------//

bool Segment::operator<(const Segment& rhs) const
{
    return g < rhs.g || (g == rhs.g && p < rhs.p);
}

//--------------------------------------------------------------------------//

size_t hash_value(const Segment& s)
{
    return boost::hash_value(make_pair(s.g, s.p));
}

//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//

bool AlignmentCloud::isValid() const
{
    return candidates.size() > 0;
}

//--------------------------------------------------------------------------//

bool AlignmentCloud::isResolved() const
{
    return candidates.size() == 1;
}

//--------------------------------------------------------------------------//

Alignment AlignmentCloud::getBest() const
{
    return candidates[bestIndex];
}

//--------------------------------------------------------------------------//

wostream& operator<<(wostream& oStream, const Segment& s)
{
    oStream << s.g << gp_sep << s.p;
    return oStream;
}

//--------------------------------------------------------------------------//

wostream& operator<<(wostream& oStream, const Alignment& a)
{
    vector<wstring> slots;
    const int nSlots = a.size();
    slots.reserve(nSlots);
    for (int i = 0; i < nSlots; i++) {
        slots.push_back(a[i].g);
    }
    oStream << join(slots, L"|") << gp_sep;
    slots.clear();
    for (int i = 0; i < nSlots; i++) {
        slots.push_back(a[i].p);
    }
    oStream << join(slots, L"|");
    return oStream;
}

//--------------------------------------------------------------------------//

wostream& operator<<(wostream& oStream, const BaseAlignment& ba)
{
    oStream << ba.first << ":" << ba.second;
    return oStream;
}

//--------------------------------------------------------------------------//