#include <version.h>
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/xtd>
namespace examples {
class program {
public:
static auto main() {
}
};
}
- 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 common language runtime, 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.
- Retrieving the version of xtd. The following example uses the xtd::environment::version property to retrieve version information about xtd.
- 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)) {
}
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() {
show_relationship(v1, v1a);
show_relationship(v1b, v1a);
}
private:
}
};
- Examples:
- application_with_cmake_assembly_info.cpp, application_with_manual_assembly_info.cpp, boxing.cpp, version.cpp, and version_os.cpp.
|
| object ()=default |
| Create a new instance of the ultimate base class object. More...
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object. More...
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type. More...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Gets the type of the current instance. More...
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal. More...
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance. More...
|
|
◆ 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/xtd>
namespace examples {
class program {
public:
static auto main() {
ustring fmt_std =
"Standard version:\n" " major.minor.build.revision = {0}.{1}.{2}.{3}";
ustring fmt_int =
"Interim version:\n" " major.minor.build.maj_rev/min_rev = {0}.{1}.{2}.{3}/{4}";
version interim(2, 4, 1128, (100 << 16) + 2);
console::write_line(fmt_int, interim.major(), interim.minor(), interim.build(), interim.major_revision(), interim.minor_revision());
}
};
}
◆ 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.
- Examples:
- version.cpp.
◆ 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()
bool xtd::version::equals |
( |
const version & |
| ) |
const |
|
overridevirtualnoexcept |
Indicates whether the current object is equal to another object of the same type.
- Parameters
-
obj | An object to compare with this object. |
- Returns
- true if the current object is equal to the other parameter; otherwise, false.
Implements xtd::iequatable< version >.
◆ 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.
- Examples:
- version.cpp.
◆ major_revision()
int16 xtd::version::major_revision |
( |
| ) |
const |
|
noexcept |
Gets the high 16 bits of the revision number.
- Returns
- A 16-bit signed integer.
- Examples:
- version.cpp.
◆ 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.
- Examples:
- version.cpp.
◆ minor_revision()
int16 xtd::version::minor_revision |
( |
| ) |
const |
|
noexcept |
Gets the low 16 bits of the revision number.
- Returns
- A 16-bit signed integer.
- Examples:
- version.cpp.
◆ 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.
◆ 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.
- Examples:
- version.cpp.
◆ to_string() [1/2]
Converts the value of the current xtd::version object to its equivalent xtd::ustring representation.
- Returns
- The xtd::ustring 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.
- Examples:
- version_os.cpp.
◆ to_string() [2/2]
xtd::ustring xtd::version::to_string |
( |
size_t |
field_count | ) |
const |
Converts the value of the current xtd::version object to its equivalent xtd::ustring 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::ustring 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
-
◆ 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: