57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
//
|
|
// Created by Shell on 2026/7/21.
|
|
//
|
|
|
|
#ifndef SEADISK_VERSION_HPP
|
|
#define SEADISK_VERSION_HPP
|
|
#include <string>
|
|
#include <optional>
|
|
#include <compare>
|
|
|
|
namespace seafile::util {
|
|
/**
|
|
* @brief Semantic version parser.
|
|
*
|
|
* Supports:
|
|
* 10
|
|
* 10.0
|
|
* 10.0.2
|
|
*/
|
|
class Version final {
|
|
public:
|
|
Version() = default;
|
|
|
|
explicit Version(const std::string &version);
|
|
|
|
Version(const Version &) = default;
|
|
|
|
Version(Version &&) noexcept = default;
|
|
|
|
Version &operator=(const Version &) = default;
|
|
|
|
Version &operator=(Version &&) noexcept = default;
|
|
|
|
[[nodiscard]]
|
|
int major() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
std::optional<int> minor() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
std::optional<int> patch() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
std::string toString() const;
|
|
|
|
std::strong_ordering operator<=>(const Version &other) const;
|
|
|
|
private:
|
|
void parse(const std::string &version);
|
|
|
|
int major_{0};
|
|
std::optional<int> minor_;
|
|
std::optional<int> patch_;
|
|
};
|
|
}
|
|
#endif //SEADISK_VERSION_HPP
|