IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
ncount.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/mem.hxx>
7
8namespace ice
9{
10
11 struct ncount_invalid_t;
12
13 struct ncount : public ice::nvalue
14 {
17 using ice::nvalue::operator==;
18
19 // support for allocation sizes
20 constexpr auto bytes(this ncount self) noexcept -> ice::usize;
21
22 constexpr ncount() noexcept = default;
23 constexpr ncount(nvalue value) noexcept;
24 constexpr ncount(base_type value) noexcept;
25 constexpr ncount(base_type value, base_type width) noexcept;
26
27 // special operators
28 constexpr bool operator==(this ncount self, ncount_invalid_t) noexcept;
29
30 // implicit type conversions
31 constexpr operator ice::usize(this ncount self) noexcept { return self.bytes(); }
32 };
33
35
36 inline constexpr auto ncount::bytes(this ncount self) noexcept -> ice::usize
37 {
38 return { static_cast<ice::usize::base_type>(std::max<base_signed_type>(self._value, 0)) * self._width };
39 }
40
41 inline constexpr ncount::ncount(nvalue value) noexcept
42 : nvalue{ value._width, value._value }
43 { }
44
45 inline constexpr ncount::ncount(base_type value) noexcept
46 : nvalue{ 1, static_cast<base_signed_type>(value) }
47 { }
48
49 inline constexpr ncount::ncount(base_type value, base_type width) noexcept
50 : nvalue{ width, static_cast<base_signed_type>(value) }
51 { }
52
53 inline constexpr bool ncount::operator==(this ncount self, ncount_invalid_t) noexcept
54 {
55 return self._width == 0;
56 }
57
61
62 constexpr auto operator""_count(unsigned long long value) noexcept -> ice::ncount
63 {
64 return ice::ncount{ value };
65 }
66
68 // For x64 platforms, size of size_t, for x32 platforms 2x32
69 static_assert(Test_Meminfo.size == 8_B);
70
71} // namespace ice
consteval auto nvalue_min_value() noexcept -> ice::detail::nvalue_base_utype
Definition nvalue.hxx:63
consteval auto nvalue_max_value() noexcept -> ice::detail::nvalue_base_utype
Definition nvalue.hxx:68
SPDX-License-Identifier: MIT.
Definition array.hxx:12
static constexpr ice::ncount ncount_min
Definition ncount.hxx:59
static constexpr ice::ncount ncount_max
Definition ncount.hxx:58
static constexpr ice::meminfo Test_Meminfo
Definition ncount.hxx:67
constexpr ice::meminfo meminfo_of
Definition mem_info.hxx:18
static constexpr ice::ncount_invalid_t ncount_none
Definition ncount.hxx:60
Definition mem_size_types.hxx:59
Definition ncount.hxx:34
Definition ncount.hxx:14
constexpr bool operator==(this ncount self, ncount_invalid_t) noexcept
Definition ncount.hxx:53
ice::detail::nvalue_base_stype base_signed_type
Definition nvalue.hxx:76
constexpr auto bytes(this ncount self) noexcept -> ice::usize
Definition ncount.hxx:36
constexpr operator ice::usize(this ncount self) noexcept
Definition ncount.hxx:31
constexpr ncount() noexcept=default
ice::detail::nvalue_base_utype base_type
Definition nvalue.hxx:75
Definition nvalue.hxx:74
ice::detail::nvalue_base_stype base_signed_type
Definition nvalue.hxx:76
ice::detail::nvalue_base_utype base_type
Definition nvalue.hxx:75
Represents a unsigned size value on the given platform.
Definition mem_size_types.hxx:26
std::size_t base_type
Definition mem_size_types.hxx:28