#include "sdversion.h"
#include <QRegExp>
#include <QStringList>


SdVersion::SdVersion(int major, int minor, int build, int revision)
{
    this->major = major;
    this->minor = minor;
    this->build = build;
    this->revision = revision;
}

SdVersion::SdVersion(QString str)
{
    clear();
    QRegExp rx("(\\d+\\.)");
    //QStringList list;
    while ((pos = rx.indexIn(str, pos)) != -1) {
        list << rx.cap(1);
        pos += rx.matchedLength();
    }

    size = list.size();
    if (size)
    {
        major = list.at(0).toInt();
        if (size >= 2) minor = list.at(1).toInt();
        if (size >= 3) build = list.at(2).toInt();
        if (size >= 4) revision = list.at(3).toInt();
        if (size > 4)
        {
            ;//
        }
    }else
    {
        ;//bad str!
    }
    // list: ["12", "14", "99", "231", "7"]

}

void SdVersion::clear()
{
    major = 0;
    minor = 0;
    build = 0;
    revision = 0;
}

bool SdVersion::operator>(SdVersion v)
{
    if (major>v.major) return true;
    if (major<v.major) return false;
    if (minor>v.minor) return true;
    if (minor<v.minor) return false;
    if (build>v.build) return true;
    if (build<v.build) return false;
    if (revision>v.revision) return true;
    if (revision<v.revision) return false;
    return false;
}

bool SdVersion::operator<(SdVersion v)
{
    if (major<v.major) return true;
    if (major>v.major) return false;
    if (minor<v.minor) return true;
    if (minor>v.minor) return false;
    if (build<v.build) return true;
    if (build>v.build) return false;
    if (revision<v.revision) return true;
    if (revision>v.revision) return false;
    return false;
}

bool SdVersion::operator<=(SdVersion v)
{
    if (major<v.major) return true;
    if (major>v.major) return false;
    if (minor<v.minor) return true;
    if (minor>v.minor) return false;
    if (build<v.build) return true;
    if (build>v.build) return false;
    if (revision<v.revision) return true;
    if (revision>v.revision) return false;
    return true;
}

bool SdVersion::operator>=(SdVersion v)
{
    if (major>v.major) return true;
    if (major<v.major) return false;
    if (minor>v.minor) return true;
    if (minor<v.minor) return false;
    if (build>v.build) return true;
    if (build<v.build) return false;
    if (revision>v.revision) return true;
    if (revision<v.revision) return false;
    return true;
}

bool SdVersion::operator==(SdVersion v)
{
    if (major!=v.major) return false;
    if (minor!=v.minor) return false;
    if (build!=v.build) return false;
    if (revision!=v.revision) return false;
    return true;
}

