ProjectVersion.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ProjectVersion.h - version compared in import upgrades
  3. *
  4. * Copyright (c) 2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
  5. * Copyright (c) 2015 Tres Finocchiaro <tres.finocchiaro/at/gmail.com>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef PROJECT_VERSION_H
  26. #define PROJECT_VERSION_H
  27. #include <QtCore/QString>
  28. #include <QtCore/QStringList>
  29. #include <limits>
  30. /*! \brief Version number parsing and comparison
  31. *
  32. * Parses and compares version information. i.e. "1.0.3" < "1.0.10"
  33. */
  34. class ProjectVersion
  35. {
  36. public:
  37. enum CompareType : int { None = 0, Major=1, Minor=2, Release=3, Stage=4, Build=5, All = std::numeric_limits<int>::max() };
  38. ProjectVersion(QString version, CompareType c = All);
  39. ProjectVersion(const char * version, CompareType c = All);
  40. const QString& getVersion() const { return m_version; }
  41. int getMajor() const { return m_major; }
  42. int getMinor() const { return m_minor; }
  43. int getPatch() const { return m_patch; }
  44. const QStringList& getLabels() const { return m_labels; }
  45. CompareType getCompareType() const { return m_compareType; }
  46. ProjectVersion setCompareType(CompareType compareType) { m_compareType = compareType; return * this; }
  47. static int compare(const ProjectVersion& a, const ProjectVersion& b, CompareType c);
  48. static int compare(ProjectVersion v1, ProjectVersion v2);
  49. private:
  50. QString m_version;
  51. int m_major = 0;
  52. int m_minor = 0;
  53. int m_patch = 0;
  54. QStringList m_labels;
  55. CompareType m_compareType;
  56. } ;
  57. /*
  58. * ProjectVersion v. ProjectVersion
  59. */
  60. inline bool operator<(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) < 0; }
  61. inline bool operator>(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) > 0; }
  62. inline bool operator<=(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) <= 0; }
  63. inline bool operator>=(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) >= 0; }
  64. inline bool operator==(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) == 0; }
  65. inline bool operator!=(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) != 0; }
  66. #endif