LibrePCB Developers Documentation
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
 
bool operator>= (const Version &rhs) const noexcept
 
bool operator<= (const Version &rhs) const noexcept
 
bool operator== (const Version &rhs) const noexcept
 
bool operator!= (const Version &rhs) const noexcept
 

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() [1/3]

Version ( )
delete

Default constructor (disabled to avoid creating invalid versions)

◆ Version() [2/3]

Version ( const Version other)
inlinenoexcept

Copy constructor.

Parameters
otherAnother librepcb::Version object

◆ ~Version()

~Version ( )
defaultnoexcept

Destructor

◆ Version() [3/3]

Version ( const QVector< uint > &  numbers)
inlineexplicitprivatenoexcept

Member Function Documentation

◆ isPrefixOf()

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.

◆ getNumbers()

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

◆ toStr()

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:

◆ toPrettyStr()

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:

◆ toComparableStr()

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:

◆ operator=()

Version & operator= ( const Version rhs)
inlinenoexcept

◆ operator>()

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:

◆ operator<()

bool operator< ( const Version rhs) const
inlinenoexcept
+ Here is the call graph for this function:

◆ operator>=()

bool operator>= ( const Version rhs) const
inlinenoexcept
+ Here is the call graph for this function:

◆ operator<=()

bool operator<= ( const Version rhs) const
inlinenoexcept
+ Here is the call graph for this function:

◆ operator==()

bool operator== ( const Version rhs) const
inlinenoexcept

◆ operator!=()

bool operator!= ( const Version rhs) const
inlinenoexcept

◆ isValid()

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

◆ fromString()

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:

◆ tryFromString()

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 call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mNumbers

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: