aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.core/errc.cc
blob: 35c9d8fb041bf9c44a9d9ac5536bb7c38666fe0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * This source code is released into the public domain.
 */

module;

#include <string>
#include <system_error>

module nihil.core;

namespace nihil {

struct nihil_error_category final : std::error_category {
	[[nodiscard]] auto name() const noexcept -> char const * override;
	[[nodiscard]] auto message(int err) const -> std::string override;
};

[[nodiscard]] auto nihil_category() noexcept -> std::error_category &
{
	static auto category = nihil_error_category();
	return category;
}

auto make_error_condition(errc ec) -> std::error_condition
{
	return {static_cast<int>(ec), nihil_category()};
}

auto nihil_error_category::name() const noexcept -> char const *
{
	return "nihil";
}

auto nihil_error_category::message(int err) const -> std::string
{
	switch (static_cast<errc>(err)) {
	case errc::no_error:
		return "No error";
	case errc::incomplete_command:
		return "Incomplete command";
	case errc::empty_string:
		return "Empty string is not permitted";
	case errc::invalid_unit:
		return "Invalid unit specifier";
	default:
		return "Undefined error";
	}
}

} // namespace nihil