ImFusion SDK 4.3
Version Struct Reference

#include <ImFusion/Core/Utils/Version.h>

Utility class to work with version information following the SemVer format. More...

Detailed Description

Utility class to work with version information following the SemVer format.

A valid version always contains of numeric major, minor, and patch components, as well as an optional suffix (called "pre-release version" in SemVer) and optional metadata component. In addition to storing the above-mentioned information this class offers member functions for semantic comparison, and conversion from/to strings. When represented as textual string they are written as <major>.<minor>.<patch>[-<suffix>][+<metadata>].

Note
This class is modeled after the SemVer definition and implements the majority of its aspects. However, it does not promise to implement all of them. For instance:
  • the version 0.0.0 is considered valid
  • the logic for ordering suffixes is slightly simplified (no support for multiple fields delimited by .)
  • it does not constrain the allowed characters in the suffix and metadata components

Public Member Functions

 Version (int major=0, int minor=0, int patch=0, std::string suffix="", std::string metadata="")
 Creates a new Version instance.
 
bool isValid () const noexcept
 Return whether all version parts are >= 0.
 
bool isValidAndNotZero () const noexcept
 Return whether all version parts are >= 0 and at least one of them is > 0.
 
std::string toString () const
 Format version as string <major>.
 

Static Public Member Functions

static Version fromString (const std::string &versionString)
 Parses version information from a string.
 

Public Attributes

int major = 0
 Major version component.
 
int minor = 0
 Minor version component.
 
int patch = 0
 Patch version component.
 
std::string suffix
 Optional suffix string indicating a pre-release.
 
std::string metadata
 Optional build metadata string to store additional information about the version.
 

Constructor & Destructor Documentation

◆ Version()

Version ( int major = 0,
int minor = 0,
int patch = 0,
std::string suffix = "",
std::string metadata = "" )
inline

Creates a new Version instance.

Parameters
majorMajor version component
minorMinor version component
patchPatch version component
suffixOptional suffix string indicating a pre-release
metadataOptional metadata string to store additional information about the version

Member Function Documentation

◆ fromString()

static Version fromString ( const std::string & versionString)
static

Parses version information from a string.

The string is expected to have the format <major>[.<minor>][.<patch>][-<suffix>][+<metadata>]. Absent components will have their default value (0 or empty string, respectively). Leading and trailing whitespace, as well as any other content after the parsed version string will be ignored.

If parsing fails the returned Version will be invalid (i.e. components < 0).

See also
toString()

◆ isValid()

bool isValid ( ) const
noexcept

Return whether all version parts are >= 0.

See also
isValidAndNotZero()

◆ toString()

std::string toString ( ) const

Format version as string <major>.

<minor>.<patch>[-<suffix>][+<metadata>] or invalid if it is not valid.

See also
fromString()

The documentation for this struct was generated from the following file:
Search Tab / S to search, Esc to close