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     AddonVersion 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     */
27   class AddonVersion
28   {
29   public:
AddonVersion(const AddonVersion & other)30     AddonVersion(const AddonVersion& other) { *this = other; }
31     explicit AddonVersion(const std::string& version);
32     explicit AddonVersion(const char* version = nullptr);
33     virtual ~AddonVersion() = default;
34 
Epoch()35     int Epoch() const { return mEpoch; }
Upstream()36     const std::string &Upstream() const { return mUpstream; }
Revision()37     const std::string &Revision() const { return mRevision; }
38 
39     AddonVersion& operator=(const AddonVersion& other);
40     bool operator< (const AddonVersion& other) const;
41     bool operator> (const AddonVersion& other) const;
42     bool operator<=(const AddonVersion& other) const;
43     bool operator>=(const AddonVersion& other) const;
44     bool operator==(const AddonVersion& other) const;
45     bool operator!=(const AddonVersion& other) const;
46     std::string asString() const;
47     bool empty() const;
48 
49     static bool SplitFileName(std::string& ID, std::string& version,
50                               const std::string& filename);
51 
52   protected:
53     int mEpoch;
54     std::string mUpstream;
55     std::string mRevision;
56 
57     static int CompareComponent(const char *a, const char *b);
58   };
59 
60   inline AddonVersion& AddonVersion::operator=(const AddonVersion& other) = default;
61 }
62