From 7409d8ddd39944c4e68ebd50c732ee9a9a886583 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Nov 2023 19:31:46 +0100 Subject: a --- compat/debug.cpp | 29 ++++++++++++++++++++++++----- compat/debug.hpp | 27 ++++++++++++++++----------- 2 files changed, 40 insertions(+), 16 deletions(-) (limited to 'compat') diff --git a/compat/debug.cpp b/compat/debug.cpp index 0a342f8b..e3efaf5c 100644 --- a/compat/debug.cpp +++ b/compat/debug.cpp @@ -1,24 +1,43 @@ -#define FM_NO_CORRADE_DEBUG_EXTERN_TEMPLATE_QUOTED #include "debug.hpp" +#include "compat/strerror.hpp" namespace floormat::detail::corrade_debug { +Debug& operator<<(Debug& dbg, ErrorString box) +{ + auto flags = dbg.flags(); + char buf[256]; + dbg.setFlags(flags | Debug::Flag::NoSpace); + dbg << ": "; + dbg << get_error_string(buf, box.value); + dbg.setFlags(flags); + return dbg; +} + template struct Quoted; -Debug::Flags debug1(Debug& dbg) +Debug::Flags debug1(Debug& dbg, char c) { auto flags = dbg.flags(); dbg << ""; dbg.setFlags(flags | Debug::Flag::NoSpace); - dbg << "'"; + char buf[2] { c, '\0' }; + dbg << buf; return flags; } -Debug& debug2(Debug& dbg, Debug::Flags flags) +Debug& debug2(Debug& dbg, Debug::Flags flags, char c) { - dbg << "'"; + char buf[2] { c, '\0' }; + dbg << buf; dbg.setFlags(flags); return dbg; } } // namespace floormat::detail::corrade_debug + +namespace floormat { + +floormat::detail::corrade_debug::ErrorString error_string(int error) { return { error }; } + +} // namespace floormat diff --git a/compat/debug.hpp b/compat/debug.hpp index 1d8e4676..0009ce52 100644 --- a/compat/debug.hpp +++ b/compat/debug.hpp @@ -1,26 +1,31 @@ #pragma once #include #include +#include namespace floormat::detail::corrade_debug { -template struct Quoted final { const T& value; }; - -#ifndef FM_NO_CORRADE_DEBUG_EXTERN_TEMPLATE_QUOTED -extern template struct Quoted; -#endif +struct ErrorString final { int value; }; +Debug& operator<<(Debug& dbg, ErrorString box); -Debug::Flags debug1(Debug& dbg); -Debug& debug2(Debug& dbg, Debug::Flags flags); +template struct Quoted final { const T& value; }; +Debug::Flags debug1(Debug& dbg, char c); +Debug& debug2(Debug& dbg, Debug::Flags flags, char c); -template -Debug& operator<<(Debug& dbg, detail::corrade_debug::Quoted box) +template Debug& operator<<(Debug& dbg, Quoted box) { - Debug::Flags flags = detail::corrade_debug::debug1(dbg); + Debug::Flags flags = debug1(dbg, '\''); dbg << box.value; - return debug2(dbg, flags); + return debug2(dbg, flags, '\''); } +extern template struct Quoted; + } // namespace floormat::detail::corrade_debug +namespace floormat { + +floormat::detail::corrade_debug::ErrorString error_string(int error); template floormat::detail::corrade_debug::Quoted quoted(const T& value) { return { value }; } + +} // namespace floormat -- cgit v1.2.3