From 378dd663a402fe196f2b56c6413eb3f623aecbbf Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Tue, 1 Jul 2025 19:18:42 +0100 Subject: cli: refactoring --- nihil.core/CMakeLists.txt | 3 --- nihil.core/errc.cc | 49 ----------------------------------------- nihil.core/errc.ccm | 55 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 62 deletions(-) delete mode 100644 nihil.core/errc.cc (limited to 'nihil.core') diff --git a/nihil.core/CMakeLists.txt b/nihil.core/CMakeLists.txt index cbb1b6b..637b825 100644 --- a/nihil.core/CMakeLists.txt +++ b/nihil.core/CMakeLists.txt @@ -8,7 +8,4 @@ target_sources(nihil.core nihil.core.ccm errc.ccm features.ccm - - PRIVATE - errc.cc ) diff --git a/nihil.core/errc.cc b/nihil.core/errc.cc deleted file mode 100644 index 411ad66..0000000 --- a/nihil.core/errc.cc +++ /dev/null @@ -1,49 +0,0 @@ -// This source code is released into the public domain. -module nihil.core; - -import nihil.std; - -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(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(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"; - case errc::failed_to_create_object: - return "Failed to create UCL object"; - case errc::type_mismatch: - return "UCL type does not match expected type"; - default: - return "Undefined error"; - } -} - -} // namespace nihil diff --git a/nihil.core/errc.ccm b/nihil.core/errc.ccm index f5aac0b..fe36274 100644 --- a/nihil.core/errc.ccm +++ b/nihil.core/errc.ccm @@ -8,22 +8,19 @@ namespace nihil { export enum struct errc : std::uint8_t { no_error = 0, - // + /////////////////////////////////////////////////////////////// // nihil.command - // incomplete_command, - // + /////////////////////////////////////////////////////////////// // nihil.ucl - // failed_to_create_object, type_mismatch, - // + /////////////////////////////////////////////////////////////// // nihil.util - // // Empty string is not allowed. empty_string, @@ -32,10 +29,48 @@ export enum struct errc : std::uint8_t { invalid_unit, }; -export [[nodiscard]] auto nihil_category() noexcept -> std::error_category &; -export [[nodiscard]] auto make_error_condition(errc ec) -> std::error_condition; +struct nihil_error_category final : std::error_category +{ + [[nodiscard]] auto name() const noexcept -> char const * override + { + return "nihil"; + } + + [[nodiscard]] auto message(int err) const -> std::string override + { + switch (static_cast(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"; + case errc::failed_to_create_object: + return "Failed to create UCL object"; + case errc::type_mismatch: + return "UCL type does not match expected type"; + default: + return "Undefined error"; + } + } +}; + +export [[nodiscard]] auto nihil_category() noexcept -> std::error_category & +{ + static auto category = nihil_error_category(); + return category; +} + +export [[nodiscard]] auto make_error_condition(errc ec) -> std::error_condition +{ + return {static_cast(ec), nihil_category()}; +} } // namespace nihil -template<> -struct std::is_error_condition_enum : std::true_type {}; +export template <> +struct std::is_error_condition_enum : std::true_type +{ +}; -- cgit v1.2.3