LibrePCB Developers Documentation
version.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_VERSION_H
21#define LIBREPCB_CORE_VERSION_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28#include <optional.hpp>
29
30/*******************************************************************************
31 * Namespace / Forward Declarations
32 ******************************************************************************/
33namespace librepcb {
34
35/*******************************************************************************
36 * Class Version
37 ******************************************************************************/
38
58class Version final {
59 Q_DECLARE_TR_FUNCTIONS(Version)
60
61public:
62 // Constructors / Destructor
63
67 Version() = delete;
68
74 Version(const Version& other) noexcept : mNumbers(other.mNumbers) {}
75
79 ~Version() noexcept = default;
80
81 // Getters
82
93 bool isPrefixOf(const Version& other) const noexcept;
94
102 const QVector<uint>& getNumbers() const noexcept { return mNumbers; }
103
109 QString toStr() const noexcept;
110
123 QString toPrettyStr(int minSegCount, int maxSegCount = 10) const noexcept;
124
136 QString toComparableStr() const noexcept;
137
138 // Operator overloadings
139 Version& operator=(const Version& rhs) noexcept {
140 mNumbers = rhs.mNumbers;
141 return *this;
142 }
143
145
152 bool operator>(const Version& rhs) const noexcept {
153 return toComparableStr() > rhs.toComparableStr();
154 }
155 bool operator<(const Version& rhs) const noexcept {
156 return toComparableStr() < rhs.toComparableStr();
157 }
158 bool operator>=(const Version& rhs) const noexcept {
159 return toComparableStr() >= rhs.toComparableStr();
160 }
161 bool operator<=(const Version& rhs) const noexcept {
162 return toComparableStr() <= rhs.toComparableStr();
163 }
164 bool operator==(const Version& rhs) const noexcept {
165 return mNumbers == rhs.mNumbers;
166 }
167 bool operator!=(const Version& rhs) const noexcept {
168 return mNumbers != rhs.mNumbers;
169 }
171
172 // Static Methods
173
182 static bool isValid(const QString& str) noexcept;
183
194 static Version fromString(const QString& str);
195
205 static tl::optional<Version> tryFromString(const QString& str) noexcept;
206
207private: // Methods
208 explicit Version(const QVector<uint>& numbers) noexcept : mNumbers(numbers) {}
209
210private: // Data
216 QVector<uint> mNumbers;
217};
218
219/*******************************************************************************
220 * End of File
221 ******************************************************************************/
222
223} // namespace librepcb
224
225#endif
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
QVector< uint > mNumbers
List of all version numbers of the whole version.
Definition: version.h:216
bool isPrefixOf(const Version &other) const noexcept
Check if this version is the prefix of another version.
Definition: version.cpp:40
const QVector< uint > & getNumbers() const noexcept
Get the numbers in the version string.
Definition: version.h:102
Version(const Version &other) noexcept
Copy constructor.
Definition: version.h:74
QString toStr() const noexcept
Get the version as a string in the format "1.2.3".
Definition: version.cpp:53
bool operator>=(const Version &rhs) const noexcept
Definition: version.h:158
Version(const QVector< uint > &numbers) noexcept
Definition: version.h:208
bool operator==(const Version &rhs) const noexcept
Definition: version.h:164
static tl::optional< Version > tryFromString(const QString &str) noexcept
Try creating a Version object from a string, returning empty optional if invalid.
Definition: version.cpp:102
bool operator!=(const Version &rhs) const noexcept
Definition: version.h:167
Version()=delete
Default constructor (disabled to avoid creating invalid versions)
bool operator>(const Version &rhs) const noexcept
Comparison operators.
Definition: version.h:152
QString toComparableStr() const noexcept
Get the version as a comparable string (59 characters)
Definition: version.cpp:69
~Version() noexcept=default
static Version fromString(const QString &str)
Create a Version object from a string.
Definition: version.cpp:91
static bool isValid(const QString &str) noexcept
Check if a string is a valid version number.
Definition: version.cpp:86
bool operator<=(const Version &rhs) const noexcept
Definition: version.h:161
bool operator<(const Version &rhs) const noexcept
Definition: version.h:155
QString toPrettyStr(int minSegCount, int maxSegCount=10) const noexcept
Get the version as a string with trailing zeros (e.g. "1.2.0")
Definition: version.cpp:57
Definition: occmodel.cpp:77