diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-29 17:16:22 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-29 17:16:22 +0100 |
| commit | 4fa6821e0645ff61a9380cd090abff472205c630 (patch) | |
| tree | bd95f13b2dc0bd9692681f50c365d2914a520bfe /nihil.core/errc.cc | |
| parent | e5180acf5f2dfac788e8c12886095ed1ac66fae5 (diff) | |
| download | nihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.gz nihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.bz2 | |
add clang-tidy support
Diffstat (limited to 'nihil.core/errc.cc')
| -rw-r--r-- | nihil.core/errc.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nihil.core/errc.cc b/nihil.core/errc.cc new file mode 100644 index 0000000..35c9d8f --- /dev/null +++ b/nihil.core/errc.cc @@ -0,0 +1,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 |
