MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
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/** 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}
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
MCRO_API FStringView UnrealView(FStdStringView const &stdStr)
MCRO_API FStdStringView StdView(FString const &unrealStr)
MCRO_API FName UnrealNameCopy(FStdStringView const &stdStr)
MCRO_API FString UnrealCopy(FStdStringView const &stdStr)
MCRO_API FStdString StdCopy(FStringView const &unrealStr)