aboutsummaryrefslogtreecommitdiff
path: root/butl/standard-version.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-04-25 11:53:11 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2017-04-26 14:19:50 +0300
commit1bea889fd59b4ac3a32232e8f7a9ba34506717dc (patch)
tree1f67ea3eb8f1ee9eab528a4ca57ce27530ed8bd3 /butl/standard-version.ixx
parentaef93c360bb8de3dd49138e9f9a065ef631a303c (diff)
Add standard_version class
Diffstat (limited to 'butl/standard-version.ixx')
-rw-r--r--butl/standard-version.ixx94
1 files changed, 94 insertions, 0 deletions
diff --git a/butl/standard-version.ixx b/butl/standard-version.ixx
new file mode 100644
index 0000000..e414deb
--- /dev/null
+++ b/butl/standard-version.ixx
@@ -0,0 +1,94 @@
+// file : butl/standard-version.ixx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+namespace butl
+{
+ inline standard_version::
+ standard_version ( std::uint16_t e,
+ std::uint64_t v,
+ const std::string& s,
+ std::uint16_t r)
+ : standard_version (v, s)
+ {
+ // Can't initialize above due to ctor delegating.
+ //
+ epoch = e;
+ revision = r;
+ }
+
+ inline std::uint16_t standard_version::
+ major () const
+ {
+ std::uint64_t v (version / 10);
+ std::uint64_t ab (v % 1000);
+ if (ab != 0)
+ v += 1000 - ab;
+
+ return static_cast<std::uint16_t> (v / 1000000000 % 1000);
+ }
+
+ inline std::uint16_t standard_version::
+ minor () const
+ {
+ std::uint64_t v (version / 10);
+ std::uint64_t ab (v % 1000);
+ if (ab != 0)
+ v += 1000 - ab;
+
+ return static_cast<std::uint16_t> (v / 1000000 % 1000);
+ }
+
+ inline std::uint16_t standard_version::
+ patch () const
+ {
+ std::uint64_t v (version / 10);
+ std::uint64_t ab (v % 1000);
+ if (ab != 0)
+ v += 1000 - ab;
+
+ return static_cast<std::uint16_t> (v / 1000 % 1000);
+ }
+
+ inline std::uint16_t standard_version::
+ pre_release () const
+ {
+ std::uint64_t ab (version / 10 % 1000);
+ if (ab > 500)
+ ab -= 500;
+
+ return static_cast<std::uint16_t> (ab);
+ }
+
+ inline bool standard_version::
+ alpha () const
+ {
+ std::uint64_t abe (version % 10000);
+ return abe > 0 && abe < 5000;
+ }
+
+ inline bool standard_version::
+ beta () const
+ {
+ std::uint64_t abe (version % 10000);
+ return abe > 5000;
+ }
+
+ inline int standard_version::
+ compare (const standard_version& v) const
+ {
+ if (epoch != v.epoch)
+ return epoch < v.epoch ? -1 : 1;
+
+ if (version != v.version)
+ return version < v.version ? -1 : 1;
+
+ if (snapshot_sn != v.snapshot_sn)
+ return snapshot_sn < v.snapshot_sn ? -1 : 1;
+
+ if (revision != v.revision)
+ return revision < v.revision ? -1 : 1;
+
+ return 0;
+ }
+}