From 7b36b8484abd90e92b7750230c162255a969c7b9 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Fri, 6 Sep 2024 14:42:16 +0200 Subject: [PATCH] Don't include fmt.h in text_types.h --- gframe/Android/COSAndroidOperator.cpp | 1 + gframe/CGUISkinSystem/CGUISkinSystem.cpp | 9 ++++---- gframe/CGUITTFont/CGUITTFont.cpp | 1 + gframe/address.cpp | 13 ++++++------ gframe/address.h | 23 ++++---------------- gframe/bufferio.h | 1 + gframe/client_card.cpp | 1 + gframe/client_field.cpp | 1 + gframe/client_updater.cpp | 1 + gframe/data_handler.cpp | 1 + gframe/data_manager.cpp | 1 + gframe/deck_con.cpp | 1 + gframe/deck_manager.cpp | 1 + gframe/discord_wrapper.cpp | 1 + gframe/dllinterface.cpp | 1 + gframe/drawing.cpp | 1 + gframe/duelclient.cpp | 1 + gframe/event_handler.cpp | 1 + gframe/fmt.h | 27 +++++++++++++++++++++++- gframe/game.cpp | 1 + gframe/game_config.cpp | 1 + gframe/gframe.cpp | 1 + gframe/iOS/COSiOSOperator.mm | 2 +- gframe/image_downloader.cpp | 1 + gframe/image_manager.cpp | 1 + gframe/logging.cpp | 1 + gframe/logging.h | 1 + gframe/menu_handler.cpp | 1 + gframe/old_replay_mode.cpp | 1 + gframe/replay.cpp | 1 + gframe/repo_cloner.cpp | 1 + gframe/repo_manager.cpp | 1 + gframe/server_lobby.cpp | 1 + gframe/single_mode.cpp | 3 ++- gframe/sound_manager.cpp | 1 + gframe/sound_sdlmixer.cpp | 1 + gframe/text_types.h | 14 ++++++------ gframe/utils.cpp | 1 + gframe/utils_gui.cpp | 1 + gframe/windbot_panel.cpp | 1 + 40 files changed, 85 insertions(+), 39 deletions(-) diff --git a/gframe/Android/COSAndroidOperator.cpp b/gframe/Android/COSAndroidOperator.cpp index 21221c025..4dacf5783 100644 --- a/gframe/Android/COSAndroidOperator.cpp +++ b/gframe/Android/COSAndroidOperator.cpp @@ -20,6 +20,7 @@ static inline int android_get_device_api_level() { #endif #include "COSAndroidOperator.h" #include "porting_android.h" +#include "../fmt.h" namespace irr { diff --git a/gframe/CGUISkinSystem/CGUISkinSystem.cpp b/gframe/CGUISkinSystem/CGUISkinSystem.cpp index 6037671c6..fd08575b7 100644 --- a/gframe/CGUISkinSystem/CGUISkinSystem.cpp +++ b/gframe/CGUISkinSystem/CGUISkinSystem.cpp @@ -8,6 +8,7 @@ #include #include #include "../utils.h" +#include "../fmt.h" using namespace irr; @@ -119,7 +120,7 @@ gui::CImageGUISkin* CGUISkinSystem::loadSkinFromFile(const fschar_t *skinname) { // is to make the registry write out the root node and see what comes out. //registry->writeFile("Skin","."); - // To switch on the fly, we have to set the skin to the fallback skin first + // To switch on the fly, we have to set the skin to the fallback skin first tmp = registry->getValueAsCStr(L"skin", L"Skin/Properties/Fallback"); // Always default to metalic fallbackType = gui::EGST_WINDOWS_METALLIC; @@ -156,7 +157,7 @@ gui::CImageGUISkin* CGUISkinSystem::loadSkinFromFile(const fschar_t *skinname) { skinConfig.CheckBoxColor = registry->getValueAsColor(L"Skin/Global/CheckBoxColor"); // If there was no progress bar colors set, set them in the config to the defaults - // otherwise their 0,0,0,0. This is neccicary for the old klagui. + // otherwise their 0,0,0,0. This is neccicary for the old klagui. if(skinConfig.ProgressBarFilled.Color == 0) skinConfig.ProgressBarFilled.Color = video::SColor(255, 255, 0, 0); @@ -380,10 +381,10 @@ bool CGUISkinSystem::applySkin(const fschar_t *skinname) { } device->getGUIEnvironment()->setSkin(skin); loaded_skin = skin; - // If we're going to switch skin we need to find all the progress bars and overwrite their colors + // If we're going to switch skin we need to find all the progress bars and overwrite their colors skin->drop(); registry = nullptr; //fs->changeWorkingDirectoryTo(oldpath); return true; -} \ No newline at end of file +} diff --git a/gframe/CGUITTFont/CGUITTFont.cpp b/gframe/CGUITTFont/CGUITTFont.cpp index 1b6205035..aa8ac7a52 100644 --- a/gframe/CGUITTFont/CGUITTFont.cpp +++ b/gframe/CGUITTFont/CGUITTFont.cpp @@ -40,6 +40,7 @@ #include #include #include +#include "../fmt.h" #ifdef YGOPRO_USE_BUNDLED_FONT extern const char* bundled_font_name; extern const size_t bundled_font_len; diff --git a/gframe/address.cpp b/gframe/address.cpp index d7a0ec483..ba93ac294 100644 --- a/gframe/address.cpp +++ b/gframe/address.cpp @@ -2,6 +2,7 @@ #include "address.h" #include "bufferio.h" #include "config.h" +#include "fmt.h" #if EDOPRO_ANDROID #include #endif @@ -42,19 +43,17 @@ void Address::toIn6Addr(in6_addr& sin6_addr) const { memcpy(sin6_addr.s6_addr, buffer, sizeof(in6_addr::s6_addr)); } -template<> -std::basic_string Address::format() const { - if(family == UNK) +std::string format_address(const Address& address) { + if(address.family == address.UNK) return ""; char ret[50]{}; - if(evutil_inet_ntop(family == INET ? AF_INET : AF_INET6, buffer, ret, sizeof(ret)) == nullptr) + if(evutil_inet_ntop(address.family == address.INET ? AF_INET : AF_INET6, address.buffer, ret, sizeof(ret)) == nullptr) return ""; return ret; } -template<> -std::basic_string Address::format() const { - return BufferIO::DecodeUTF8(format()); +std::wstring wformat_address(const Address& address) { + return BufferIO::DecodeUTF8(format_address(address)); } bool Host::operator==(const Host& other) const { diff --git a/gframe/address.h b/gframe/address.h index 138f703aa..b81cd691e 100644 --- a/gframe/address.h +++ b/gframe/address.h @@ -3,7 +3,6 @@ #include #include -#include "fmt.h" #include "bufferio.h" #include "text_types.h" @@ -16,6 +15,7 @@ namespace epro { struct Address { friend struct Host; + friend std::string format_address(const Address& address); private: uint8_t buffer[32]{}; //buffer big enough to store an ipv6 public: @@ -30,8 +30,6 @@ struct Address { AF family; void setIP4(const uint32_t* ip); void setIP6(const void* ip); - template - std::basic_string format() const; void toInAddr(in_addr& sin_addr) const; void toIn6Addr(in6_addr& sin6_addr) const; }; @@ -46,22 +44,9 @@ struct Host { static Host resolve(epro::stringview address, uint16_t port); }; -template<> -std::basic_string Address::format() const; -template<> -std::basic_string Address::format() const; -} - -template -struct fmt::formatter { - template - constexpr auto parse(ParseContext& ctx) const { return ctx.begin(); } +std::string format_address(const Address&); +std::wstring wformat_address(const Address&); - template - auto format(const epro::Address& address, FormatContext& ctx) const { - static constexpr auto format_str = CHAR_T_STRINGVIEW(T, "{}"); - return format_to(ctx.out(), format_str, address.format()); - } -}; +} #endif //ADDRESS_H diff --git a/gframe/bufferio.h b/gframe/bufferio.h index ed708d36e..3b4ac8c2a 100644 --- a/gframe/bufferio.h +++ b/gframe/bufferio.h @@ -1,6 +1,7 @@ #ifndef BUFFERIO_H #define BUFFERIO_H +#include #include #include #include diff --git a/gframe/client_card.cpp b/gframe/client_card.cpp index 3a314cc6f..25b69f71b 100644 --- a/gframe/client_card.cpp +++ b/gframe/client_card.cpp @@ -2,6 +2,7 @@ #include "data_manager.h" #include "common.h" #include "client_card.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/client_field.cpp b/gframe/client_field.cpp index cc239157d..37d08ebeb 100644 --- a/gframe/client_field.cpp +++ b/gframe/client_field.cpp @@ -21,6 +21,7 @@ #include "CGUIImageButton/CGUIImageButton.h" #include "CGUITTFont/CGUITTFont.h" #include "custom_skin_enum.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/client_updater.cpp b/gframe/client_updater.cpp index 75b273775..df460b0f7 100644 --- a/gframe/client_updater.cpp +++ b/gframe/client_updater.cpp @@ -20,6 +20,7 @@ #include "utils.h" #include "porting.h" #include "game_config.h" +#include "fmt.h" #define LOCKFILE EPRO_TEXT("./.edopro_lock") #define UPDATES_FOLDER EPRO_TEXT("./updates/{}") diff --git a/gframe/data_handler.cpp b/gframe/data_handler.cpp index 89a95f028..1dbbf4a7c 100644 --- a/gframe/data_handler.cpp +++ b/gframe/data_handler.cpp @@ -6,6 +6,7 @@ #include "utils_gui.h" #include "deck_manager.h" #include "logging.h" +#include "fmt.h" #include "utils.h" #include "windbot.h" #include "windbot_panel.h" diff --git a/gframe/data_manager.cpp b/gframe/data_manager.cpp index c382efeab..da8b95507 100644 --- a/gframe/data_manager.cpp +++ b/gframe/data_manager.cpp @@ -8,6 +8,7 @@ #include "utils.h" #include "common.h" #include "file_stream.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/deck_con.cpp b/gframe/deck_con.cpp index c0e4eb1de..efc53f24b 100644 --- a/gframe/deck_con.cpp +++ b/gframe/deck_con.cpp @@ -13,6 +13,7 @@ #include "duelclient.h" #include "single_mode.h" #include "client_card.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/deck_manager.cpp b/gframe/deck_manager.cpp index d835dcb2e..9b7f5beaa 100644 --- a/gframe/deck_manager.cpp +++ b/gframe/deck_manager.cpp @@ -9,6 +9,7 @@ #include "utils.h" #include "client_card.h" #include "file_stream.h" +#include "fmt.h" namespace ygo { const CardDataC* DeckManager::GetDummyOrMappedCardData(uint32_t code) const { diff --git a/gframe/discord_wrapper.cpp b/gframe/discord_wrapper.cpp index 2bc94b67f..7dae85d33 100644 --- a/gframe/discord_wrapper.cpp +++ b/gframe/discord_wrapper.cpp @@ -15,6 +15,7 @@ #include "logging.h" #include "config.h" #include "server_lobby.h" +#include "fmt.h" #endif #include "text_types.h" #include "discord_wrapper.h" diff --git a/gframe/dllinterface.cpp b/gframe/dllinterface.cpp index f8fb6357c..3ca8d6983 100644 --- a/gframe/dllinterface.cpp +++ b/gframe/dllinterface.cpp @@ -11,6 +11,7 @@ #include "config.h" #include "dllinterface.h" #include "utils.h" +#include "fmt.h" #if EDOPRO_WINDOWS #define CORENAME EPRO_TEXT("ocgcore.dll") diff --git a/gframe/drawing.cpp b/gframe/drawing.cpp index 97fcba5f7..356e0dddd 100644 --- a/gframe/drawing.cpp +++ b/gframe/drawing.cpp @@ -9,6 +9,7 @@ #include "CGUIImageButton/CGUIImageButton.h" #include "custom_skin_enum.h" #include "image_manager.h" +#include "fmt.h" namespace ygo { void Game::DrawSelectionLine(const Materials::QuadVertex vec, bool strip, int width, irr::video::SColor color) { diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index 6a77638f8..d63134e3b 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -28,6 +28,7 @@ #include "progressivebuffer.h" #include "utils.h" #include "porting.h" +#include "fmt.h" #define DEFAULT_DUEL_RULE 5 namespace ygo { diff --git a/gframe/event_handler.cpp b/gframe/event_handler.cpp index c24673e3e..e12bf8723 100644 --- a/gframe/event_handler.cpp +++ b/gframe/event_handler.cpp @@ -38,6 +38,7 @@ #include "joystick_wrapper.h" #include "porting.h" #include "config.h" +#include "fmt.h" namespace { diff --git a/gframe/fmt.h b/gframe/fmt.h index e3bf6bd59..4581568e8 100644 --- a/gframe/fmt.h +++ b/gframe/fmt.h @@ -29,7 +29,32 @@ struct fmt::formatter, CharT> { constexpr auto parse(ParseContext& ctx) { return ctx.begin(); } template constexpr auto format(const irr::core::string& s, ParseContext& ctx) const { - return format_to(ctx.out(), fmt::basic_string_view{s.data(), s.size()}); + return format_to(ctx.out(), basic_string_view{s.data(), s.size()}); + } +}; + +namespace epro { +struct Address; +std::string format_address(const Address&); +std::wstring wformat_address(const Address&); +} + +template +struct fmt::formatter { + template + constexpr auto parse(ParseContext& ctx) const { return ctx.begin(); } + + template + auto format(const epro::Address& address, FormatContext& ctx) const { + static constexpr auto format_str = CHAR_T_STRINGVIEW(T, "{}"); + const auto formatted = [&] { + if constexpr(std::is_same_v) { + return wformat_address(address); + } else { + return format_address(address); + } + }(); + return format_to(ctx.out(), format_str, formatted); } }; diff --git a/gframe/game.cpp b/gframe/game.cpp index 8b3d60044..a0c65b5d2 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -38,6 +38,7 @@ #include "CGUIWindowedTabControl/CGUIWindowedTabControl.h" #include "file_stream.h" #include "porting.h" +#include "fmt.h" #if EDOPRO_ANDROID || EDOPRO_IOS #include "CGUICustomComboBox/CGUICustomComboBox.h" diff --git a/gframe/game_config.cpp b/gframe/game_config.cpp index bb72a0e68..5b892d141 100644 --- a/gframe/game_config.cpp +++ b/gframe/game_config.cpp @@ -7,6 +7,7 @@ #include "config.h" #include "logging.h" #include "file_stream.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index 369ed624d..f315336f3 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -17,6 +17,7 @@ #include "log.h" #include "joystick_wrapper.h" #include "utils_gui.h" +#include "fmt.h" #if EDOPRO_MACOS #include "osx_menu.h" #endif diff --git a/gframe/iOS/COSiOSOperator.mm b/gframe/iOS/COSiOSOperator.mm index 2c2722760..d3ad437da 100644 --- a/gframe/iOS/COSiOSOperator.mm +++ b/gframe/iOS/COSiOSOperator.mm @@ -2,9 +2,9 @@ #import #include -#include #include "../bufferio.h" #include "../text_types.h" +#include "../fmt.h" #include "COSiOSOperator.h" namespace irr { diff --git a/gframe/image_downloader.cpp b/gframe/image_downloader.cpp index 11d889403..88ca41709 100644 --- a/gframe/image_downloader.cpp +++ b/gframe/image_downloader.cpp @@ -6,6 +6,7 @@ #include "utils.h" #include "game_config.h" #include "file_stream.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/image_manager.cpp b/gframe/image_manager.cpp index bb8fcc5b1..718a9d1d1 100644 --- a/gframe/image_manager.cpp +++ b/gframe/image_manager.cpp @@ -10,6 +10,7 @@ #include "image_downloader.h" #include "game.h" #include "config.h" +#include "fmt.h" #define BASE_PATH EPRO_TEXT("./textures/") diff --git a/gframe/logging.cpp b/gframe/logging.cpp index 205372456..23d6fe0e1 100644 --- a/gframe/logging.cpp +++ b/gframe/logging.cpp @@ -1,5 +1,6 @@ #include "logging.h" #include +#include "fmt.h" #include "file_stream.h" namespace ygo { diff --git a/gframe/logging.h b/gframe/logging.h index a76107ba5..4f4f6a810 100644 --- a/gframe/logging.h +++ b/gframe/logging.h @@ -2,6 +2,7 @@ #define LOGGING_H #include "text_types.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/menu_handler.cpp b/gframe/menu_handler.cpp index a86f09b16..4bd595e07 100644 --- a/gframe/menu_handler.cpp +++ b/gframe/menu_handler.cpp @@ -26,6 +26,7 @@ #include #include #include "address.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/old_replay_mode.cpp b/gframe/old_replay_mode.cpp index 3b6ee650f..cdf8ccca4 100644 --- a/gframe/old_replay_mode.cpp +++ b/gframe/old_replay_mode.cpp @@ -3,6 +3,7 @@ #include "duelclient.h" #include "game.h" #include "single_mode.h" +#include "fmt.h" namespace ygo { bool ReplayMode::ReadReplayResponse() { diff --git a/gframe/replay.cpp b/gframe/replay.cpp index 31ad9d0a0..9ebb2a207 100644 --- a/gframe/replay.cpp +++ b/gframe/replay.cpp @@ -4,6 +4,7 @@ #include "common.h" #include "utils.h" #include "file_stream.h" +#include "fmt.h" namespace ygo { void Replay::BeginRecord(bool write, epro::path_string name) { diff --git a/gframe/repo_cloner.cpp b/gframe/repo_cloner.cpp index 9e5758744..8dc1b1ec3 100644 --- a/gframe/repo_cloner.cpp +++ b/gframe/repo_cloner.cpp @@ -1,6 +1,7 @@ #include "repo_cloner.h" #include "config.h" +#include "fmt.h" #include "game_config.h" #include "porting.h" #include "repo_manager.h" diff --git a/gframe/repo_manager.cpp b/gframe/repo_manager.cpp index 77a3100e8..fe0c40996 100644 --- a/gframe/repo_manager.cpp +++ b/gframe/repo_manager.cpp @@ -8,6 +8,7 @@ #include "logging.h" #include "utils.h" #include "libgit2.hpp" +#include "fmt.h" static constexpr int MAX_HISTORY_LENGTH = 100; static constexpr int FETCH_OBJECTS_PERCENTAGE = 60; diff --git a/gframe/server_lobby.cpp b/gframe/server_lobby.cpp index 566c27d56..798d54cf2 100644 --- a/gframe/server_lobby.cpp +++ b/gframe/server_lobby.cpp @@ -17,6 +17,7 @@ #include "custom_skin_enum.h" #include "game_config.h" #include "address.h" +#include "fmt.h" namespace ygo { diff --git a/gframe/single_mode.cpp b/gframe/single_mode.cpp index 997b63173..b06ba0c14 100644 --- a/gframe/single_mode.cpp +++ b/gframe/single_mode.cpp @@ -4,6 +4,7 @@ #include "game.h" #include "core_utils.h" #include "sound_manager.h" +#include "fmt.h" #include "CGUIFileSelectListBox/CGUIFileSelectListBox.h" #include #include @@ -381,7 +382,7 @@ bool SingleMode::SinglePlayAnalyze(CoreUtils::Packet& packet) { case 203: { analyze = true; break; - + } } if(analyze) diff --git a/gframe/sound_manager.cpp b/gframe/sound_manager.cpp index 7e8dee924..28df29be3 100644 --- a/gframe/sound_manager.cpp +++ b/gframe/sound_manager.cpp @@ -2,6 +2,7 @@ #include "sound_manager.h" #include "utils.h" #include "config.h" +#include "fmt.h" #if defined(YGOPRO_USE_IRRKLANG) #include "sound_irrklang.h" #define BACKEND SoundIrrklang diff --git a/gframe/sound_sdlmixer.cpp b/gframe/sound_sdlmixer.cpp index 55ae5b869..8cb631f4c 100644 --- a/gframe/sound_sdlmixer.cpp +++ b/gframe/sound_sdlmixer.cpp @@ -1,5 +1,6 @@ #ifdef YGOPRO_USE_SDL_MIXER #include "sound_sdlmixer.h" +#include "fmt.h" #define SDL_MAIN_HANDLED #include #include diff --git a/gframe/text_types.h b/gframe/text_types.h index 1a1a34f0b..4c4dfbe6e 100644 --- a/gframe/text_types.h +++ b/gframe/text_types.h @@ -1,7 +1,7 @@ #ifndef TEXT_TYPES_H_ #define TEXT_TYPES_H_ #include -#include "fmt.h" +#include // Double macro to convert the macro-defined int to a character literal #define STR_HELPER(x) #x @@ -22,11 +22,13 @@ using wstringview = basic_string_view; namespace Detail { template -constexpr epro::basic_string_view CHAR_T_STRINGVIEW(epro::stringview, epro::wstringview); -template<> -constexpr epro::stringview CHAR_T_STRINGVIEW(epro::stringview string, epro::wstringview) { return string; } -template<> -constexpr epro::wstringview CHAR_T_STRINGVIEW(epro::stringview, epro::wstringview string) { return string; } +static constexpr inline epro::basic_string_view CHAR_T_STRINGVIEW(epro::stringview stringview, epro::wstringview wstringview) { + if constexpr(std::is_same_v) { + return wstringview; + } else { + return stringview; + } +} } #define CHAR_T_STRINGVIEW(Char, text) epro::Detail::CHAR_T_STRINGVIEW(text ""sv, L"" text ""sv) diff --git a/gframe/utils.cpp b/gframe/utils.cpp index 535a18abe..4236d1e89 100644 --- a/gframe/utils.cpp +++ b/gframe/utils.cpp @@ -2,6 +2,7 @@ #include // std::round #include "epro_thread.h" #include "config.h" +#include "fmt.h" #if EDOPRO_WINDOWS #define WIN32_LEAN_AND_MEAN diff --git a/gframe/utils_gui.cpp b/gframe/utils_gui.cpp index d283108d6..40bdf5a40 100644 --- a/gframe/utils_gui.cpp +++ b/gframe/utils_gui.cpp @@ -6,6 +6,7 @@ #include "game_config.h" #include "text_types.h" #include "porting.h" +#include "fmt.h" #if EDOPRO_WINDOWS #define WIN32_LEAN_AND_MEAN #include diff --git a/gframe/windbot_panel.cpp b/gframe/windbot_panel.cpp index de08542fa..860d893eb 100644 --- a/gframe/windbot_panel.cpp +++ b/gframe/windbot_panel.cpp @@ -4,6 +4,7 @@ #include #include "config.h" #include "data_manager.h" +#include "fmt.h" namespace ygo {