17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-19 02:39:19 +02:00
Files
maszyna/betterRenderer/mashadercompiler/src/utils.hpp
maj00r 26501b0fd7 hoist standard includes above everything else
Ordering them before the imports in the same file was not enough: a
project header on line 1 can import a module several levels down whose
global module fragment already pulled in the same standard header, and
that include guard does not cross the module boundary. Putting them
first means the guard is set before anything can import.

Skips vendored single-header libraries and anything inside an #if.
2026-09-10 01:02:17 +02:00

33 lines
1003 B
C++

#pragma once
#include <cstdint>
#include <string>
#include <yaml-cpp/yaml.h>
inline std::wstring ToWide(const std::string& str) {
std::wstring wstr{};
wstr.resize(std::mbstowcs(nullptr, str.c_str(), static_cast<uint64_t>(-1)));
std::mbstowcs(wstr.data(), str.c_str(), wstr.size());
return wstr;
}
inline std::string ToNarrow(const std::wstring& wstr) {
std::string str{};
str.resize(std::wcstombs(nullptr, wstr.c_str(), static_cast<uint64_t>(-1)));
std::wcstombs(str.data(), wstr.c_str(), str.size());
return str;
}
template <typename KeyType>
YAML::Node TemplateOverride(const KeyType& key, const YAML::Node& container,
const YAML::Node& templates) {
YAML::Node local = container[key];
YAML::Node use_template = container["use_template"];
if (!local.IsDefined() && use_template.IsDefined() &&
templates[use_template.as<std::string_view>()].IsDefined()) {
return templates[use_template.as<std::string_view>()][key];
}
return local;
}