Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da2e93c405
commit
28b94883fd
156 files changed
+278
-220
No files matched your search
@@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace Void::Semver
|
||||
{
|
||||
|
||||
// ── Version ───────────────────────────────────────────────────────────────────
|
||||
|
||||
struct Version
|
||||
{
|
||||
unsigned major{0};
|
||||
unsigned minor{0};
|
||||
unsigned patch{0};
|
||||
std::string pre_release; // e.g. "alpha.1"
|
||||
std::string build; // e.g. "20240101"
|
||||
|
||||
[[nodiscard]] std::string to_string() const
|
||||
{
|
||||
std::string s = std::format("{}.{}.{}", major, minor, patch);
|
||||
if (!pre_release.empty()) { s += '-'; s += pre_release; }
|
||||
if (!build.empty()) { s += '+'; s += build; }
|
||||
return s;
|
||||
}
|
||||
|
||||
// Precedence comparison per semver spec (build metadata ignored).
|
||||
[[nodiscard]] std::strong_ordering
|
||||
operator<=>(const Version& o) const noexcept
|
||||
{
|
||||
if (auto c = major <=> o.major; c != 0) return c;
|
||||
if (auto c = minor <=> o.minor; c != 0) return c;
|
||||
if (auto c = patch <=> o.patch; c != 0) return c;
|
||||
// No pre-release > has pre-release
|
||||
const bool l_pre = !pre_release.empty();
|
||||
const bool r_pre = !o.pre_release.empty();
|
||||
if (!l_pre && r_pre) return std::strong_ordering::greater;
|
||||
if (l_pre && !r_pre) return std::strong_ordering::less;
|
||||
// Both have pre-release — lexicographic (simplified)
|
||||
if (auto c = pre_release <=> o.pre_release; c != 0) {
|
||||
return c < 0 ? std::strong_ordering::less
|
||||
: std::strong_ordering::greater;
|
||||
}
|
||||
return std::strong_ordering::equal;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool operator==(const Version& o) const noexcept
|
||||
{
|
||||
return major == o.major && minor == o.minor && patch == o.patch &&
|
||||
pre_release == o.pre_release;
|
||||
}
|
||||
|
||||
// Is this version compatible with `required`? (same major, >= minor.patch)
|
||||
[[nodiscard]] bool compatible_with(const Version& required) const noexcept
|
||||
{
|
||||
if (major != required.major) return false;
|
||||
return (*this <=> required) >= 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_stable() const noexcept
|
||||
{
|
||||
return major >= 1 && pre_release.empty();
|
||||
}
|
||||
|
||||
[[nodiscard]] Version bumped_major() const noexcept
|
||||
{
|
||||
return {major + 1, 0, 0};
|
||||
}
|
||||
|
||||
[[nodiscard]] Version bumped_minor() const noexcept
|
||||
{
|
||||
return {major, minor + 1, 0};
|
||||
}
|
||||
|
||||
[[nodiscard]] Version bumped_patch() const noexcept
|
||||
{
|
||||
return {major, minor, patch + 1};
|
||||
}
|
||||
};
|
||||
|
||||
// ── Parsing ───────────────────────────────────────────────────────────────────
|
||||
|
||||
[[nodiscard]] inline std::optional<Version> parse(std::string_view s)
|
||||
{
|
||||
Version v;
|
||||
|
||||
auto parse_uint = [](std::string_view sv, unsigned& out) -> bool {
|
||||
if (sv.empty()) return false;
|
||||
out = 0;
|
||||
for (char c : sv) {
|
||||
if (c < '0' || c > '9') return false;
|
||||
out = out * 10 + static_cast<unsigned>(c - '0');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// Optional leading 'v'
|
||||
if (!s.empty() && (s[0] == 'v' || s[0] == 'V')) s.remove_prefix(1);
|
||||
|
||||
// Split build metadata first
|
||||
const auto plus = s.find('+');
|
||||
if (plus != std::string_view::npos) {
|
||||
v.build = std::string{s.substr(plus + 1)};
|
||||
s = s.substr(0, plus);
|
||||
}
|
||||
|
||||
// Split pre-release
|
||||
const auto dash = s.find('-');
|
||||
if (dash != std::string_view::npos) {
|
||||
v.pre_release = std::string{s.substr(dash + 1)};
|
||||
s = s.substr(0, dash);
|
||||
}
|
||||
|
||||
// Major.minor.patch
|
||||
const auto d1 = s.find('.');
|
||||
if (d1 == std::string_view::npos) return std::nullopt;
|
||||
if (!parse_uint(s.substr(0, d1), v.major)) return std::nullopt;
|
||||
s = s.substr(d1 + 1);
|
||||
|
||||
const auto d2 = s.find('.');
|
||||
if (d2 == std::string_view::npos) return std::nullopt;
|
||||
if (!parse_uint(s.substr(0, d2), v.minor)) return std::nullopt;
|
||||
if (!parse_uint(s.substr(d2 + 1), v.patch)) return std::nullopt;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
} // namespace Void::Semver
|
||||
Reference in new issue
Block a user