From f2dce910981bbae0532f1d15ce1944d0bee70bd4 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Wed, 1 Mar 2023 14:46:19 +0100 Subject: [PATCH] Make Error classes header only --- fairmq/CMakeLists.txt | 1 - fairmq/Error.cxx | 39 --------------------------------------- fairmq/Error.h | 28 ++++++++++++++++++++++++---- 3 files changed, 24 insertions(+), 44 deletions(-) delete mode 100644 fairmq/Error.cxx diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index 0d36c9fe..1b49e599 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -117,7 +117,6 @@ if(BUILD_FAIRMQ) Channel.cxx Device.cxx DeviceRunner.cxx - Error.cxx JSONParser.cxx MemoryResources.cxx Plugin.cxx diff --git a/fairmq/Error.cxx b/fairmq/Error.cxx deleted file mode 100644 index 90f257fb..00000000 --- a/fairmq/Error.cxx +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * - * * - * This software is distributed under the terms of the * - * GNU Lesser General Public Licence (LGPL) version 3, * - * copied verbatim in the file "LICENSE" * - ********************************************************************************/ - -#include "Error.h" - -namespace fair::mq { - -const char* ErrorCategory::name() const noexcept { return "fairmq"; } - -std::string ErrorCategory::message(int ev) const -{ - switch (static_cast(ev)) { - case ErrorCode::OperationInProgress: - return "async operation already in progress"; - case ErrorCode::OperationTimeout: - return "async operation timed out"; - case ErrorCode::OperationCanceled: - return "async operation canceled"; - case ErrorCode::DeviceChangeStateFailed: - return "failed to change state of a fairmq device"; - case ErrorCode::DeviceGetPropertiesFailed: - return "failed to get fairmq device properties"; - case ErrorCode::DeviceSetPropertiesFailed: - return "failed to set fairmq device properties"; - default: - return "(unrecognized error)"; - } -} - -const ErrorCategory errorCategory{}; - -std::error_code MakeErrorCode(ErrorCode e) { return {static_cast(e), errorCategory}; } - -} // namespace fair::mq diff --git a/fairmq/Error.h b/fairmq/Error.h index eed0d56b..0d06f132 100644 --- a/fairmq/Error.h +++ b/fairmq/Error.h @@ -38,14 +38,34 @@ enum class ErrorCode DeviceSetPropertiesFailed }; -std::error_code MakeErrorCode(ErrorCode); - struct ErrorCategory : std::error_category { - const char* name() const noexcept override; - std::string message(int ev) const override; + const char* name() const noexcept override { return "fairmq"; } + std::string message(int ev) const override + { + switch (static_cast(ev)) { + case ErrorCode::OperationInProgress: + return "async operation already in progress"; + case ErrorCode::OperationTimeout: + return "async operation timed out"; + case ErrorCode::OperationCanceled: + return "async operation canceled"; + case ErrorCode::DeviceChangeStateFailed: + return "failed to change state of a fairmq device"; + case ErrorCode::DeviceGetPropertiesFailed: + return "failed to get fairmq device properties"; + case ErrorCode::DeviceSetPropertiesFailed: + return "failed to set fairmq device properties"; + default: + return "(unrecognized error)"; + } + } }; +static ErrorCategory ec; + +inline std::error_code MakeErrorCode(ErrorCode e) { return {static_cast(e), ec}; } + } // namespace fair::mq namespace std {