| |
| |
| |
| |
| |
|
|
| #ifndef MAMBA_SPECS_VERSION_HPP |
| #define MAMBA_SPECS_VERSION_HPP |
|
|
| #include <optional> |
| #include <string> |
| #include <string_view> |
| #include <vector> |
|
|
| #include <fmt/format.h> |
|
|
| #include "mamba/specs/error.hpp" |
| #include "mamba/util/charconv.hpp" |
|
|
| namespace mamba::specs |
| { |
|
|
| |
| |
| |
| |
| |
| |
| |
| class VersionPartAtom |
| { |
| public: |
|
|
| VersionPartAtom() noexcept = default; |
| VersionPartAtom(std::size_t numeral) noexcept; |
| VersionPartAtom(std::size_t numeral, std::string_view literal); |
| |
| template <typename Char> |
| VersionPartAtom(std::size_t numeral, std::basic_string<Char> literal); |
|
|
| [[nodiscard]] auto numeral() const noexcept -> std::size_t; |
| [[nodiscard]] auto literal() const& noexcept -> const std::string&; |
| auto literal() && noexcept -> std::string; |
|
|
| [[nodiscard]] auto to_string() const -> std::string; |
|
|
| private: |
|
|
| |
| std::string m_literal = ""; |
| std::size_t m_numeral = 0; |
| }; |
|
|
| auto operator==(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; |
| auto operator!=(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; |
| auto operator<(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; |
| auto operator<=(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; |
| auto operator>(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; |
| auto operator>=(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; |
|
|
| extern template VersionPartAtom::VersionPartAtom(std::size_t, std::string); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| struct VersionPart |
| { |
| |
| std::vector<VersionPartAtom> atoms = {}; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| bool implicit_leading_zero = false; |
|
|
| VersionPart(); |
| VersionPart(std::initializer_list<VersionPartAtom> init); |
| VersionPart(std::vector<VersionPartAtom> atoms, bool implicit_leading_zero); |
|
|
| [[nodiscard]] auto to_string() const -> std::string; |
| }; |
|
|
| auto operator==(const VersionPart& left, const VersionPart& other) -> bool; |
| auto operator!=(const VersionPart& left, const VersionPart& other) -> bool; |
| auto operator<(const VersionPart& left, const VersionPart& other) -> bool; |
| auto operator<=(const VersionPart& left, const VersionPart& other) -> bool; |
| auto operator>(const VersionPart& left, const VersionPart& other) -> bool; |
| auto operator>=(const VersionPart& left, const VersionPart& other) -> bool; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| using CommonVersion = std::vector<VersionPart>; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class Version |
| { |
| public: |
|
|
| static constexpr char epoch_delim = '!'; |
| static constexpr char local_delim = '+'; |
| static constexpr char part_delim = '.'; |
| static constexpr char part_delim_alt = '-'; |
| static constexpr char part_delim_special = '_'; |
|
|
| static auto parse(std::string_view str) -> expected_parse_t<Version>; |
|
|
| |
| Version() noexcept = default; |
| Version(std::size_t epoch, CommonVersion version, CommonVersion local = {}) noexcept; |
|
|
| [[nodiscard]] auto epoch() const noexcept -> std::size_t; |
| [[nodiscard]] auto version() const noexcept -> const CommonVersion&; |
| [[nodiscard]] auto local() const noexcept -> const CommonVersion&; |
|
|
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto to_string() const -> std::string; |
|
|
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto to_string(std::size_t level) const -> std::string; |
|
|
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto to_string_glob() const -> std::string; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto starts_with(const Version& prefix) const -> bool; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto compatible_with(const Version& older, std::size_t level) const -> bool; |
|
|
| private: |
|
|
| |
| CommonVersion m_version = {}; |
| CommonVersion m_local = {}; |
| std::size_t m_epoch = 0; |
| }; |
|
|
| auto operator==(const Version& left, const Version& other) -> bool; |
| auto operator!=(const Version& left, const Version& other) -> bool; |
| auto operator<(const Version& left, const Version& other) -> bool; |
| auto operator<=(const Version& left, const Version& other) -> bool; |
| auto operator>(const Version& left, const Version& other) -> bool; |
| auto operator>=(const Version& left, const Version& other) -> bool; |
|
|
| namespace version_literals |
| { |
| auto operator""_v(const char* str, std::size_t len) -> Version; |
| } |
| } |
|
|
| template <> |
| struct fmt::formatter<mamba::specs::VersionPartAtom> |
| { |
| constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator |
| { |
| |
| if (ctx.begin() != ctx.end() && *ctx.begin() != '}') |
| { |
| throw fmt::format_error("Invalid format"); |
| } |
| return ctx.begin(); |
| } |
|
|
| auto format(const ::mamba::specs::VersionPartAtom atom, format_context& ctx) const |
| -> format_context::iterator; |
| }; |
|
|
| template <> |
| struct fmt::formatter<mamba::specs::VersionPart> |
| { |
| constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator |
| { |
| |
| if (ctx.begin() != ctx.end() && *ctx.begin() != '}') |
| { |
| throw fmt::format_error("Invalid format"); |
| } |
| return ctx.begin(); |
| } |
|
|
| auto format(const ::mamba::specs::VersionPart atom, format_context& ctx) const |
| -> format_context::iterator; |
| }; |
|
|
| template <> |
| struct fmt::formatter<mamba::specs::Version> |
| { |
| enum struct FormatType |
| { |
| Normal, |
| |
| |
| |
| |
| |
| Glob, |
| }; |
|
|
| std::optional<std::size_t> m_level; |
| FormatType m_type = FormatType::Normal; |
|
|
| constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator |
| { |
| const auto end = ctx.end(); |
| const auto start = ctx.begin(); |
|
|
| |
| if (start == end || *start == '}') |
| { |
| return start; |
| } |
|
|
| |
| std::size_t val = 0; |
| auto [ptr, ec] = mamba::util::constexpr_from_chars(start, end, val); |
| if (ec == std::errc()) |
| { |
| m_level = val; |
| } |
|
|
| |
| if (ptr == end || *ptr == '}') |
| { |
| return ptr; |
| } |
|
|
| |
| if (*ptr == 'g') |
| { |
| m_type = FormatType::Glob; |
| ++ptr; |
| } |
|
|
| return ptr; |
| } |
|
|
| auto format(const ::mamba::specs::Version v, format_context& ctx) const |
| -> format_context::iterator; |
| }; |
|
|
| #endif |
|
|