HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_15924.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/module.hpp"
8#include <string_view>
9#include <cstdint>
10#include <format>
11
12namespace hi::inline v1 {
13
17class iso_15924 {
18public:
19 constexpr iso_15924() noexcept : _v(0) {}
20 constexpr iso_15924(iso_15924 const&) noexcept = default;
21 constexpr iso_15924(iso_15924&&) noexcept = default;
22 constexpr iso_15924& operator=(iso_15924 const&) noexcept = default;
23 constexpr iso_15924& operator=(iso_15924&&) noexcept = default;
24
25 constexpr iso_15924(std::integral auto number) : _v(0)
26 {
27 hi_check_bounds(number, 0, 1000);
28 _v = narrow_cast<uint16_t>(number);
29 }
30
31 iso_15924(std::string_view code4);
32
33 constexpr iso_15924(intrinsic_t, uint16_t v) noexcept : _v(v)
34 {
35 hi_axiom_bounds(_v, 0, 1000);
36 }
37
38 [[nodiscard]] constexpr uint16_t const& intrinsic() const noexcept
39 {
40 return _v;
41 }
42
43 [[nodiscard]] constexpr uint16_t& intrinsic() noexcept
44 {
45 return _v;
46 }
47
48 [[nodiscard]] constexpr bool empty() const noexcept
49 {
50 return _v == 0;
51 }
52
53 explicit operator bool() const noexcept
54 {
55 return not empty();
56 }
57
60 [[nodiscard]] constexpr uint16_t number() const noexcept
61 {
62 return _v;
63 }
64
67 [[nodiscard]] std::string_view code4() const noexcept;
68
71 [[nodiscard]] std::string_view code4_open_type() const noexcept;
72
75 [[nodiscard]] bool left_to_right() const noexcept;
76
77 [[nodiscard]] constexpr friend bool operator==(iso_15924 const& lhs, iso_15924 const& rhs) noexcept = default;
78 [[nodiscard]] constexpr friend auto operator<=>(iso_15924 const& lhs, iso_15924 const& rhs) noexcept = default;
79
86 [[nodiscard]] constexpr friend bool matches(iso_15924 const& lhs, iso_15924 const& rhs) noexcept
87 {
88 return lhs.empty() or lhs == rhs;
89 }
90
91private:
92 uint16_t _v;
93};
94
95} // namespace hi::inline v1
96
97template<>
98struct std::hash<hi::iso_15924> {
99 [[nodiscard]] size_t operator()(hi::iso_15924 const& rhs) const noexcept
100 {
101 return std::hash<uint16_t>{}(rhs.number());
102 }
103};
#define hi_axiom_bounds(x,...)
Specify an axiom that the value is within bounds.
Definition assert.hpp:264
#define hi_check_bounds(x,...)
Assert if a value is within bounds, or throw a parse_error.
Definition assert.hpp:132
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
ISO-15924 script code.
Definition iso_15924.hpp:17
std::string_view code4() const noexcept
Get the iso-15924 4-letter code.
constexpr uint16_t number() const noexcept
Get the iso-15924 numeric value.
Definition iso_15924.hpp:60
T operator()(T... args)