From d6b69ca8fc7357c25c09f87a29a9ac427869ecbf Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 16 Jan 2023 01:08:02 -0800 Subject: [PATCH] move useful functions from uicommon to MiscUtils --- library/include/MiscUtils.h | 31 ++++++++++++++++++++++++++----- plugins/uicommon.h | 18 ------------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h index d089640ef..124987535 100644 --- a/library/include/MiscUtils.h +++ b/library/include/MiscUtils.h @@ -23,17 +23,20 @@ distribution. */ #pragma once + #include "Export.h" + #include -#include -#include #include #include -#include -#include -#include #include +#include +#include +#include #include +#include +#include +#include #if defined(_MSC_VER) #define DFHACK_FUNCTION_SIG __FUNCSIG__ @@ -338,6 +341,24 @@ inline typename T::mapped_type map_find( return (it == map.end()) ? defval : it->second; } +template +static void for_each_(std::vector &v, Fn func) +{ + std::for_each(v.begin(), v.end(), func); +} + +template +static void for_each_(std::map &v, Fn func) +{ + std::for_each(v.begin(), v.end(), func); +} + +template +static void transform_(const std::vector &src, std::vector &dst, Fn func) +{ + std::transform(src.begin(), src.end(), std::back_inserter(dst), func); +} + DFHACK_EXPORT bool prefix_matches(const std::string &prefix, const std::string &key, std::string *tail = NULL); template diff --git a/plugins/uicommon.h b/plugins/uicommon.h index 03914b461..6179324d4 100644 --- a/plugins/uicommon.h +++ b/plugins/uicommon.h @@ -65,24 +65,6 @@ struct coord32_t } }; -template -static void for_each_(vector &v, Fn func) -{ - for_each(v.begin(), v.end(), func); -} - -template -static void for_each_(map &v, Fn func) -{ - for_each(v.begin(), v.end(), func); -} - -template -static void transform_(const vector &src, vector &dst, Fn func) -{ - transform(src.begin(), src.end(), back_inserter(dst), func); -} - typedef int8_t UIColor; static inline void OutputString(UIColor color, int &x, int &y, const std::string &text,