HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_3166.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 <cctype>
8#include "../utility/module.hpp"
9#include "../strings.hpp"
10
11namespace hi::inline v1 {
12
15class iso_3166 {
16public:
17 constexpr iso_3166(iso_3166 const&) noexcept = default;
18 constexpr iso_3166(iso_3166&&) noexcept = default;
19 constexpr iso_3166& operator=(iso_3166 const&) noexcept = default;
20 constexpr iso_3166& operator=(iso_3166&&) noexcept = default;
21
22 constexpr iso_3166() noexcept : _v(0) {}
23
24 constexpr iso_3166(uint16_t number) : _v(number)
25 {
26 hi_check(number <= 999, "ISO-3166 number must be between 0 and 999, got {}", number);
27 }
28
29 iso_3166(std::string_view str);
30
31 constexpr iso_3166(intrinsic_t, uint16_t v) noexcept : _v(v)
32 {
33 hi_axiom(_v < 1000);
34 }
35
36 [[nodiscard]] constexpr uint16_t const& intrinsic() const noexcept
37 {
38 return _v;
39 }
40
41 [[nodiscard]] constexpr uint16_t& intrinsic() noexcept
42 {
43 return _v;
44 }
45
46 [[nodiscard]] constexpr bool empty() const noexcept
47 {
48 return _v == 0;
49 }
50
51 constexpr explicit operator bool() const noexcept
52 {
53 return not empty();
54 }
55
56 [[nodiscard]] constexpr uint16_t number() const noexcept
57 {
58 return _v;
59 }
60
61 [[nodiscard]] std::string_view code2() const noexcept;
62 [[nodiscard]] std::string_view code3() const noexcept;
63
64 [[nodiscard]] constexpr friend bool operator==(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
65 [[nodiscard]] constexpr friend auto operator<=>(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
66
73 [[nodiscard]] constexpr friend bool matches(iso_3166 const& lhs, iso_3166 const& rhs) noexcept
74 {
75 return lhs.empty() or lhs == rhs;
76 }
77
78private:
79 uint16_t _v;
80};
81
82} // namespace hi::inline v1
83
84template<>
85struct std::hash<hi::iso_3166> {
86 [[nodiscard]] size_t operator()(hi::iso_3166 const& rhs) const noexcept
87 {
88 return std::hash<uint16_t>{}(rhs.number());
89 }
90};
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:110
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
ISO-3166 country code.
Definition iso_3166.hpp:15
constexpr friend bool matches(iso_3166 const &lhs, iso_3166 const &rhs) noexcept
Check if rhs matches with lhs.
Definition iso_3166.hpp:73
T operator()(T... args)