From 669a246c175a002e368404fc0037379900bcca04 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 1 May 2017 16:21:37 +0300 Subject: service: refactoring * No more compiler-specific macros. --- um/service/include/service/common.hpp | 9 ----- um/service/include/service/windows_error.hpp | 52 +++++++++++++++------------- 2 files changed, 28 insertions(+), 33 deletions(-) (limited to 'um/service/include') diff --git a/um/service/include/service/common.hpp b/um/service/include/service/common.hpp index a1c46fb..89aa600 100644 --- a/um/service/include/service/common.hpp +++ b/um/service/include/service/common.hpp @@ -5,13 +5,4 @@ #pragma once -#define LIBSERVICE_FILE_PATH __FILE__ -#define LIBSERVICE_LINE_NUMBER __LINE__ -#define LIBSERVICE_FUNCTION_NAME __FUNCTION__ - -#define LIBSERVICE_TO_STRING(s) LIBSERVICE_TO_STRING_(s) -#define LIBSERVICE_TO_STRING_(s) #s - -#define LIBSERVICE_LINE_NUMBER_STRING LIBSERVICE_TO_STRING(LIBSERVICE_LINE_NUMBER) - #define LIBSERVICE_NOEXCEPT throw() diff --git a/um/service/include/service/windows_error.hpp b/um/service/include/service/windows_error.hpp index c96dcfc..ab46cfd 100644 --- a/um/service/include/service/windows_error.hpp +++ b/um/service/include/service/windows_error.hpp @@ -8,31 +8,33 @@ #include "common.hpp" #include "singleton.hpp" +#include + #include #include #include namespace service { - class WindowsErrorCategory - : public std::error_category - , public Singleton + namespace windows_error { - public: - const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; } + class Category + : public std::error_category + , public Singleton + { + public: + const char* name() const LIBSERVICE_NOEXCEPT { return "Windows"; } - std::string message(int) const; + std::string message(int) const; - private: - friend class Singleton; - }; + private: + friend class Singleton; + }; - namespace error - { - inline std::string build_what( - const char* function, + inline std::string build_message_prefix( const char* file, - int line) + int line, + const char* function) { std::ostringstream oss; oss << "Error in function '" << function @@ -40,15 +42,17 @@ namespace service << "', line " << line; return oss.str(); } + + inline std::system_error make( + DWORD code, + const char* file, + int line, + const char* function) + { + return std::system_error( + code, + Category::get(), + build_message_prefix(file, line, function)); + } } } - -#if defined(_MSC_VER) -#define LIBSERVICE_ERROR_PREFIX \ - "Error in function '" LIBSERVICE_FUNCTION_NAME "' at file '" LIBSERVICE_FILE_PATH "', line " LIBSERVICE_LINE_NUMBER_STRING -#elif defined(__GNUC__) -#define LIBSERVICE_ERROR_PREFIX \ - service::error::build_what(LIBSERVICE_FUNCTION_NAME, LIBSERVICE_FILE_PATH, LIBSERVICE_LINE_NUMBER) -#else -#define LIBSERVICE_ERROR_PREFIX "Error" -#endif -- cgit v1.2.3