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 * @brief 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 << FWD(rhs);
45 return *this;
46 }
47 };
48
49 /** @brief Annotate a mapping region in a YAML::Emitter stream, which ends when this object goes out of scope */
51
52 /** @brief Annotate a sequence region in a YAML::Emitter stream, which ends when this object goes out of scope */
54
55 /** @brief 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 << StdConvert<ANSICHAR>(FWD(v));
61 return out;
62 }
63
64 /** @brief 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 << StdConvert<ANSICHAR>(magic_enum::enum_name(v));
69 return out;
70 }
71}
Use this header and Start.h in tandem to include third-party library headers which may not tolerate U...
#define FWD(...)
Shorten forwarding expression with this macro so one may not need to specify explicit type.
Definition Macros.h:100
Use this header and End.h in tandem to include third-party library headers which may not tolerate Unr...
RAII friendly region annotation for YAML::Emitter streams.
Definition Yaml.h:34
TScopedRegion & operator<<(T &&rhs)
Definition Yaml.h:42
TScopedRegion(YAML::Emitter &out)
Definition Yaml.h:38
Mixed text utilities and type traits.
Definition Enums.h:51
TTuple< Rest..., T > operator<<(TTuple< Rest... > const &left, T &&right)
Append a value to a tuple.
Definition Tuples.h:241