Audacity 3.2.0
VersionId.cpp
Go to the documentation of this file.
1/*!********************************************************************
2 Audacity: A Digital Audio Editor
3
4 @file VersionId.h
5 @brief Declare a class with version number manipulation.
6
7 Anton Gerasimov
8 **********************************************************************/
9#include "VersionId.h"
10
11VersionId::VersionId(int version, int release, int revision, int patch)
12 : mVersion(version),
13 mRelease(release),
14 mRevision(revision),
15 mPatch(patch)
16{}
17
18wxString VersionId::MakeString(int version, int release, int revision, int patch)
19{
20 if (patch == 0)
21 return std::to_string(version)
22 + "." + std::to_string(release)
23 + "." + std::to_string(revision);
24 else
25 return std::to_string(version)
26 + "." + std::to_string(release)
27 + "." + std::to_string(revision)
28 + "." + std::to_string(patch);
29}
30
31VersionId VersionId::ParseFromString(wxString& versionString)
32{
33 auto versionStringParts = wxSplit(versionString, '.');
34
35 // If we have corrupted version string,
36 // then return the zero version number, that not allow us to update.
37 const auto size = versionStringParts.size();
38 if (size < 2 || size > 4)
39 return VersionId{};
40
41 VersionId versionId;
42
43 const auto fields = { &versionId.mVersion, &versionId.mRelease,
44 &versionId.mRevision, &versionId.mPatch };
45
46 auto currentField = fields.begin();
47
48 for (auto& v : versionStringParts)
49 {
50 if (v.empty() || !v.IsNumber())
51 return VersionId{};
52
53 **currentField = std::stoi(v.ToStdString());
54 ++currentField;
55 }
56
57 return versionId;
58}
59
60wxString VersionId::GetString() const
61{
63}
64
66{
67 return std::tie(mVersion, mRelease, mRevision, mPatch) ==
68 std::tie(other.mVersion, other.mRelease, other.mRevision, other.mPatch);
69}
70
72{
73 return !(*this == other);
74}
75
77{
78 return std::tie(mVersion, mRelease, mRevision, mPatch) <
79 std::tie(other.mVersion, other.mRelease, other.mRevision, other.mPatch);
80}
81
83{
84 return !(*this < other) && (*this != other);
85}
Declare a class with version number manipulation.
A class, that supports base manipulation with version number.
Definition: VersionId.h:19
bool operator!=(const VersionId &other)
Definition: VersionId.cpp:71
bool operator==(const VersionId &other)
Definition: VersionId.cpp:65
static VersionId ParseFromString(wxString &versionString)
Parse and return version object from version string like "1.2.3".
Definition: VersionId.cpp:31
wxString GetString() const
Make string with version by MakeString() from instance values.
Definition: VersionId.cpp:60
bool operator>(const VersionId &other)
Definition: VersionId.cpp:82
int mRevision
Definition: VersionId.h:42
int mRelease
Definition: VersionId.h:41
VersionId()=default
Creates an zero version object.
int mVersion
Definition: VersionId.h:40
int mPatch
Definition: VersionId.h:43
bool operator<(const VersionId &other)
Definition: VersionId.cpp:76
static wxString MakeString(int version, int release, int revision, int patch)
Creates version string like "1.2.3" by parameters.
Definition: VersionId.cpp:18