Utility functions and classes

pni::nexus::Version

class pni::nexus::Version

a 3 number version class

Describes a version number.

Public Types

using NumberType = unsigned long

the number type used to represent version numbers

Public Functions

Version() noexcept

default constructor

Set all three version numbers to 0

Version(NumberType major, NumberType minor, NumberType patch) noexcept

constructor

Parameters
  • major: the major version number

  • minor: the minor version number

  • patch: the patch version number

Version(const Version&) = default

copy constructor

We can use the compiler provided default implementation here as all members are trivially copyable.

NumberType major() const noexcept

return the major version number

NumberType minor() const noexcept

return the minor version number

NumberType patch() const noexcept

return the patch version number

Public Static Functions

Version from_string(const std::string &str)

read version from a string

The string must be formated as MAJOR.MINOR.PATCH. Otherwise a runtime exception will be thrown. Incomplete version numbers are permitted starting from MAJOR downwards. Non-existing elements of the version are assumed to be 0.

Return

a new instance of Version

Exceptions
  • std::runtime_error: in the case of a malformed input string

Parameters
  • str: the string with the version number

std::string to_string(const Version &version)

convert a Version to a string

The result is a string with the format MAJOR.MINOR.PATCH.

Return

a new instance of std::string

Parameters
  • version: reference to a instance of Version

Related

PNINEXUS_EXPORT std::ostream &operator<<(std::ostream &stream, const Version &version)

output stream operator

Writes an instance of Version to a std::ostream. The output format is the same as for Version::to_string.

Return

modified version of std::ostream

See

Version::to_string

Parameters
  • stream: the stream where to write the version

  • version: reference to the Version to write

PNINEXUS_EXPORT std::istream &operator>>(std::istream &stream, Version &version)

input stream operator

Read an instance of Version from a stream. The input format expected is the same as for Version::from_string.

Return

modified input stream

See

Version::from_string

Parameters
  • stream: reference to the stream from which to read the Version

  • version: reference to the version to which to read

PNINEXUS_EXPORT bool operator==(const Version &lhs, const Version &rhs)

checks two version for equality

Two version are considered equal if all of their parts are equal.

Return

true if versions are equal, false otherwise

Parameters
  • lhs: reference to the left hand side version

  • rhs: reference to the right hand side version

PNINEXUS_EXPORT bool operator!=(const Version &lhs, const Version &rhs)

checks if two versions are not equal

Return

true if versions are not equal, false otherwise

Parameters
  • lhs: reference to the left hand side version

  • rhs: reference to the right hand side version

PNINEXUS_EXPORT bool operator<(const Version &lhs, const Version &rhs)

checks if the left version is strictly small than the right

Parameters
  • lhs: reference to the left hand side version

  • rhs: reference to the right hand side version

PNINEXUS_EXPORT bool operator>=(const Version &lhs, const Version &rhs)

checks if the left version is bigger or equal than the right

Parameters
  • lhs: reference to the left hand side version

  • rhs: reference to the right hand side version

PNINEXUS_EXPORT bool operator>(const Version &lhs, const Version &rhs)

checks if the left version is strictly bigger than the right

Parameters
  • lhs: reference to the left hand side version

  • rhs: reference to the right hand side version

pni::nexus::DateTime

class pni::nexus::DateTime

date time factory

nxdate_time provides static methods to create date-time strings which are compliant to the Nexus standard. It is highly important for this class to work properly that the time zone setup is correct. Time-zone information can come either directly from the host machine the program is running on or can be configured manually if this setup is not correct.

Public Static Functions

std::string get_date_time_str()

date-time now

Returns a string with a Nexus compliant date-time string for now.

Return

Nexus date-time string

std::string get_date_time_str(const time_t &t)

date-time at t

Converts a given time in time_t format to a Nexus date-time string.

Return

Nexus date-time string

Parameters
  • t: time as time_t