ProjectVersion.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /*! \brief Version number parsing and comparison
  29. *
  30. * Parses and compares version information. i.e. "1.0.3" < "1.0.10"
  31. */
  32. class ProjectVersion
  33. {
  34. public:
  35. enum CompareType { Major, Minor, Release, Stage, Build };
  36. ProjectVersion(QString version, CompareType c = Build);
  37. ProjectVersion(const char * version, CompareType c = Build);
  38. int getMajor() const { return m_major; }
  39. int getMinor() const { return m_minor; }
  40. int getRelease() const { return m_release; }
  41. QString getStage() const { return m_stage; }
  42. int getBuild() const { return m_build; }
  43. CompareType getCompareType() const { return m_compareType; }
  44. ProjectVersion setCompareType(CompareType compareType) { m_compareType = compareType; return * this; }
  45. static int compare(const ProjectVersion& a, const ProjectVersion& b, CompareType c);
  46. static int compare(ProjectVersion v1, ProjectVersion v2);
  47. private:
  48. QString m_version;
  49. int m_major;
  50. int m_minor;
  51. int m_release;
  52. QString m_stage;
  53. int m_build;
  54. CompareType m_compareType;
  55. } ;
  56. /*
  57. * ProjectVersion v. ProjectVersion
  58. */
  59. inline bool operator<(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) < 0; }
  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. #endif