1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
/*
* This file is part of the xTuple ERP: PostBooks Edition, a free and
* open source Enterprise Resource Planning software suite,
* Copyright (c) 1999-2010 by OpenMFG LLC, d/b/a xTuple.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
#include "xversion.h"
#include <QStringList>
#include <QObject>
#include <QRegExp>
#define DEBUG false
XVersion::XVersion()
: _major(-1), _minor(-1), _point(-1), _stage(UNKNOWN), _substage(-1)
{
}
XVersion::XVersion(const QString &pString)
: _major(-1), _minor(-1), _point(-1), _stage(UNKNOWN), _substage(-1)
{
setVersion(pString);
}
XVersion::XVersion(const XVersion &pVersion)
{
_major = pVersion._major;
_minor = pVersion._minor;
_point = pVersion._point;
_stage = pVersion._stage;
_substage = pVersion._substage;
}
XVersion::~XVersion()
{
}
bool XVersion::isValid() const
{
if (_major == -1 || _stage == UNKNOWN)
return false;
else
return true;
}
void XVersion::setVersion(const QString &pString)
{
QStringList suffixes;
suffixes << "wip" << "alpha" << "beta" << "rc";
QRegExp relregex("^(\\d+)\\.(\\d+)(\\.\\d+)?(?:(" +
suffixes.join("|") +
")(\\d*)?)?$");
if (relregex.indexIn(pString.toLower()) == -1)
return;
if (relregex.cap(1).isEmpty())
return;
_major = relregex.cap(1).toInt();
if (relregex.cap(2).isEmpty())
return;
_minor = relregex.cap(2).toInt();
if (! relregex.cap(3).isEmpty())
_point = relregex.cap(3).mid(1).toInt();
if (relregex.cap(4).isEmpty())
{
_stage = FINAL;
_substage = 0;
}
else switch (suffixes.indexOf(relregex.cap(4)))
{
case 0: _stage = WIP; _substage = 0; break;
case 1: _stage = ALPHA; _substage = 0; break;
case 2: _stage = BETA; _substage = 0; break;
case 3: _stage = RC; _substage = 0; break;
default: _stage = UNKNOWN; break;
}
if (! relregex.cap(5).isEmpty())
_substage = relregex.cap(5).toInt();
}
int XVersion::majorNumber(bool &ok) const
{
ok = (_major >= 0);
return _major;
}
int XVersion::minorNumber(bool &ok) const
{
ok = (_minor >= 0);
return _minor;
}
int XVersion::pointNumber(bool &ok) const
{
if (_point >= 0)
{
ok = true;
return _point;
}
else
{
ok = false;
return 0;
}
}
XVersion::ReleaseStage XVersion::stage(bool &ok) const
{
ok = (_stage != UNKNOWN);
return _stage;
}
int XVersion::substageNumber(bool &ok) const
{
ok = (_substage >= 0);
return _substage;
}
QString XVersion::toString() const
{
QString result = QObject::tr("invalid");
if (_major >= 0)
{
result = QString::number(_major);
if (_minor >= 0)
{
result += "." + QString::number(_minor);
if (_point >= 0)
{
result += "." + QString::number(_point);
}
}
switch (_stage)
{
case WIP: result += "wip"; break;
case ALPHA: result += "alpha"; break;
case BETA: result += "beta"; break;
case RC: result += "rc"; break;
case FINAL: break;
case UNKNOWN:
default: result = QObject::tr("invalid");
}
if (_substage > 0 && (_stage == WIP ||
_stage == ALPHA ||
_stage == BETA ||
_stage == RC))
result += QString::number(_substage);
}
return result;
}
// NOTE:
// all of the comparisons return false if either version is obviously invalid
bool XVersion::operator==(XVersion other)
{
bool ok;
if (! isValid() || ! other.isValid())
return false;
else
return (_major == other._major &&
_minor == other._minor &&
pointNumber(ok) == other.pointNumber(ok) && // treat uninit as 0
_stage == other._stage &&
_substage == other._substage);
}
/* can't simple say if (major > other.major && minor > other.minor ...
because v2.3 > v1.4 but 3 < 4 and so would fail here: ^^^^^^^^^^^^^^^^^^
*/
bool XVersion::operator>(XVersion other)
{
if (! isValid() || !other.isValid()) return false;
else if (_major > other._major) return true;
else if (_major < other._major) return false;
else if (_minor > other._minor) return true;
else if (_minor < other._minor) return false;
else if (_point > other._point) return true;
else if (_point < other._point) return false;
else if (_stage > other._stage) return true;
else if (_stage < other._stage) return false;
else return (_substage > other._substage);
}
bool XVersion::operator>=(XVersion other)
{
if (! isValid() || ! other.isValid())
return false;
else
return (*this == other || *this > other);
}
bool XVersion::operator< (XVersion other)
{
if (! isValid() || ! other.isValid())
return false;
else
return !(*this == other || *this > other);
}
bool XVersion::operator<=(XVersion other)
{
if (! isValid() || ! other.isValid())
return false;
else
return (*this == other || *this < other);
}
bool XVersion::operator!=(XVersion other)
{
if (! isValid() || ! other.isValid())
return false;
else
return ! (*this == other);
}
|