From f3f09dac499f7e122864eef2555ae8b66ef71975 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 23 May 2019 13:42:44 +0300 Subject: Increase standard and semantic versions major, minor, and patch max values up to 99999 --- libbutl/semantic-version.cxx | 26 +++++++-------- libbutl/semantic-version.mxx | 10 +++--- libbutl/standard-version.cxx | 77 +++++++++++++++++++++++++++----------------- libbutl/standard-version.ixx | 57 ++++++++++++++++---------------- libbutl/standard-version.mxx | 48 +++++++++++++-------------- 5 files changed, 118 insertions(+), 100 deletions(-) (limited to 'libbutl') diff --git a/libbutl/semantic-version.cxx b/libbutl/semantic-version.cxx index ef2a583..375e9e3 100644 --- a/libbutl/semantic-version.cxx +++ b/libbutl/semantic-version.cxx @@ -56,32 +56,28 @@ namespace butl uint64_t semantic_version:: numeric () const { - if (const char* w = (major > 999 ? "major version greater than 999" : - minor > 999 ? "minor version greater than 999" : - patch > 999 ? "patch version greater than 999" : + if (const char* w = (major > 99999 ? "major version greater than 99999" : + minor > 99999 ? "minor version greater than 99999" : + patch > 99999 ? "patch version greater than 99999" : nullptr)) throw invalid_argument (w); - // AAABBBCCC0000 - // 10000000000 - // 10000000 - // 10000 - // - return (major * 10000000000) + (minor * 10000000) + (patch * 10000); + // AAAAABBBBBCCCCC0000 BBBBBCCCCC0000 CCCCC0000 + return (major * 100000000000000) + (minor * 1000000000) + (patch * 10000); } semantic_version:: semantic_version (uint64_t n, std::string b) : build (move (b)) { - // AAABBBCCC0000 - if (n > 9999999990000ULL || (n % 1000) != 0) + // AAAAABBBBBCCCCC0000 + if (n > 9999999999999990000ULL || (n % 10000) != 0) throw invalid_argument ("invalid numeric representation"); - // AAABBBCCC0000 - major = n / 10000000000 % 1000; - minor = n / 10000000 % 1000; - patch = n / 10000 % 1000; + // AAAAABBBBBCCCCC0000 + major = n / 100000000000000 % 100000; + minor = n / 1000000000 % 100000; + patch = n / 10000 % 100000; } semantic_version:: diff --git a/libbutl/semantic-version.mxx b/libbutl/semantic-version.mxx index 35bf1b8..f143588 100644 --- a/libbutl/semantic-version.mxx +++ b/libbutl/semantic-version.mxx @@ -101,18 +101,18 @@ LIBBUTL_MODEXPORT namespace butl std::string string (bool ignore_build = false) const; - // Numeric representation in the AAABBBCCC0000 form, where: + // Numeric representation in the AAAAABBBBBCCCCC0000 form, where: // - // AAA - major version number - // BBB - minor version number - // CCC - patch version number + // AAAAA - major version number + // BBBBB - minor version number + // CCCCC - patch version number // // See standard version for details. // explicit semantic_version (std::uint64_t numeric, std::string build = ""); - // If any of the major/minor/patch components is greater than 999, then + // If any of the major/minor/patch components is greater than 99999, then // throw std::invalid_argument. The build component is ignored. // std::uint64_t diff --git a/libbutl/standard-version.cxx b/libbutl/standard-version.cxx index bb76ad6..f4517ef 100644 --- a/libbutl/standard-version.cxx +++ b/libbutl/standard-version.cxx @@ -69,19 +69,34 @@ namespace butl return true; } + template static bool - parse_uint16 (const string& s, size_t& p, - uint16_t& r, - uint16_t min = 0, uint16_t max = 999) + parse_uint (const string& s, size_t& p, T& r, T min, T max) { uint64_t v; if (!parse_uint64 (s, p, v, min, max)) return false; - r = static_cast (v); + r = static_cast (v); return true; } + static inline bool + parse_uint16 (const string& s, size_t& p, + uint16_t& r, + uint16_t min = 0, uint16_t max = 999) + { + return parse_uint (s, p, r, min, max); + } + + static inline bool + parse_uint32 (const string& s, size_t& p, + uint32_t& r, + uint32_t min = 0, uint32_t max = 99999) + { + return parse_uint (s, p, r, min, max); + } + static void check_version (uint64_t vr, bool sn, standard_version::flags fl) { @@ -98,8 +113,8 @@ namespace butl { // Check that the version isn't too large, unless represents stub. // - // AAABBBCCCDDDE - r = vr < 10000000000000ULL; + // AAAAABBBBBCCCCCDDDE + r = vr < 10000000000000000000ULL; // Check that E version component is consistent with the snapshot flag. // Note that if the allow_earliest flag is set, then E can be 1 for the @@ -217,17 +232,20 @@ namespace butl return bail ("'-' expected after epoch"); } - uint16_t ma, mi, bf, ab (0); + uint32_t ma, mi, bf; + uint16_t ab (0); bool earliest (false); - if (!parse_uint16 (s, p, ma)) + if (!parse_uint32 (s, p, ma)) return bail ("invalid major version"); // The only valid version that has no epoch, contains only the major // version being equal to zero, that is optionally followed by the plus // character, is the stub version, unless forbidden. // - bool stub ((f & standard_version::allow_stub) != 0 && !ep && ma == 0 && + bool stub ((f & standard_version::allow_stub) != 0 && + !ep && + ma == 0 && (p == n || s[p] == '+')); if (stub) @@ -240,19 +258,19 @@ namespace butl if (s[p] != '.') return bail ("'.' expected after major version"); - if (!parse_uint16 (s, ++p, mi)) + if (!parse_uint32 (s, ++p, mi)) return bail ("invalid minor version"); if (s[p] != '.') return bail ("'.' expected after minor version"); - if (!parse_uint16 (s, ++p, bf)) + if (!parse_uint32 (s, ++p, bf)) return bail ("invalid patch version"); - // AAABBBCCCDDDE - r.version = ma * 10000000000ULL + - mi * 10000000ULL + - bf * 10000ULL; + // AAAAABBBBBCCCCCDDDE + r.version = ma * 100000000000000ULL + + mi * 1000000000ULL + + bf * 10000ULL; if (r.version == 0) return bail ("0.0.0 version"); @@ -403,9 +421,10 @@ namespace butl throw invalid_argument ("snapshot for stub"); } - if (!snapshot_id.empty () && (snapshot_id.size () > 16 || - snapshot_sn == 0 || - snapshot_sn == latest_sn)) + if (!snapshot_id.empty () && + (snapshot_id.size () > 16 || + snapshot_sn == 0 || + snapshot_sn == latest_sn)) throw invalid_argument ("invalid snapshot"); } @@ -494,9 +513,9 @@ namespace butl if (snapshot ()) // Trailing dot already in id. { - r += (snapshot_sn == latest_sn ? "z" : + r += (snapshot_sn == latest_sn ? "z" : snapshot_id.empty () ? to_string (snapshot_sn) : - snapshot_id); + snapshot_id); } return r; @@ -552,10 +571,10 @@ namespace butl if (c == '~' || (c == '^' && version.major () == 0)) { - // If for ~X.Y.Z Y is 999, then we cannot produce a valid X.Y+1.0- + // If for ~X.Y.Z Y is 99999, then we cannot produce a valid X.Y+1.0- // version (due to an overflow). // - if (version.minor () == 999) + if (version.minor () == 99999) { if (ignore_overflow) return standard_version (); @@ -563,16 +582,16 @@ namespace butl throw invalid_argument ("invalid minor version"); } - // AAABBBCCCDDDE - v = version.major () * 10000000000ULL + - (version.minor () + 1) * 10000000ULL; + // AAAAABBBBBCCCCCDDDE + v = version.major () * 100000000000000ULL + + (version.minor () + 1) * 1000000000ULL; } else { - // If for ^X.Y.Z X is 999, then we cannot produce a valid X+1.0.0- + // If for ^X.Y.Z X is 99999, then we cannot produce a valid X+1.0.0- // version (due to an overflow). // - if (version.major () == 999) + if (version.major () == 99999) { if (ignore_overflow) return standard_version (); @@ -580,8 +599,8 @@ namespace butl throw invalid_argument ("invalid major version"); } - // AAABBBCCCDDDE - v = (version.major () + 1) * 10000000000ULL; + // AAAAABBBBBCCCCCDDDE + v = (version.major () + 1) * 100000000000000ULL; } return standard_version (version.epoch, diff --git a/libbutl/standard-version.ixx b/libbutl/standard-version.ixx index 6142586..52cf9cb 100644 --- a/libbutl/standard-version.ixx +++ b/libbutl/standard-version.ixx @@ -4,7 +4,7 @@ namespace butl { - inline std::uint16_t standard_version:: + inline std::uint32_t standard_version:: major () const noexcept { std::uint64_t e (version % 10); @@ -13,10 +13,11 @@ namespace butl if (ab != 0 || e == 1) v += 1000 - ab; - return static_cast (v / 1000000000 % 1000); + // AAAAABBBBBCCCCCDDD + return static_cast (v / 10000000000000 % 100000); } - inline std::uint16_t standard_version:: + inline std::uint32_t standard_version:: minor () const noexcept { std::uint64_t e (version % 10); @@ -25,10 +26,11 @@ namespace butl if (ab != 0 || e == 1) v += 1000 - ab; - return static_cast (v / 1000000 % 1000); + // AAAAABBBBBCCCCCDDD + return static_cast (v / 100000000 % 100000); } - inline std::uint16_t standard_version:: + inline std::uint32_t standard_version:: patch () const noexcept { std::uint64_t e (version % 10); @@ -37,7 +39,8 @@ namespace butl if (ab != 0 || e == 1) v += 1000 - ab; - return static_cast (v / 1000 % 1000); + // AAAAABBBBBCCCCCDDD + return static_cast (v / 1000 % 100000); } inline bool standard_version:: @@ -87,23 +90,23 @@ namespace butl return snapshot () && snapshot_sn == latest_sn; } - // Note: in the following constructors we subtract one from AAABBBCCC if - // DDDE is not zero (see standard-version.hxx for details). + // Note: in the following constructors we subtract one from AAAAABBBBBCCCCC + // if DDDE is not zero (see standard-version.hxx for details). // inline standard_version:: standard_version (std::uint16_t ep, - std::uint16_t mj, - std::uint16_t mi, - std::uint16_t pa, + std::uint32_t mj, + std::uint32_t mi, + std::uint32_t pa, std::uint16_t pr, std::uint16_t rv) : standard_version (ep, - // AAABBBCCCDDDE - (mj * 10000000000ULL + - mi * 10000000ULL + - pa * 10000ULL + - pr * 10ULL - - (pr != 0 ? 10000ULL : 0ULL)), + // AAAAABBBBBCCCCCDDDE + (mj * 100000000000000ULL + + mi * 1000000000ULL + + pa * 10000ULL + + pr * 10ULL - + (pr != 0 ? 10000ULL : 0ULL)), "" /* snapshot */, rv) { @@ -111,21 +114,21 @@ namespace butl inline standard_version:: standard_version (std::uint16_t ep, - std::uint16_t mj, - std::uint16_t mi, - std::uint16_t pa, + std::uint32_t mj, + std::uint32_t mi, + std::uint32_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 */ - - 10000ULL), + // AAAAABBBBBCCCCCDDDE + (mj * 100000000000000ULL + + mi * 1000000000ULL + + pa * 10000ULL + + pr * 10ULL + + 1ULL /* snapshot */ - + 10000ULL), sn, si, rv) diff --git a/libbutl/standard-version.mxx b/libbutl/standard-version.mxx index c899e57..3c38242 100644 --- a/libbutl/standard-version.mxx +++ b/libbutl/standard-version.mxx @@ -52,24 +52,24 @@ LIBBUTL_MODEXPORT namespace butl // snapshot (release is naturally always final). Pre-release can be alpha or // beta. // - // The numeric version format is AAABBBCCCDDDE where: + // The numeric version format is AAAAABBBBBCCCCCDDDE where: // - // AAA - major version number - // BBB - minor version number - // CCC - patch version number - // DDD - alpha / beta (DDD + 500) version number - // E - final (0) / snapshot (1) + // AAAAA - major version number + // BBBBB - minor version number + // CCCCC - patch version number + // DDD - alpha / beta (DDD + 500) version number + // E - final (0) / snapshot (1) // - // When DDDE is not 0, 1 is subtracted from AAABBBCCC. For example: + // When DDDE is not 0, 1 is subtracted from AAAAABBBBBCCCCC. For example: // - // Version AAABBBCCCDDDE + // Version AAAAABBBBBCCCCCDDDE // - // 0.1.0 0000010000000 - // 0.1.2 0000010010000 - // 1.2.3 0010020030000 - // 2.2.0-a.1 0020019990010 - // 3.0.0-b.2 0029999995020 - // 2.2.0-a.1.z 0020019990011 + // 0.1.0 0000000001000000000 + // 0.1.2 0000000001000020000 + // 1.2.3 0000100002000030000 + // 2.2.0-a.1 0000200001999990010 + // 3.0.0-b.2 0000299999999995020 + // 2.2.0-a.1.z 0000200001999990011 // // Stub is represented as ~0 (but is not considered a pre-release). // @@ -88,14 +88,14 @@ 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 or ~0 for stub. + std::uint64_t version = 0; // AAAAABBBBBCCCCCDDDE 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. - std::uint16_t major () const noexcept; - std::uint16_t minor () const noexcept; - std::uint16_t patch () const noexcept; + std::uint32_t major () const noexcept; + std::uint32_t minor () const noexcept; + std::uint32_t patch () const noexcept; // Return the alpha/beta version number if pre-release and nullopt // otherwise. @@ -201,16 +201,16 @@ LIBBUTL_MODEXPORT namespace butl // by 500 for betas. // standard_version (std::uint16_t epoch, - std::uint16_t major, - std::uint16_t minor, - std::uint16_t patch, + std::uint32_t major, + std::uint32_t minor, + std::uint32_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::uint32_t major, + std::uint32_t minor, + std::uint32_t patch, std::uint16_t pre_release, std::uint64_t snapshot_sn, std::string snapshot_id, -- cgit v1.1