versionnumber.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "versionnumber.h"
00022
00023 VersionNumber::VersionNumber()
00024 {
00025 }
00026
00027 VersionNumber::VersionNumber(const QString & value)
00028 {
00029 helper_setValue(value);
00030 }
00031
00032 VersionNumber::VersionNumber(const VersionNumber & value)
00033 {
00034 helper_copyFromHere(value);
00035 }
00036
00037 VersionNumber::VersionNumber(const qint64 value)
00038 {
00039 helper_setValue(QString::number(value));
00040 }
00041
00042 VersionNumber::~VersionNumber()
00043 {
00044 }
00045
00046 QString VersionNumber::toString() const
00047 {
00048 return theString;
00049 }
00050
00051 VersionNumber VersionNumber::operator=(const VersionNumber & value)
00052 {
00053 helper_copyFromHere(value);
00054 return *this;
00055 }
00056
00057 VersionNumber VersionNumber::operator=(const QString & value)
00058 {
00059 helper_setValue(value);
00060 return *this;
00061 }
00062
00063 VersionNumber VersionNumber::operator=(qint64 value)
00064 {
00065 helper_setValue(QString::number(value));
00066 return *this;
00067 }
00068
00069 bool VersionNumber::operator<(const VersionNumber & value) const
00070 {
00071 return (whichIsBigger(*this, value) == second_one);
00072 }
00073
00074 bool VersionNumber::operator<=(const VersionNumber & value) const
00075 {
00076 return (! (whichIsBigger(*this, value) == first_one));
00077 }
00078
00079 bool VersionNumber::operator>(const VersionNumber & value) const
00080 {
00081 return (whichIsBigger(*this, value) == first_one);
00082 }
00083
00084 bool VersionNumber::operator>=(const VersionNumber & value) const
00085 {
00086 return (!(whichIsBigger(*this, value) == second_one));
00087 }
00088
00089 bool VersionNumber::operator==(const VersionNumber & value) const
00090 {
00091 return (whichIsBigger(*this, value) == both_are_equal);
00092 }
00093
00094 bool VersionNumber::operator!=(const VersionNumber & value) const
00095 {
00096 return (!(whichIsBigger(*this, value) == both_are_equal));
00097 }
00098
00099 void VersionNumber::helper_setValue(const QString & value)
00100 {
00101 theString = value;
00102 if (value.contains(':')) {
00103
00104 epoch = helper_createNumberWithPointsAndDashes(value.section(':', 0, 0));
00105
00106 version_and_release = helper_createNumberWithPointsAndDashes(value.section(':', 1));
00107 } else {
00108 epoch = helper_createNumberWithPointsAndDashes(QChar('0'));
00109 version_and_release = helper_createNumberWithPointsAndDashes(value);
00110 };
00111 }
00112
00113 VersionNumber::characterType VersionNumber::helper_characterType(const QChar & value)
00114 {
00115
00116 characterType returnValue;
00117
00118
00119 if (value.isLetter()) {
00120 returnValue = letter;
00121 } else {
00122 if (value.isDigit()) {
00123 returnValue = digit;
00124 } else {
00125 returnValue = other;
00126 };
00127 };
00128 return returnValue;
00129 }
00130
00131 VersionNumber::simpleNumber VersionNumber::helper_createSimpleNumber(const QString & value)
00132 {
00133
00134 simpleNumber returnValue;
00135 int i;
00136 characterType oldCharacterType;
00137 characterType newCharacterType;
00138 QString stack;
00139
00140
00141 if (value.size() > 0) {
00142 oldCharacterType = helper_characterType(value.at(0));
00143
00144 for (i=0; i<value.size(); ++i) {
00145 newCharacterType = helper_characterType(value.at(i));
00146 if (newCharacterType == oldCharacterType) {
00147 stack += value.at(i);
00148 } else {
00149 returnValue.append(stack);
00150 stack.clear();
00151 stack += value.at(i);
00152 oldCharacterType = newCharacterType;
00153 };
00154 };
00155 returnValue.append(stack);
00156 };
00157 return returnValue;
00158 }
00159
00160 VersionNumber::numberWithPoints VersionNumber::helper_createNumberWithPoints(
00161 const QString & value)
00162 {
00163
00164 numberWithPoints returnValue;
00165 QStringList m_list;
00166 int i;
00167
00168
00169 m_list = value.split('-');
00170 for (i=0; i<m_list.size(); i++) {
00171 returnValue.append(helper_createSimpleNumber(m_list.at(i)));
00172 };
00173 return returnValue;
00174 }
00175
00176 VersionNumber::numberWithPointsAndDashes VersionNumber::helper_createNumberWithPointsAndDashes(
00177 const QString & value)
00178 {
00179
00180 numberWithPointsAndDashes returnValue;
00181 QStringList m_list;
00182 int i;
00183
00184
00185 m_list = value.split('-');
00186 for (i=0; i<m_list.size(); i++) {
00187 returnValue.append(helper_createNumberWithPoints(m_list.at(i)));
00188 };
00189 return returnValue;
00190 }
00191
00192 void VersionNumber::helper_copyFromHere(const VersionNumber & value)
00193 {
00194 theString = value.theString;
00195 epoch = value.epoch;
00196 version_and_release = value.version_and_release;
00197 }
00198
00199 VersionNumber::type_whichIsBigger VersionNumber::whichIsBigger(const VersionNumber & firstValue,
00200 const VersionNumber & secondValue)
00201 {
00202
00203 type_whichIsBigger temp;
00204 type_whichIsBigger returnValue;
00205
00206
00207 temp = whichIsBigger(firstValue.epoch, secondValue.epoch);
00208 if (temp != both_are_equal) {
00209 returnValue = temp;
00210 } else {
00211 returnValue = whichIsBigger(firstValue.version_and_release, secondValue.version_and_release);
00212 };
00213 return returnValue;
00214 }
00215
00216 VersionNumber::type_whichIsBigger VersionNumber::whichIsBigger(
00217 const numberWithPointsAndDashes & firstValue,
00218 const numberWithPointsAndDashes & secondValue)
00219 {
00220
00221 type_whichIsBigger temp;
00222 bool abort;
00223 int i;
00224
00225
00226 i = 0;
00227 abort = false;
00228 while (abort == false) {
00229 if (firstValue.size() > i) {
00230
00231 if (secondValue.size() > i) {
00232 temp = whichIsBigger(firstValue.at(i), secondValue.at(i));
00233 if (temp != both_are_equal) {
00234 abort = true;
00235 };
00236 } else {
00237 temp = first_one;
00238 abort = true;
00239 };
00240
00241 } else {
00242
00243 if (secondValue.size() > i) {
00244 temp = second_one;
00245 abort = true;
00246 } else {
00247 temp = both_are_equal;
00248 abort = true;
00249 };
00250
00251 };
00252 i = i+1;
00253 };
00254 return temp;
00255 }
00256
00257 VersionNumber::type_whichIsBigger VersionNumber::whichIsBigger(
00258 const numberWithPoints & firstValue,
00259 const numberWithPoints & secondValue)
00260 {
00261
00262
00263 type_whichIsBigger temp;
00264 bool abort;
00265 int i;
00266
00267
00268 i = 0;
00269 abort = false;
00270 while (abort == false) {
00271 if (firstValue.size() > i) {
00272
00273 if (secondValue.size() > i) {
00274 temp = whichIsBigger(firstValue.at(i), secondValue.at(i));
00275 if (temp != both_are_equal) {
00276 abort = true;
00277 };
00278 } else {
00279 temp = first_one;
00280 abort = true;
00281 };
00282
00283 } else {
00284
00285 if (secondValue.size() > i) {
00286 temp = second_one;
00287 abort = true;
00288 } else {
00289 temp = both_are_equal;
00290 abort = true;
00291 };
00292
00293 };
00294 i = i+1;
00295 };
00296 return temp;
00297 }
00298
00299 VersionNumber::type_whichIsBigger VersionNumber::whichIsBigger(const simpleNumber & firstValue,
00300 const simpleNumber & secondValue)
00301 {
00302
00303
00304 type_whichIsBigger temp;
00305 bool abort;
00306 int i;
00307
00308
00309 i = 0;
00310 abort = false;
00311 while (abort == false) {
00312 if (firstValue.size() > i) {
00313
00314 if (secondValue.size() > i) {
00315 temp = whichIsBigger(firstValue.at(i), secondValue.at(i));
00316 if (temp != both_are_equal) {
00317 abort = true;
00318 };
00319 } else {
00320 temp = first_one;
00321 abort = true;
00322 };
00323
00324 } else {
00325
00326 if (secondValue.size() > i) {
00327 temp = second_one;
00328 abort = true;
00329 } else {
00330 temp = both_are_equal;
00331 abort = true;
00332 };
00333
00334 };
00335 i = i+1;
00336 };
00337 return temp;
00338 }
00339
00340 VersionNumber::type_whichIsBigger VersionNumber::helper_whichNumberIsBigger(
00341 const QString & firstValue,
00342 const QString & secondValue)
00343 {
00344
00345 quint64 m_firstNumber;
00346 quint64 m_secondNumber;
00347 quint64 m_firstStringSize;
00348 quint64 m_secondStringSize;
00349 type_whichIsBigger returnValue;
00350
00351
00352 m_firstNumber = firstValue.toULongLong();
00353 m_secondNumber = secondValue.toULongLong();
00354 if (m_firstNumber > m_secondNumber) {
00355 returnValue = first_one;
00356 } else if (m_firstNumber < m_secondNumber) {
00357 returnValue = second_one;
00358 } else {
00359 m_firstStringSize = firstValue.size();
00360 m_secondStringSize = secondValue.size();
00361 if (m_firstStringSize > m_secondStringSize) {
00362 returnValue = first_one;
00363 } else if (m_firstStringSize < m_secondStringSize) {
00364 returnValue = second_one;
00365 } else {
00366 returnValue = both_are_equal;
00367 };
00368 };
00369 return returnValue;
00370 }
00371
00372 VersionNumber::type_whichIsBigger VersionNumber::helper_whichStringIsBigger(
00373 const QString & firstValue,
00374 const QString & secondValue)
00375 {
00376
00377 type_whichIsBigger returnValue;
00378
00379
00380 if (firstValue > secondValue) {
00381 returnValue = first_one;
00382 } else if (firstValue < secondValue) {
00383 returnValue = second_one;
00384 } else {
00385 returnValue = both_are_equal;
00386 };
00387 return returnValue;
00388 }
00389
00390 VersionNumber::type_whichIsBigger VersionNumber::whichIsBigger(const QString & firstValue,
00391 const QString & secondValue)
00392 {
00393
00394 type_whichIsBigger returnValue;
00395
00396
00397 if (firstValue.at(0).isDigit() && secondValue.at(0).isDigit()) {
00398 returnValue = helper_whichNumberIsBigger(firstValue, secondValue);
00399 } else {
00400 returnValue = helper_whichStringIsBigger(firstValue, secondValue);
00401 };
00402 return returnValue;
00403 }