IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
mem_size_types.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/mem_types.hxx>
7
8namespace ice
9{
10
13 struct isize
14 {
16 using base_type = std::conditional_t<ice::build::is_x64, ice::i64, ice::i32>;
17
18 constexpr auto to_usize() const noexcept;
19
21 };
22
25 struct usize
26 {
28 using base_type = std::size_t;
29
30 constexpr operator isize() const noexcept;
31
33 static constexpr auto subtract(ice::usize left, ice::usize right) noexcept -> ice::usize;
34
36 };
37
38 enum class ualign : ice::u32
39 {
41
42 b_1 = 1,
43 b_2 = 2,
44 b_4 = 4,
45 b_8 = 8,
46 b_16 = 16,
47 b_32 = 32,
48 b_64 = 64,
49 b_128 = 128,
50 b_256 = 256,
51 b_512 = 512,
52 b_1024 = 1024,
53 b_2048 = 2048,
54
56 };
57
63
64
65 // MEMORY SIZE LITERALS
66
67 constexpr auto operator""_B(unsigned long long v) noexcept -> ice::usize
68 {
69 return ice::usize{ static_cast<ice::usize::base_type>(v) };
70 }
71
72 constexpr auto operator""_KiB(unsigned long long v) noexcept -> ice::usize
73 {
74 return ice::usize{ static_cast<ice::usize::base_type>(v) * 1024 };
75 }
76
77 constexpr auto operator""_MiB(unsigned long long v) noexcept -> ice::usize
78 {
79 return ice::usize{ static_cast<ice::usize::base_type>(v) * 1024 * 1024 };
80 }
81
82 // EXPLICIT OPERATORS
83
84 constexpr auto isize::to_usize() const noexcept
85 {
86 return ice::usize{ static_cast<ice::usize::base_type>(value) };
87 }
88
89 constexpr usize::operator isize() const noexcept
90 {
91 return ice::isize{ static_cast<ice::isize::base_type>(value) };
92 }
93
94 constexpr auto usize::subtract(ice::usize baseval, ice::usize subval) noexcept -> ice::usize
95 {
96 ICE_ASSERT_CORE(baseval >= subval);
97 return { baseval.value - subval.value };
98 }
99
100
101 constexpr auto operator-(ice::usize left, ice::usize right) noexcept -> ice::isize
102 {
103 return { static_cast<ice::isize::base_type>(left.value) - static_cast<ice::isize::base_type>(right.value) };
104 }
105
106 constexpr auto operator-=(ice::usize& left, ice::usize right) noexcept -> ice::usize& = delete;
107
108 constexpr auto operator-(ice::usize left) noexcept -> ice::isize
109 {
110 return { -static_cast<ice::isize::base_type>(left.value) };
111 }
112
113 constexpr auto operator==(ice::usize left, ice::isize right) noexcept -> bool
114 {
115 return static_cast<ice::isize::base_type>(left.value) == right.value;
116 }
117
118 constexpr auto operator+(ice::usize left, ice::isize right) noexcept -> ice::isize
119 {
120 return { static_cast<ice::isize::base_type>(left.value) + right.value };
121 }
122
123 constexpr auto operator-(ice::usize left, ice::isize right) noexcept -> ice::isize
124 {
125 return { static_cast<ice::isize::base_type>(left.value) - right.value };
126 }
127
128 constexpr auto operator+(ice::isize left, ice::usize right) noexcept -> ice::isize
129 {
130 return { left.value + static_cast<ice::isize::base_type>(right.value) };
131 }
132
133 constexpr auto operator-(ice::isize left, ice::usize right) noexcept -> ice::isize
134 {
135 return { left.value - static_cast<ice::isize::base_type>(right.value) };
136 }
137
138 constexpr auto operator%(ice::usize left, ice::ualign right) noexcept -> ice::usize
139 {
140 return { left.value % static_cast<ice::usize::base_type>(right) };
141 }
142
143 constexpr auto operator%(ice::isize left, ice::ualign right) noexcept -> ice::isize
144 {
145 return { left.value % static_cast<ice::isize::base_type>(right) };
146 }
147
148 constexpr auto operator<=>(ice::usize left, ice::isize right) noexcept
149 {
150 return static_cast<ice::isize::base_type>(left.value) <=> right.value;
151 }
152
153 constexpr auto operator<=>(ice::isize left, ice::usize right) noexcept
154 {
155 return left.value <=> static_cast<ice::isize::base_type>(right.value);
156 }
157
158} // namespace ice
#define ICE_ASSERT_CORE(expression)
Definition assert_core.hxx:43
static constexpr bool is_x64
Definition build.hxx:34
SPDX-License-Identifier: MIT.
Definition array.hxx:12
constexpr auto operator<=>(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:135
constexpr auto operator-(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:151
constexpr auto operator==(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:159
constexpr auto operator-=(T &left, T right) noexcept -> T &
Definition strong_type_integral.hxx:127
constexpr auto operator%(ice::usize left, ice::ualign right) noexcept -> ice::usize
Definition mem_size_types.hxx:138
std::uint32_t u32
Definition types.hxx:26
ualign
Definition mem_size_types.hxx:39
@ b_4
Definition mem_size_types.hxx:44
@ b_8
Definition mem_size_types.hxx:45
@ b_128
Definition mem_size_types.hxx:49
@ b_default
Definition mem_size_types.hxx:55
@ b_512
Definition mem_size_types.hxx:51
@ b_2
Definition mem_size_types.hxx:43
@ b_16
Definition mem_size_types.hxx:46
@ b_32
Definition mem_size_types.hxx:47
@ b_64
Definition mem_size_types.hxx:48
@ b_1
Definition mem_size_types.hxx:42
@ b_1024
Definition mem_size_types.hxx:52
@ b_2048
Definition mem_size_types.hxx:53
@ b_256
Definition mem_size_types.hxx:50
@ invalid
Definition mem_size_types.hxx:40
constexpr auto operator+(ice::TimeType auto left, TimeType auto right) noexcept
Definition clock_types.hxx:143
Type tag to enable utility functions for strongly typed numeric values.
Definition strong_type_integral.hxx:11
Represents a signed size value on the given platform.
Definition mem_size_types.hxx:14
ice::StrongNumeric TypeTag
Definition mem_size_types.hxx:15
constexpr auto to_usize() const noexcept
Definition mem_size_types.hxx:84
base_type value
Definition mem_size_types.hxx:20
std::conditional_t< ice::build::is_x64, ice::i64, ice::i32 > base_type
Definition mem_size_types.hxx:16
Definition mem_size_types.hxx:59
ice::ualign alignment
Definition mem_size_types.hxx:61
ice::usize size
Definition mem_size_types.hxx:60
Represents a unsigned size value on the given platform.
Definition mem_size_types.hxx:26
base_type value
Definition mem_size_types.hxx:35
ice::StrongNumeric TypeTag
Definition mem_size_types.hxx:27
std::size_t base_type
Definition mem_size_types.hxx:28
static constexpr auto subtract(ice::usize left, ice::usize right) noexcept -> ice::usize
Perform a checked subtraction, ensuring 'left' is greater or equal to 'right'.
Definition mem_size_types.hxx:94