diff options
-rw-r--r-- | libbutl/standard-version.cxx | 2 | ||||
-rw-r--r-- | libbutl/standard-version.ixx | 42 | ||||
-rw-r--r-- | libbutl/standard-version.mxx | 48 |
3 files changed, 84 insertions, 8 deletions
diff --git a/libbutl/standard-version.cxx b/libbutl/standard-version.cxx index fc2d528..8e6354c 100644 --- a/libbutl/standard-version.cxx +++ b/libbutl/standard-version.cxx @@ -138,7 +138,7 @@ namespace butl } if (!r) - throw invalid_argument ("invalid project version"); + throw invalid_argument ("invalid standard version"); } static bool diff --git a/libbutl/standard-version.ixx b/libbutl/standard-version.ixx index f24e358..c488284 100644 --- a/libbutl/standard-version.ixx +++ b/libbutl/standard-version.ixx @@ -44,7 +44,7 @@ namespace butl pre_release () const noexcept { std::uint64_t ab (version / 10 % 1000); - if (ab > 500) + if (ab >= 500) ab -= 500; return static_cast<std::uint16_t> (ab); @@ -70,6 +70,46 @@ namespace butl return version % 10000 == 1 && !snapshot () && !stub (); } + inline standard_version:: + standard_version (std::uint16_t ep, + std::uint16_t mj, + std::uint16_t mi, + std::uint16_t pa, + std::uint16_t pr, + std::uint16_t rv) + : standard_version (ep, + // AAABBBCCCDDDE + (mj * 10000000000ULL + + mi * 10000000ULL + + pa * 10000ULL + + pr * 10ULL), + "" /* snapshot */, + rv) + { + } + + inline standard_version:: + standard_version (std::uint16_t ep, + std::uint16_t mj, + std::uint16_t mi, + std::uint16_t pa, + std::uint16_t pr, + std::uint64_t sn, + std::string si, + std::uint16_t rv) + : standard_version (ep, + // AAABBBCCCDDDE + (mj * 10000000000ULL + + mi * 10000000ULL + + pa * 10000ULL + + pr * 10ULL + + /**/ 1ULL /* snapshot */), + sn, + si, + rv) + { + } + inline standard_version::flags operator& (standard_version::flags x, standard_version::flags y) { diff --git a/libbutl/standard-version.mxx b/libbutl/standard-version.mxx index 7b1f232..0415318 100644 --- a/libbutl/standard-version.mxx +++ b/libbutl/standard-version.mxx @@ -46,7 +46,7 @@ LIBBUTL_MODEXPORT namespace butl // // [+<epoch>-]<maj>.<min>.<patch>[-(a|b).<num>[.<snapsn>[.<snapid>]]][+<rev>] // [+<epoch>-]<maj>.<min>.<patch>- - // 0[+<revision>] + // 0[+<rev>] // // The numeric version format is AAABBBCCCDDDE where: // @@ -67,6 +67,8 @@ LIBBUTL_MODEXPORT namespace butl // 3.0.0-b.2 0029999995020 // 2.2.0-a.1.z 0020019990011 // + // Stub is represented as ~0. + // struct LIBBUTL_SYMEXPORT standard_version { // Invariants: @@ -82,7 +84,7 @@ LIBBUTL_MODEXPORT namespace butl static const std::uint64_t latest_sn = std::uint64_t (~0); std::uint16_t epoch = 1; // 0 if a stub, 1 if not specified. - std::uint64_t version = 0; // AAABBBCCCDDDE + std::uint64_t version = 0; // AAABBBCCCDDDE or ~0 for stub. std::uint64_t snapshot_sn = 0; // 0 if not specifed, latest_sn if 'z'. std::string snapshot_id; // Empty if not specified. std::uint16_t revision = 0; // 0 if not specified. @@ -91,7 +93,15 @@ LIBBUTL_MODEXPORT namespace butl std::uint16_t minor () const noexcept; std::uint16_t patch () const noexcept; - // Note: 0 is ambiguous (-a.0.z). + // The alpha/beta number (decremented by 500 for betas). Note: 0 is + // ambiguous (can be non-pre-release or -[ab].0.z). + // + // @@ Inconsistent with the pre_release argument in constructors + // below. The whole pre-release interface feels off, maybe we should + // redo it? I.e., return DDD from pre_release() (though 0 will still be + // ambigous; maybe DDDE) and have separate functions to get alpha/beta + // numbers? Maybe alpha()/beta() return optional<std::uint16_t>? Maybe + // pre-release should return bool (or also optional)? // std::uint16_t pre_release () const noexcept; @@ -123,7 +133,8 @@ LIBBUTL_MODEXPORT namespace butl // Comparison of empty or stub versions doesn't make sense. // int - compare (const standard_version& v) const noexcept + compare (const standard_version& v, + bool ignore_revision = false) const noexcept { if (epoch != v.epoch) return epoch < v.epoch ? -1 : 1; @@ -134,8 +145,11 @@ LIBBUTL_MODEXPORT namespace butl if (snapshot_sn != v.snapshot_sn) return snapshot_sn < v.snapshot_sn ? -1 : 1; - if (revision != v.revision) - return revision < v.revision ? -1 : 1; + if (!ignore_revision) + { + if (revision != v.revision) + return revision < v.revision ? -1 : 1; + } return 0; } @@ -160,6 +174,8 @@ LIBBUTL_MODEXPORT namespace butl const std::string& snapshot, flags = none); + // Note that the default epoch is 1 for real versions and 0 for stubs. + // standard_version (std::uint16_t epoch, std::uint64_t version, const std::string& snapshot, @@ -173,6 +189,26 @@ LIBBUTL_MODEXPORT namespace butl std::uint16_t revision, flags = none); + // Version as separate major, minor, patch, and pre-release components. + // Note that the pre-release here is in the DDD form, that is, incremenetd + // by 500 for betas. + // + standard_version (std::uint16_t epoch, + std::uint16_t major, + std::uint16_t minor, + std::uint16_t patch, + std::uint16_t pre_release = 0, + std::uint16_t revision = 0); + + standard_version (std::uint16_t epoch, + std::uint16_t major, + std::uint16_t minor, + std::uint16_t patch, + std::uint16_t pre_release, + std::uint64_t snapshot_sn, + std::string snapshot_id, + std::uint16_t revision = 0); + // Create empty version. // standard_version () {} // = default; @@ MOD VC |