Represents the version number of an assembly, operating system, or the xtd. This class cannot be inherited.
- Namespace
- xtd
- Library
- xtd.core
- Examples
- The following example shows how to use xtd::version to get the version of the Operating System.
#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
namespace version_os_example {
class program {
public:
static auto main() {
auto ver = os.version();
}
};
}
startup_(version_os_example::program::main);
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static xtd::operating_system os_version() noexcept
Gets an xtd::operating_system object that contains the current platform identifier and version number...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:167
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
- Warning
- The value of xtd::version properties that have not been explicitly assigned a value is undefined (-1).
- Retrieving Version Information
- xtd::version objects are most frequently used to store version information about some system or application component (such as the operating system), the current application's executable, or a particular assembly. The following examples illustrate some of the most common scenarios:
- Retrieving the operating system version. The following example uses the xtd::operating_system::version property to retrieve the version number of the operating system.
Represents information about an operating system, such as the version and platform identifier....
Definition operating_system.hpp:25
const xtd::version & version() const noexcept
Gets a xtd::version object that identifies the operating system.
xtd::string version_string() const noexcept
Gets the concatenated string representation of the platform identifier, version, and service pack tha...
version() noexcept=default
Initializes a new instance of the xtd::version class.
xtd::string to_string() const noexcept override
Converts the value of the current xtd::version object to its equivalent xtd::string representation.
- Retrieving the version of xtd. The following example uses the xtd::environment::version property to retrieve version information about xtd.
static xtd::version version() noexcept
Gets a version consisting of the major, minor, build, and revision numbers of the xtd framework.
- Comparing xtd::version objects
- You can use the xtd::version::compare_to method to determine whether one xtd::version object is earlier than, the same as, or later than a second xtd::version object. The following example indicates that xtd::version 2.1 is later than xtd::version 2.0.
switch(v1.compare_to(v2)) {
}
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
For two versions to be equal, the major, minor, build, and revision numbers of the first xtd::version object must be identical to those of the second xtd::version object. If the build or revision number of a xtd::version object is undefined, that xtd::version object is considered to be earlier than a xtd::vVersion object whose build or revision number is equal to zero. The following example illustrates this by comparing three xtd::version objects that have undefined version components.
enum class version_time {earlier = -1, same = 0, later = 1 };
explicit operator auto()
const noexcept {
return xtd::enum_collection<version_time> {{version_time::earlier,
"earlier"}, {version_time::same,
"same"}, {version_time::later,
"later"}};}
};
class example {
public:
static auto main() {
version v1(1, 1);
version v1a("1.1.0");
show_relationship(v1, v1a);
version v1b(1, 1, 0, 0);
show_relationship(v1b, v1a);
}
private:
static void show_relationship(const version& v1, const version& v2) {
console::write_line(
"Relationship of {0} to {1}: {2}", v1, v2, as<version_time>(v1.
compare_to(v2)));
}
};
int32 compare_to(const version &version) const noexcept override
Compares the current xtd::version object to a specified object and returns an indication of their rel...
std::vector< std::pair< enum_t, xtd::string > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition enum_collection.hpp:24
Provides the registration struct for enumerations.
Definition enum_register.hpp:38
- Examples
- application_with_cmake_assembly_info.cpp, application_with_manual_assembly_info.cpp, boxing.cpp, and version.cpp.
|
int32 | build () const noexcept |
| Gets the value of the build component of the version number for the current xtd::version object.
|
|
int32 | major () const noexcept |
| Gets the value of the major component of the version number for the current xtd::version object.
|
|
int16 | major_revision () const noexcept |
| Gets the high 16 bits of the revision number.
|
|
int32 | minor () const noexcept |
| Gets the value of the minor component of the version number for the current xtd::version object.
|
|
int16 | minor_revision () const noexcept |
| Gets the low 16 bits of the revision number.
|
|
int32 | revision () const noexcept |
| Gets the value of the revision component of the version number for the current xtd::version object.
|
|
|
int32 | compare_to (const version &version) const noexcept override |
| Compares the current xtd::version object to a specified object and returns an indication of their relative values.
|
|
bool | equals (const object &obj) const noexcept override |
| Determines whether the specified object is equal to the current object.
|
|
bool | equals (const version &v) const noexcept override |
| Determines whether the specified object is equal to the current object.
|
|
xtd::size | get_hash_code () const noexcept override |
| Serves as a hash function for a particular type.
|
|
xtd::string | to_string () const noexcept override |
| Converts the value of the current xtd::version object to its equivalent xtd::string representation.
|
|
xtd::string | to_string (size_t field_count) const |
| Converts the value of the current xtd::version object to its equivalent xtd::string representation. A specified count indicates the number of components to return.
|
|
|
static version | parse (const xtd::string &input) |
| Converts the string representation of a version number to an equivalent Version object.
|
|
static bool | try_parse (const xtd::string &input, version &result) noexcept |
| Tries to convert the string representation of a version number to an equivalent xtd::version object, and returns a value that indicates whether the conversion succeeded.
|
|
|
| object ()=default |
| Create a new instance of the ultimate base class object.
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance.
|
|
template<class object_t> |
xtd::unique_ptr_object< object_t > | memberwise_clone () const |
| Creates a shallow copy of the current object.
|
|
template<class object_a_t, class object_b_t> |
static bool | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
| Determines whether the specified object instances are considered equal.
|
|
template<class object_a_t, class object_b_t> |
static bool | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
| Determines whether the specified object instances are the same instance.
|
|
◆ version() [1/5]
xtd::version::version |
( |
| ) |
|
|
defaultnoexcept |
◆ version() [2/5]
Initializes a new instance of the xtd::version class using the specified string.
- Parameters
-
version | A string containing the major, minor, build, and revision numbers, where each number is delimited with a period character ('.'). |
- Exceptions
-
◆ version() [3/5]
xtd::version::version |
( |
int32 | major, |
|
|
int32 | minor ) |
Initializes a new instance of the xtd::version class using the specified major and minor values.
- Parameters
-
major | The major version number. |
minor | The minor version number. |
- Exceptions
-
xtd::out_of_range_exception | major or minor is less than zero. |
◆ version() [4/5]
Initializes a new instance of the xtd::version class using the specified major, minor and build values.
- Parameters
-
major | The major version number. |
minor | The minor version number. |
build | The build version number. |
- Exceptions
-
xtd::out_of_range_exception | major, minor or build is less than zero. |
◆ version() [5/5]
Initializes a new instance of the xtd::version class using the specified major, minor, build and revision values.
- Parameters
-
major | The major version number. |
minor | The minor version number. |
build | The build version number. |
revision | The revision version number. |
- Exceptions
-
xtd::out_of_range_exception | major, minor, build or revision is less than zero. |
- Examples
- The following code example demonstrates the xtd::version constructor, and xtd::version::major, xtd::version::minor, xtd::version::build, xtd::version::revision, xtd::version::major_revision, and xtd::version::minor_revision properties.
#include <xtd/console>
#include <xtd/startup>
#include <xtd/version>
namespace version_example {
class program {
public:
static auto main() {
auto fmt_std = "Standard version:\n"
" major.minor.build.revision = {0}.{1}.{2}.{3}";
auto fmt_int = "Interim version:\n"
" major.minor.build.maj_rev/min_rev = {0}.{1}.{2}.{3}/{4}";
auto std =
version {2, 4, 1128, 2};
auto interim =
version {2, 4, 1128, (100 << 16) + 2};
console::write_line(fmt_int, interim.major(), interim.minor(), interim.build(), interim.major_revision(), interim.minor_revision());
}
};
}
startup_(version_example::program::main);
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
◆ build()
int32 xtd::version::build |
( |
| ) |
const |
|
noexcept |
Gets the value of the build component of the version number for the current xtd::version object.
- Returns
- The build number, or -1 if the build number is undefined.
◆ major()
int32 xtd::version::major |
( |
| ) |
const |
|
noexcept |
Gets the value of the major component of the version number for the current xtd::version object.
- Returns
- The major version number.
◆ major_revision()
int16 xtd::version::major_revision |
( |
| ) |
const |
|
noexcept |
Gets the high 16 bits of the revision number.
- Returns
- A 16-bit signed integer.
◆ minor()
int32 xtd::version::minor |
( |
| ) |
const |
|
noexcept |
Gets the value of the minor component of the version number for the current xtd::version object.
- Returns
- The minor version number.
◆ minor_revision()
int16 xtd::version::minor_revision |
( |
| ) |
const |
|
noexcept |
Gets the low 16 bits of the revision number.
- Returns
- A 16-bit signed integer.
◆ revision()
int32 xtd::version::revision |
( |
| ) |
const |
|
noexcept |
Gets the value of the revision component of the version number for the current xtd::version object.
- Returns
- The revision number, or -1 if the revision number is undefined.
◆ compare_to()
int32 xtd::version::compare_to |
( |
const version & | version | ) |
const |
|
overridevirtualnoexcept |
Compares the current xtd::version object to a specified object and returns an indication of their relative values.
- Parameters
-
version | An object to compare. |
- Returns
- A signed integer that indicates the relative values of the two objects, as shown in the following table.
Return value | Meaning |
Less than zero | The current xtd::version object is a version before version. |
Zero | The current xtd::version object is the same version as version. |
Greater than zero | The current xtd::version object is a version subsequent to version. |
Implements xtd::icomparable< version >.
◆ equals() [1/2]
bool xtd::version::equals |
( |
const object & | obj | ) |
const |
|
overridevirtualnoexcept |
Determines whether the specified object is equal to the current object.
- Parameters
-
obj | The object to compare with the current object. |
- Returns
true
if the specified object is equal to the current object. otherwise, false
.
Reimplemented from xtd::object.
◆ equals() [2/2]
bool xtd::version::equals |
( |
const version & | v | ) |
const |
|
overridevirtualnoexcept |
Determines whether the specified object is equal to the current object.
- Parameters
-
v | The object to compare with the current object. |
- Returns
true
if the specified object is equal to the current object. otherwise, false
.
Implements xtd::iequatable< version >.
◆ get_hash_code()
xtd::size xtd::version::get_hash_code |
( |
| ) |
const |
|
overridevirtualnoexcept |
Serves as a hash function for a particular type.
- Returns
- A hash code for the current object.
Reimplemented from xtd::object.
◆ to_string() [1/2]
Converts the value of the current xtd::version object to its equivalent xtd::string representation.
- Returns
- The xtd::string representation of the values of the major, minor, build, and revision components of the current xtd::version object, as depicted in the following format. Each component is separated by a period character ('.'). Square brackets ('[' and ']') indicate a component that will not appear in the return value if the component is not defined:
major.minor[.build[.revision]]
For example, if you create a xtd::version object using the constructor xtd::version(1, 1), the returned string is "1.1". If you create a xtd::version object using the constructor xtd::version(1, 3, 4, 2), the returned string is "1.3.4.2".
Reimplemented from xtd::object.
◆ to_string() [2/2]
xtd::string xtd::version::to_string |
( |
size_t | field_count | ) |
const |
Converts the value of the current xtd::version object to its equivalent xtd::string representation. A specified count indicates the number of components to return.
- Parameters
-
field_count | The number of components to return. The field_count ranges from 0 to 4. |
- Returns
- The xtd::string representation of the values of the major, minor, build, and revision components of the current xtd::version object, each separated by a period character ('.'). The field_count parameter determines how many components are returned.
field_count | Return Value |
0 | An empty string (""). |
1 | major |
2 | major.minor |
3 | major.minor.build |
4 | major.minor.build.revision |
For example, if you create xtd::version object using the constructor xtd::version(1,3,5), xtd::version::to_string(2) returns "1.3" and xtd::version::to_string(4) throws an exception.
- Exceptions
-
◆ parse()
Converts the string representation of a version number to an equivalent Version object.
- Parameters
-
input | A string that contains a version number to convert. |
- Returns
- An object that is equivalent to the version number specified in the input parameter.
- Exceptions
-
- Warning
- Because the string representation of a version number must conform to a recognized pattern, applications should always use exception handling when calling the xtd::version::parse method to parse user input. Alternatively, you can call the xtd::version::try_parse method to parse the string representation of a version number and return a value that indicates whether the parse operation succeeded.
◆ try_parse()
Tries to convert the string representation of a version number to an equivalent xtd::version object, and returns a value that indicates whether the conversion succeeded.
- Parameters
-
input | A string that contains a version number to convert. |
result | When this method returns, contains the xtd::version equivalent of the number that is contained in input, if the conversion succeeded. If input is empty, or if the conversion fails, result is empty when the method returns. |
- Returns
true
if the input parameter was converted successfully; otherwise, false
.
The documentation for this class was generated from the following file: