MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Yaml.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14#include "CoreMinimal.h"
15#include "Mcro/Text.h"
16
18#include "PreMagicEnum.h"
19#include "magic_enum.hpp"
20#include "yaml-cpp/yaml.h"
22
23namespace Mcro::Yaml
24{
25 using namespace Mcro::Text;
26
27 /**
28 * RAII friendly region annotation for YAML::Emitter streams
29 * @tparam Begin The YAML region begin tag
30 * @tparam End The YAML region end tag
31 */
32 template <YAML::EMITTER_MANIP Begin, YAML::EMITTER_MANIP End>
34 {
35 YAML::Emitter& Out;
36
37 public:
38 TScopedRegion(YAML::Emitter& out) : Out(out) { Out << Begin; }
39 ~TScopedRegion() { Out << End; }
40
41 template <typename T>
43 {
44 Out << Forward<T>(rhs);
45 return *this;
46 }
47 };
48
49 /** Annotate a mapping region in a YAML::Emitter stream, which ends when this object goes out of scope */
51
52 /** Annotate a sequence region in a YAML::Emitter stream, which ends when this object goes out of scope */
54
55 /** Convenience operator to append Unreal or potentially wide strings to YAML::Emitter streams */
56 template <typename String>
57 requires (CStringOrViewOrName<String> || CStdStringOrView<String>)
58 YAML::Emitter& operator << (YAML::Emitter& out, String&& v)
59 {
60 out << StdConvertUtf8(Forward<String>(v));
61 return out;
62 }
63
64 /** Convenience operator to append enums as strings to a YAML::Emitter streams */
65 template <CEnum Enum>
66 YAML::Emitter& operator << (YAML::Emitter& out, Enum v)
67 {
68 out << StdConvertUtf8(magic_enum::enum_name(v));
69 return out;
70 }
71}
TScopedRegion & operator<<(T &&rhs)
Definition Yaml.h:42
TScopedRegion(YAML::Emitter &out)
Definition Yaml.h:38
MCRO_API std::string StdConvertUtf8(FStringView const &unrealStr)
YAML::Emitter & operator<<(YAML::Emitter &out, String &&v)
Definition Yaml.h:58