LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Version Class Referencefinal

The Version class represents a version number in the format "1.42.7". More...

#include <version.h>

+ Collaboration diagram for Version:

Public Member Functions

 Version ()=delete
 Default constructor (disabled to avoid creating invalid versions) More...
 
 Version (const Version &other) noexcept
 Copy constructor. More...
 
 ~Version () noexcept=default
 
bool isPrefixOf (const Version &other) const noexcept
 Check if this version is the prefix of another version. More...
 
const QVector< uint > & getNumbers () const noexcept
 Get the numbers in the version string. More...
 
QString toStr () const noexcept
 Get the version as a string in the format "1.2.3". More...
 
QString toPrettyStr (int minSegCount, int maxSegCount=10) const noexcept
 Get the version as a string with trailing zeros (e.g. "1.2.0") More...
 
QString toComparableStr () const noexcept
 Get the version as a comparable string (59 characters) More...
 
Versionoperator= (const Version &rhs) noexcept
 
bool operator> (const Version &rhs) const noexcept
 Comparison operators. More...
 
bool operator< (const Version &rhs) const noexcept
 Comparison operators. More...
 
bool operator>= (const Version &rhs) const noexcept
 Comparison operators. More...
 
bool operator<= (const Version &rhs) const noexcept
 Comparison operators. More...
 
bool operator== (const Version &rhs) const noexcept
 Comparison operators. More...
 
bool operator!= (const Version &rhs) const noexcept
 Comparison operators. More...
 

Static Public Member Functions

static bool isValid (const QString &str) noexcept
 Check if a string is a valid version number. More...
 
static Version fromString (const QString &str)
 Create a Version object from a string. More...
 
static tl::optional< VersiontryFromString (const QString &str) noexcept
 Try creating a Version object from a string, returning empty optional if invalid. More...
 

Private Member Functions

 Version (const QVector< uint > &numbers) noexcept
 

Private Attributes

QVector< uint > mNumbers
 List of all version numbers of the whole version. More...
 

Detailed Description

The Version class represents a version number in the format "1.42.7".

Rules for a version number:

  • Minimum count of numbers: 1 (example: "15")
  • Maximum count of numbers: 10 (example: "31.41.5.926.5358.97.9.3.238.462")
  • Minimum count of digits of a number: 1
  • Maximum count of digits of a number: 5

So the lowest possible version is "0", and the highest possible version is "99999.99999.99999.99999.99999.99999.99999.99999.99999.99999".

Leading zeros in numbers are ignored: "002.0005" will be converted to "2.5" Trailing zero numbers are ignored: "2.5.0.0" will be converted to "2.5"

Note
This class guarantees that only Version objects representing a valid version number can be created! If you need a nullable Version, use tl::optional<librepcb::Version> instead.

Constructor & Destructor Documentation

Version ( )
delete

Default constructor (disabled to avoid creating invalid versions)

Version ( const Version other)
inlinenoexcept

Copy constructor.

Parameters
otherAnother Version object
~Version ( )
defaultnoexcept

Destructor

Version ( const QVector< uint > &  numbers)
inlineexplicitprivatenoexcept

Member Function Documentation

bool isPrefixOf ( const Version other) const
noexcept

Check if this version is the prefix of another version.

Example: "1.2" is a prefix of "1.2", "1.2.0.1", "1.2.1"

Parameters
otherAnother version
Returns
True if "other" starts with the same segments as all segments of this version, otherwise false.
const QVector<uint>& getNumbers ( ) const
inlinenoexcept

Get the numbers in the version string.

The first item in the list is the major version number.

Returns
Vector of numbers
QString toStr ( ) const
noexcept

Get the version as a string in the format "1.2.3".

Returns
The version as a string

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString toPrettyStr ( int  minSegCount,
int  maxSegCount = 10 
) const
noexcept

Get the version as a string with trailing zeros (e.g. "1.2.0")

Parameters
minSegCountIf the version has less segments than specified by this parameter, trailing zeros will be appended. Example: "0.1" gets "0.1.0.0" with minSegCount = 4
maxSegCountIf the version has more segments than specified by this parameter, trailing segments will be omitted. Example: "0.1.2.3.4" gets "0.1" with maxSegCount = 2
Returns
The version as a string

+ Here is the caller graph for this function:

QString toComparableStr ( ) const
noexcept

Get the version as a comparable string (59 characters)

The version will be returned with all 10x5 decimal places: "#####.#####.#####.#####.#####.#####.#####.#####.#####.#####"

This method is useful to compare versions in a database (e.g. SQLite) as you only need a simple string compare.

Returns
The version as a comparable string

+ Here is the caller graph for this function:

Version& operator= ( const Version rhs)
inlinenoexcept
bool operator> ( const Version rhs) const
inlinenoexcept

Comparison operators.

Parameters
rhsThe other object to compare
Returns
Result of comparing the UUIDs as comparable strings

+ Here is the call graph for this function:

bool operator< ( const Version rhs) const
inlinenoexcept

Comparison operators.

Parameters
rhsThe other object to compare
Returns
Result of comparing the UUIDs as comparable strings

+ Here is the call graph for this function:

bool operator>= ( const Version rhs) const
inlinenoexcept

Comparison operators.

Parameters
rhsThe other object to compare
Returns
Result of comparing the UUIDs as comparable strings

+ Here is the call graph for this function:

bool operator<= ( const Version rhs) const
inlinenoexcept

Comparison operators.

Parameters
rhsThe other object to compare
Returns
Result of comparing the UUIDs as comparable strings

+ Here is the call graph for this function:

bool operator== ( const Version rhs) const
inlinenoexcept

Comparison operators.

Parameters
rhsThe other object to compare
Returns
Result of comparing the UUIDs as comparable strings
bool operator!= ( const Version rhs) const
inlinenoexcept

Comparison operators.

Parameters
rhsThe other object to compare
Returns
Result of comparing the UUIDs as comparable strings
bool isValid ( const QString &  str)
staticnoexcept

Check if a string is a valid version number.

Parameters
strThe string to check
Return values
trueIf str is a valid version number
falseIf str is not a valid version number
Version fromString ( const QString &  str)
static

Create a Version object from a string.

Parameters
strThe version string in the format "1.2.3" (variable count of numbers)
Returns
A valid Version object
Exceptions
Exceptionif the string does not contain a valid version number

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

tl::optional< Version > tryFromString ( const QString &  str)
staticnoexcept

Try creating a Version object from a string, returning empty optional if invalid.

Parameters
strInput string
Return values
VersionThe created Version object if str was valid
tl::nulloptIf str was not a valid version number

+ Here is the caller graph for this function:

Member Data Documentation

QVector<uint> mNumbers
private

List of all version numbers of the whole version.

Guaranteed to contain at least one item.


The documentation for this class was generated from the following files: