rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
version.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include "platform/constexpr.hpp"
6#include "binary/bit.hpp"
7
8#include <ostream>
9#include <cstdint>
10
11namespace rexlib
12{
13
15{
16public:
17 version() = default;
18 REXLIB_CONSTEXPR version(
19 std::uint32_t major,
20 std::uint32_t minor,
21 std::uint32_t patch
22 ) noexcept;
23 version(const version& other) = default;
24 ~version() = default;
25
26 version& operator=(const version& other) = default;
27
28 REXLIB_CONSTEXPR void set_major(std::uint32_t major) noexcept;
29 REXLIB_CONSTEXPR std::uint32_t get_major() const noexcept;
30
31 REXLIB_CONSTEXPR void set_minor(std::uint32_t minor) noexcept;
32 REXLIB_CONSTEXPR std::uint32_t get_minor() const noexcept;
33
34 REXLIB_CONSTEXPR void set_patch(std::uint32_t patch) noexcept;
35 REXLIB_CONSTEXPR std::uint32_t get_patch() const noexcept;
36
37 REXLIB_CONSTEXPR std::uint32_t get_data() const noexcept;
38
39 friend REXLIB_CONSTEXPR
40 bool operator==(const version& lhs, const version& rhs) noexcept
41 {
42 return lhs.get_data() == rhs.get_data();
43 }
44
45 friend REXLIB_CONSTEXPR
46 bool operator!=(const version& lhs, const version& rhs) noexcept
47 {
48 return lhs.get_data() != rhs.get_data();
49 }
50
51 friend REXLIB_CONSTEXPR
52 bool operator<(const version& lhs, const version& rhs) noexcept
53 {
54 return lhs.get_data() < rhs.get_data();
55 }
56
57 friend REXLIB_CONSTEXPR
58 bool operator<=(const version& lhs, const version& rhs) noexcept
59 {
60 return lhs.get_data() <= rhs.get_data();
61 }
62
63 friend REXLIB_CONSTEXPR
64 bool operator>(const version& lhs, const version& rhs) noexcept
65 {
66 return lhs.get_data() > rhs.get_data();
67 }
68
69 friend REXLIB_CONSTEXPR
70 bool operator>=(const version& lhs, const version& rhs) noexcept
71 {
72 return lhs.get_data() >= rhs.get_data();
73 }
74
75 template<typename T>
76 friend std::basic_ostream<T>&
77 operator<<(std::basic_ostream<T>& os, const version& ver)
78 {
79 REXLIB_CONST_CONSTEXPR T sep = '.';
80 return os
81 << ver.get_major() << sep
82 << ver.get_minor() << sep
83 << ver.get_patch();
84 }
85
86private:
87 static REXLIB_INLINE_CONST_CONSTEXPR std::size_t patch_bits = 10;
88 static REXLIB_INLINE_CONST_CONSTEXPR std::size_t minor_bits = 10;
89 static REXLIB_INLINE_CONST_CONSTEXPR std::size_t major_bits = 12;
90
91 static REXLIB_INLINE_CONST_CONSTEXPR std::size_t patch_offset = 0;
92 static REXLIB_INLINE_CONST_CONSTEXPR std::size_t minor_offset = patch_offset + patch_bits;
93 static REXLIB_INLINE_CONST_CONSTEXPR std::size_t major_offset = minor_offset + minor_bits;
94
95 static REXLIB_INLINE_CONST_CONSTEXPR std::uint32_t patch_mask =
96 bit_range_mask<std::uint32_t>(patch_offset, patch_offset+patch_bits);
97 static REXLIB_INLINE_CONST_CONSTEXPR std::uint32_t minor_mask =
98 bit_range_mask<std::uint32_t>(minor_offset, minor_offset+minor_bits);
99 static REXLIB_INLINE_CONST_CONSTEXPR std::uint32_t major_mask =
100 bit_range_mask<std::uint32_t>(major_offset, major_offset+major_bits);
101
102 std::uint32_t m_data;
103};
104
105} // namespace rexlib
106
107#include "version.inl"
Container for multidimensional numeric data.
Definition array.hpp:31
Definition version.hpp:15
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10