HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_3166_intf.hpp
1// Copyright Take Vos 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/utility.hpp"
8#include "../macros.hpp"
9#include <compare>
10#include <cctype>
11#include <string_view>
12#include <string>
13#include <format>
14
15hi_export_module(hikogui.i18n.iso_3166 : intf);
16
17hi_export namespace hi::inline v1 {
18
21hi_export class iso_3166 {
22public:
23 constexpr iso_3166(iso_3166 const&) noexcept = default;
24 constexpr iso_3166(iso_3166&&) noexcept = default;
25 constexpr iso_3166& operator=(iso_3166 const&) noexcept = default;
26 constexpr iso_3166& operator=(iso_3166&&) noexcept = default;
27
28 constexpr iso_3166() noexcept : _v(0) {}
29
30 constexpr iso_3166(uint16_t number) : _v(number)
31 {
32 hi_check(number <= 999, "ISO-3166 number must be between 0 and 999, got {}", number);
33 }
34
35 constexpr iso_3166(std::string_view str);
36
37 constexpr iso_3166(std::in_place_t, uint16_t v) noexcept : _v(v)
38 {
39 hi_axiom(_v < 1000);
40 }
41
42 [[nodiscard]] constexpr uint16_t const& intrinsic() const noexcept
43 {
44 return _v;
45 }
46
47 [[nodiscard]] constexpr uint16_t& intrinsic() noexcept
48 {
49 return _v;
50 }
51
52 [[nodiscard]] constexpr bool empty() const noexcept
53 {
54 return _v == 0;
55 }
56
57 constexpr explicit operator bool() const noexcept
58 {
59 return not empty();
60 }
61
62 [[nodiscard]] constexpr uint16_t number() const noexcept
63 {
64 return _v;
65 }
66
67 [[nodiscard]] constexpr std::string code2() const noexcept;
68 [[nodiscard]] constexpr std::string code3() const noexcept;
69
70 [[nodiscard]] constexpr friend std::string to_string(iso_3166 const &rhs) noexcept
71 {
72 return rhs.code2();
73 }
74
75 [[nodiscard]] constexpr friend bool operator==(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
76 [[nodiscard]] constexpr friend auto operator<=>(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
77
84 [[nodiscard]] constexpr friend bool matches(iso_3166 const& lhs, iso_3166 const& rhs) noexcept
85 {
86 return lhs.empty() or lhs == rhs;
87 }
88
89private:
90 uint16_t _v;
91};
92
93} // namespace hi::inline v1
94
95template<>
96struct std::hash<hi::iso_3166> {
97 [[nodiscard]] size_t operator()(hi::iso_3166 const& rhs) const noexcept
98 {
99 return std::hash<uint16_t>{}(rhs.number());
100 }
101};
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
ISO-3166 country code.
Definition iso_3166_intf.hpp:21
constexpr friend bool matches(iso_3166 const &lhs, iso_3166 const &rhs) noexcept
Check if rhs matches with lhs.
Definition iso_3166_intf.hpp:84
T operator()(T... args)