move useful functions from uicommon to MiscUtils

develop
Myk Taylor 2023-01-16 01:08:02 -08:00
parent bb3f640afa
commit d6b69ca8fc
No known key found for this signature in database
2 changed files with 26 additions and 23 deletions

@ -23,17 +23,20 @@ distribution.
*/ */
#pragma once #pragma once
#include "Export.h" #include "Export.h"
#include <algorithm> #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cctype> #include <cctype>
#include <climits> #include <climits>
#include <stdint.h>
#include <vector>
#include <sstream>
#include <cstdio> #include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory> #include <memory>
#include <sstream>
#include <stdint.h>
#include <vector>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define DFHACK_FUNCTION_SIG __FUNCSIG__ #define DFHACK_FUNCTION_SIG __FUNCSIG__
@ -338,6 +341,24 @@ inline typename T::mapped_type map_find(
return (it == map.end()) ? defval : it->second; return (it == map.end()) ? defval : it->second;
} }
template <class T, typename Fn>
static void for_each_(std::vector<T> &v, Fn func)
{
std::for_each(v.begin(), v.end(), func);
}
template <class T, class V, typename Fn>
static void for_each_(std::map<T, V> &v, Fn func)
{
std::for_each(v.begin(), v.end(), func);
}
template <class T, class V, typename Fn>
static void transform_(const std::vector<T> &src, std::vector<V> &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); DFHACK_EXPORT bool prefix_matches(const std::string &prefix, const std::string &key, std::string *tail = NULL);
template<typename T> template<typename T>

@ -65,24 +65,6 @@ struct coord32_t
} }
}; };
template <class T, typename Fn>
static void for_each_(vector<T> &v, Fn func)
{
for_each(v.begin(), v.end(), func);
}
template <class T, class V, typename Fn>
static void for_each_(map<T, V> &v, Fn func)
{
for_each(v.begin(), v.end(), func);
}
template <class T, class V, typename Fn>
static void transform_(const vector<T> &src, vector<V> &dst, Fn func)
{
transform(src.begin(), src.end(), back_inserter(dst), func);
}
typedef int8_t UIColor; typedef int8_t UIColor;
static inline void OutputString(UIColor color, int &x, int &y, const std::string &text, static inline void OutputString(UIColor color, int &x, int &y, const std::string &text,