MCRO
C++23 utilities for Unreal Engine.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
Enums.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "CoreMinimal.h"
5#include "Mcro/Concepts.h"
6#include "Mcro/Text.h"
7
9#include "PreMagicEnum.h"
10#include "magic_enum.hpp"
12
13/** @brief Contains utilities for handling enums as strings or vice-versa */
14namespace Mcro::Enums
15{
16 using namespace Mcro::Concepts;
17 using namespace Mcro::Text;
18
19 template <CEnum Enum>
20 FString EnumToStringCopy(Enum input)
21 {
22 return UnrealCopy(magic_enum::enum_name(input));
23 }
24
25 template <CEnum Enum>
26 FStringView EnumToStringView(Enum input)
27 {
28 return UnrealView(magic_enum::enum_name(input));
29 }
30
31 template <CEnum Enum>
32 FName EnumToName(Enum input)
33 {
34 return UnrealNameCopy(magic_enum::enum_name(input));
35 }
36
37 template <CEnum Enum, CStringOrView String>
38 Enum StringToEnum(String const& input)
39 {
40 return magic_enum::enum_cast<Enum>(StdView(input));
41 }
42
43 template <CEnum Enum>
44 Enum NameToEnum(FName const& input)
45 {
46 return magic_enum::enum_cast<Enum>(StdCopy(input));
47 }
48}
49
50namespace Mcro::Text
51{
52 template <CEnum Operand>
53 struct TAsFormatArgument<Operand>
54 {
55 FStringView operator () (Operand left) const
56 {
58 }
59 };
60}
This header exists because STL headers in Android doesn't define STL concepts (other than same_as whi...
Use this header and Start.h in tandem to include third-party library headers which may not tolerate U...
Use this header and End.h in tandem to include third-party library headers which may not tolerate Unr...
Contains utilities for handling enums as strings or vice-versa.
Definition Enums.h:15
FName EnumToName(Enum input)
Definition Enums.h:32
FStringView EnumToStringView(Enum input)
Definition Enums.h:26
FString EnumToStringCopy(Enum input)
Definition Enums.h:20
Enum NameToEnum(FName const &input)
Definition Enums.h:44
Enum StringToEnum(String const &input)
Definition Enums.h:38
Mixed text utilities and type traits.
Definition Enums.h:51
constexpr auto UnrealView(TStdStringView< CharType > const &stdStr)
View an STL string object via an Unreal TStringView
Definition Text.h:164
MCRO_API FName UnrealNameCopy(FStdStringView const &stdStr)
Create a copy of an input STL string as an FName.
constexpr auto StdView(T const &unrealStr)
View an Unreal TStringView via an STL string view.
Definition Text.h:171
MCRO_API FString UnrealCopy(FStdStringView const &stdStr)
Create a copy of an input STL string.
MCRO_API FStdString StdCopy(FStringView const &unrealStr)
Create an Stl copy of an input Unreal string view.