xbmc
AddonVersion.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <string>
12 
13 namespace ADDON
14 {
15 /* \brief Addon versioning using the debian versioning scheme
16 
17  CAddonVersion uses debian versioning, which means in the each section of the period
18  separated version string, numbers are compared numerically rather than lexicographically,
19  thus any preceding zeros are ignored.
20 
21  i.e. 1.00 is considered the same as 1.0, and 1.01 is considered the same as 1.1.
22 
23  Further, 1.0 < 1.0.0
24 
25  See here for more info: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
26  */
28 {
29 public:
30  explicit CAddonVersion(const char* version = nullptr);
31  explicit CAddonVersion(const std::string& version);
32 
33  CAddonVersion(const CAddonVersion& other) = default;
34  CAddonVersion(CAddonVersion&& other) = default;
35  CAddonVersion& operator=(const CAddonVersion& other) = default;
36  CAddonVersion& operator=(CAddonVersion&& other) = default;
37 
38  virtual ~CAddonVersion() = default;
39 
40  int Epoch() const { return mEpoch; }
41  const std::string& Upstream() const { return mUpstream; }
42  const std::string& Revision() const { return mRevision; }
43 
44  bool operator<(const CAddonVersion& other) const;
45  bool operator>(const CAddonVersion& other) const;
46  bool operator<=(const CAddonVersion& other) const;
47  bool operator>=(const CAddonVersion& other) const;
48  bool operator==(const CAddonVersion& other) const;
49  bool operator!=(const CAddonVersion& other) const;
50  std::string asString() const;
51  bool empty() const;
52 
53  static bool SplitFileName(std::string& ID, std::string& version, const std::string& filename);
54 
55 protected:
56  int mEpoch;
57  std::string mUpstream;
58  std::string mRevision;
59 
60  static int CompareComponent(const char* a, const char* b);
61 };
62 } // namespace ADDON
Definition: AddonVersion.h:27
static int CompareComponent(const char *a, const char *b)
Compare two components of a Debian-style version.
Definition: AddonVersion.cpp:71
Definition: Addon.cpp:39