UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
StringOutputDevice.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Misc/OutputDevice.h"
7#include "Templates/Tuple.h"
9
10class FName;
11
12namespace ELogVerbosity
13{
14 enum Type : uint8;
15}
16
20class FStringOutputDevice : public FString, public FOutputDevice
21{
22public:
23 FStringOutputDevice(const TCHAR* Prefix = TEXT(""))
24 : FString(Prefix)
25 {
27 }
28
29 virtual void Serialize(const TCHAR* InData, ELogVerbosity::Type Verbosity, const FName& Category) override
30 {
31 FString::operator+=((TCHAR*)InData);
33 {
34 *this += LINE_TERMINATOR;
35 }
36 }
37
42
43 // Make += operator virtual.
44 virtual FString& operator+=(const FString& Other)
45 {
46 return FString::operator+=(Other);
47 }
48
49 UE_REWRITE bool UEOpEquals(const FString& Rhs) const
50 {
51 return FString::UEOpEquals(Rhs);
52 }
53
54 UE_REWRITE bool UEOpLessThan(const FString& Rhs) const
55 {
56 return FString::UEOpLessThan(Rhs);
57 }
58
59 UE_REWRITE bool UEOpGreaterThan(const FString& Rhs) const
60 {
61 return Rhs.UEOpLessThan(*this);
62 }
63};
64
65template <>
67{
68 enum { Value = true };
69};
70
75{
77
78public:
80 : Super(Prefix)
81 {
82 }
83
84 virtual void Serialize(const TCHAR* InData, ELogVerbosity::Type Verbosity, const class FName& Category) override
85 {
86 Super::Serialize(InData, Verbosity, Category);
88 for (;;)
89 {
91 if (!InData)
92 {
93 break;
94 }
95 LineCount++;
97 }
98
100 {
101 LineCount++;
102 }
103 }
104
109 {
110 FString::operator+=(static_cast<const FString&>(Other));
111
112 LineCount += Other.GetLineCount();
113
114 return *this;
115 }
116
121 virtual FString& operator+=(const FString& Other) override
122 {
123 Log(Other);
124
125 return *this;
126 }
127
129 {
130 return LineCount;
131 }
132
135
137 : Super ((Super&&)Other)
138 , LineCount(Other.LineCount)
139 {
140 Other.LineCount = 0;
141 }
142
144 {
145 if (this != &Other)
146 {
147 (Super&)*this = (Super&&)Other;
148 LineCount = Other.LineCount;
149
150 Other.LineCount = 0;
151 }
152 return *this;
153 }
154
155private:
156 int32 LineCount = 0;
157};
158
159template <>
164
168template <typename... LogCategoryTypes>
170{
171public:
177
178 virtual void Serialize(const TCHAR* InData, ELogVerbosity::Type Verbosity, const FName& Category) override
179 {
180 bool bFoundMatchingCategory = false;
182 [&bFoundMatchingCategory, &Category](auto& Elem)
183 {
184 bFoundMatchingCategory = bFoundMatchingCategory || (Category == Elem->GetCategoryName());
185 },
186 LogCategories);
187
189 {
190 FStringOutputDevice::Serialize(InData, Verbosity, Category);
191 }
192 }
193
194private:
195 TTuple<LogCategoryTypes*...> LogCategories;
196};
197
198template <typename... LogCategoryTypes>
#define UE_LIFETIMEBOUND
Definition Platform.h:812
#define LINE_TERMINATOR
Definition Platform.h:902
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_REWRITE
Definition Platform.h:747
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_FORCEINLINE_HINT void VisitTupleElements(FuncType &&Func, FirstTupleType &&FirstTuple, TupleTypes &&... Tuples)
Definition Tuple.h:878
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition NameTypes.h:617
Definition OutputDevice.h:133
bool bAutoEmitLineTerminator
Definition OutputDevice.h:271
Definition StringOutputDevice.h:75
FStringOutputDeviceCountLines & operator=(FStringOutputDeviceCountLines &&Other)
Definition StringOutputDevice.h:143
virtual FStringOutputDeviceCountLines & operator+=(const FStringOutputDeviceCountLines &Other)
Definition StringOutputDevice.h:108
FStringOutputDeviceCountLines & operator=(const FStringOutputDeviceCountLines &)=default
FStringOutputDeviceCountLines(const FStringOutputDeviceCountLines &)=default
virtual void Serialize(const TCHAR *InData, ELogVerbosity::Type Verbosity, const class FName &Category) override
Definition StringOutputDevice.h:84
virtual FString & operator+=(const FString &Other) override
Definition StringOutputDevice.h:121
int32 GetLineCount() const
Definition StringOutputDevice.h:128
FStringOutputDeviceCountLines(FStringOutputDeviceCountLines &&Other)
Definition StringOutputDevice.h:136
FStringOutputDeviceCountLines(const TCHAR *Prefix=TEXT(""))
Definition StringOutputDevice.h:79
Definition StringOutputDevice.h:21
FStringOutputDevice(const FStringOutputDevice &)=default
UE_REWRITE bool UEOpGreaterThan(const FString &Rhs) const
Definition StringOutputDevice.h:59
virtual void Serialize(const TCHAR *InData, ELogVerbosity::Type Verbosity, const FName &Category) override
Definition StringOutputDevice.h:29
UE_REWRITE bool UEOpLessThan(const FString &Rhs) const
Definition StringOutputDevice.h:54
FStringOutputDevice & operator=(FStringOutputDevice &&)=default
virtual FString & operator+=(const FString &Other)
Definition StringOutputDevice.h:44
FStringOutputDevice & operator=(const FStringOutputDevice &)=default
FStringOutputDevice(FStringOutputDevice &&)=default
UE_REWRITE bool UEOpEquals(const FString &Rhs) const
Definition StringOutputDevice.h:49
FStringOutputDevice(const TCHAR *Prefix=TEXT(""))
Definition StringOutputDevice.h:23
Definition StringOutputDevice.h:170
TLogCategoryOutputDevice(LogCategoryTypes &... InLogCategories UE_LIFETIMEBOUND)
Definition StringOutputDevice.h:172
virtual void Serialize(const TCHAR *InData, ELogVerbosity::Type Verbosity, const FName &Category) override
Definition StringOutputDevice.h:178
UE_FORCEINLINE_HINT bool UEOpLessThan(const UE_STRING_CLASS &Rhs) const
Definition UnrealString.h.inl:893
Definition GenericPlatformFile.h:25
Type
Definition LogVerbosity.h:17
static int32 Strlen(const CharType *String)
Definition CString.h:1047
static UE_FORCEINLINE_HINT const CharType * Strstr(const CharType *String, const CharType *Find)
Definition CString.h:1066
Definition IsContiguousContainer.h:16
static constexpr bool Value
Definition IsContiguousContainer.h:20
Definition Tuple.h:652