#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_ #define FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_ #include #include #include #include #include #include #include #include "strconv.h" namespace flutter_inappwebview_plugin { template struct is_vector_impl : std::false_type { }; template struct is_mappish_impl : std::false_type { }; template struct is_vector_impl>::value> > : std::true_type { }; template struct is_vector_impl::value_type>::iterator>::value> > : std::true_type { }; template struct is_mappish_impl()[std::declval()])>> : std::true_type { }; template struct is_mappish : is_mappish_impl::type { }; template struct is_vector : is_vector_impl::type { }; static inline void debugLog(const std::string& msg) { #ifndef NDEBUG std::cout << msg << std::endl; OutputDebugString(ansi_to_wide(msg + "\n").c_str()); #endif } static inline std::string getErrorMessage(const HRESULT& error) { _com_error err(error); return wide_to_ansi(err.ErrorMessage()); } template static inline std::optional make_pointer_optional(const T* value) { return value == nullptr ? std::nullopt : std::make_optional(*value); } static inline std::string variant_to_string(const std::variant& var) { return std::visit([](auto&& arg) { using T = std::decay_t; if constexpr (std::is_same_v) return arg; else if constexpr (std::is_arithmetic_v) return std::to_string(arg); else static_assert(always_false_v, "non-exhaustive visitor!"); }, var); } template static inline bool map_contains(const std::map& map, const K& key) { return map.find(key) != map.end(); } template static inline T map_at_or_null(const std::map& map, const K& key) { auto itr = map.find(key); return itr != map.end() ? itr->second : nullptr; } template static inline auto functional_map(Iterator begin, Iterator end, Func&& func) -> std::vector()))> { using value_type = decltype(func(std::declval())); std::vector out_vector; out_vector.reserve(std::distance(begin, end)); std::transform(begin, end, std::back_inserter(out_vector), std::forward(func)); return out_vector; } template static inline auto functional_map(const T& iterable, Func&& func) -> std::vector()))> { return functional_map(std::begin(iterable), std::end(iterable), std::forward(func)); } template static inline auto functional_map(const std::optional& iterable, Func&& func) -> std::vector()))> { if (!iterable.has_value()) { return {}; } return functional_map(iterable.value(), std::forward(func)); } } #endif //FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_H_