Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
GeneratedTypeName.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Delegates/IntegerSequence.h"
7
8#if defined(_MSC_VER) && !defined(__clang__)
9 #define SIG __FUNCSIG__
10 #define SIG_STARTCHAR '<'
11 #define SIG_ENDCHAR '>'
12
13 #pragma warning(push)
14 #pragma warning(disable : 4503) // "identifier" : decorated name length exceeded, name was truncated
15#else
16 #define SIG __PRETTY_FUNCTION__
17 #define SIG_STARTCHAR '='
18 #define SIG_ENDCHAR ']'
19#endif
20
22
24{
25 // Class representing a substring of another string
26 struct FSubstr
27 {
28 const char* Ptr;
29 uint32 Length;
30
31 constexpr char operator[](uint32 Index) const
32 {
33 return Ptr[Index];
34 }
35
36 constexpr uint32 Len() const
37 {
38 return Length;
39 }
40
41 constexpr FSubstr PopFront(int Num = 1) const
42 {
43 return { Ptr + Num, Len() - Num };
44 }
45
46 constexpr FSubstr PopBack(int Num = 1) const
47 {
48 return { Ptr, Len() - Num };
49 }
50
51 constexpr FSubstr PopFrontAll(char Ch) const
52 {
53 return (Len() > 0 && Ptr[0] == Ch) ? PopFront().PopFrontAll(Ch) : *this;
54 }
55
56 constexpr FSubstr PopFrontAllNot(char Ch) const
57 {
58 return (Len() > 0 && Ptr[0] != Ch) ? PopFront().PopFrontAllNot(Ch) : *this;
59 }
60
61 constexpr FSubstr PopBackAll(char Ch) const
62 {
63 return (Len() > 0 && Ptr[Len() - 1] == Ch) ? PopBack().PopBackAll(Ch) : *this;
64 }
65
66 constexpr FSubstr PopBackAllNot(char Ch) const
67 {
68 return (Len() > 0 && Ptr[Len() - 1] != Ch) ? PopBack().PopBackAllNot(Ch) : *this;
69 }
70 };
71
72 // Gets the name of the type as a substring of a literal
73 template <typename T>
75 {
76 return FSubstr{ SIG, sizeof(SIG) - 1 }
83 }
84
85 template <uint32 NumChars>
87 {
88 TCHAR Array[NumChars + 1];
89 };
90
91 template <typename T, uint32... Indices>
93 {
94 return TCharArray<sizeof...(Indices)> { { (TCHAR)GetTypeSubstr<T>()[Indices]... } };
95 }
96}
97
98#endif
99
100/**
101 * Returns a pointer to a static string representing the name of the type, e.g.:
102 *
103 * const TCHAR* FStringName = GetGeneratedTypeName<FString>() // "FString"
104 *
105 * Caveats:
106 * - The strings are compiler-dependent and thus non-portable, and so shouldn't be saved or relied upon as a form of identity, e.g. the example above returns "class FString" on MSVC.
107 * - Default template parameters are also handled differently by different compilers, sometimes ignored, sometimes not.
108 * - Only the concrete type is known to the compiler, aliases are ignored, e.g. GetGeneratedTypeName<TCHAR>() typically returns "wchar_t".
109 */
110template <typename T>
111inline const TCHAR* GetGeneratedTypeName()
112{
113 static constexpr auto Result = UETypeName_Private::TypeSubstrToCharArray<T>(TMakeIntegerSequence<uint32, UETypeName_Private::GetTypeSubstr<T>().Len()>());
114 return Result.Array;
115}
116
117#if defined(_MSC_VER) && !defined(__clang__)
118 #pragma warning(pop)
119#endif
120
121#undef SIG_ENDCHAR
122#undef SIG_STARTCHAR
123#undef SIG
#define UE_BUILD_DOCS
Definition Build.h:38
#define SIG_ENDCHAR
#define SIG_STARTCHAR
#define SIG
const TCHAR * GetGeneratedTypeName()
constexpr TCharArray< sizeof...(Indices)> TypeSubstrToCharArray(TIntegerSequence< uint32, Indices... >)
constexpr FSubstr GetTypeSubstr()
constexpr FSubstr PopFrontAll(char Ch) const
constexpr char operator[](uint32 Index) const
constexpr FSubstr PopFront(int Num=1) const
constexpr FSubstr PopBack(int Num=1) const
constexpr uint32 Len() const
constexpr FSubstr PopBackAllNot(char Ch) const
constexpr FSubstr PopBackAll(char Ch) const
constexpr FSubstr PopFrontAllNot(char Ch) const