iosWebViewFix/flutter_inappwebview_windows/windows/utils/util.h

57 lines
1.4 KiB
C
Raw Normal View History

2024-01-06 03:51:16 +00:00
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_
#define FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_
2024-01-08 11:36:48 +00:00
#include <algorithm>
#include <iostream>
2024-01-08 11:36:48 +00:00
#include <map>
2024-01-06 03:51:16 +00:00
#include <optional>
2024-01-08 11:36:48 +00:00
#include <string>
#include <variant>
#include "strconv.h"
2024-01-06 03:51:16 +00:00
namespace flutter_inappwebview_plugin
{
2024-01-08 11:36:48 +00:00
static inline void debugLog(const std::string& msg)
{
#ifndef NDEBUG
2024-01-08 11:36:48 +00:00
std::cout << msg << std::endl;
OutputDebugString(ansi_to_wide(msg + "\n").c_str());
#endif
2024-01-08 11:36:48 +00:00
}
template<typename T>
static inline std::optional<T> make_pointer_optional(const T* value)
{
return value == nullptr ? std::nullopt : std::make_optional<T>(*value);
}
static inline std::string variant_to_string(const std::variant<std::string, int>& var)
{
return std::visit([](auto&& arg)
{
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, std::string>)
return arg;
else if constexpr (std::is_arithmetic_v<T>)
return std::to_string(arg);
else
static_assert(always_false_v<T>, "non-exhaustive visitor!");
}, var);
}
template<typename K, typename T>
static inline bool map_contains(const std::map<K, T>& map, const K& key)
{
return map.find(key) != map.end();
}
template<typename K, typename T>
static inline T map_at_or_null(const std::map<K, T>& map, const K& key)
{
auto itr = map.find(key);
return itr != map.end() ? itr->second : nullptr;
}
2024-01-06 03:51:16 +00:00
}
#endif //FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_