56 lines
1.0 KiB
C++
56 lines
1.0 KiB
C++
//
|
|
// Created by Shell on 2026/7/21.
|
|
//
|
|
|
|
#ifndef SEADISK_VERSION_HPP
|
|
#define SEADISK_VERSION_HPP
|
|
#include <string>
|
|
#include <optional>
|
|
|
|
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);
|
|
|
|
[[nodiscard]]
|
|
int major() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
std::optional<int> minor() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
std::optional<int> patch() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
std::string toString() const;
|
|
|
|
bool operator==(const Version& other) const;
|
|
|
|
bool operator<(const Version& other) const;
|
|
|
|
|
|
private:
|
|
void parse(const std::string& version);
|
|
|
|
private:
|
|
int major_{0};
|
|
std::optional<int> minor_;
|
|
std::optional<int> patch_;
|
|
};
|
|
|
|
}
|
|
#endif //SEADISK_VERSION_HPP
|