UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IoStatus.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
9
10template <typename CharType> class TStringBuilderBase;
11
12
14
18enum class EIoErrorCode
20 Ok,
21 Unknown,
40 Timeout,
48 Last
49};
50
53
55
60{
61public:
64
65 CORE_API FIoStatus(EIoErrorCode ErrorCode, const FStringView& ErrorMessage);
66 CORE_API FIoStatus(EIoErrorCode ErrorCode, uint32 SystemErrorCode, const FStringView& ErrorMessage);
67 CORE_API FIoStatus(EIoErrorCode ErrorCode, uint32 SystemErrorCode);
70 CORE_API FIoStatus& operator=(const EIoErrorCode ErrorCode);
71
72 CORE_API bool operator==(const FIoStatus& Other) const;
73 bool operator!=(const FIoStatus& Other) const { return !operator==(Other); }
74
75 inline bool IsOk() const { return ErrorCode == EIoErrorCode::Ok; }
76 inline bool IsCompleted() const { return ErrorCode != EIoErrorCode::Unknown; }
77 inline EIoErrorCode GetErrorCode() const { return ErrorCode; }
78 inline uint32 GetSystemErrorCode() const { return SystemErrorCode; }
79 const TCHAR* GetErrorMessage() const { return ErrorMessage.IsEmpty() ? nullptr : *ErrorMessage; }
80 CORE_API FString ToString() const;
81
82 CORE_API friend void SerializeForLog(FCbWriter& Writer, const FIoStatus& Value);
83
84 CORE_API static const FIoStatus Ok;
85 CORE_API static const FIoStatus Unknown;
86 CORE_API static const FIoStatus Invalid;
87
88private:
89 UE::FSharedString ErrorMessage;
91 uint32 SystemErrorCode = 0;
92
93 friend class FIoStatusBuilder;
94};
95
99template<typename T>
101{
102 template<typename U> friend class TIoStatusOr;
103
104public:
105 TIoStatusOr() : StatusValue(FIoStatus::Unknown) {}
108
110 TIoStatusOr(const T& InValue);
111 TIoStatusOr(T&& InValue);
112
113 ~TIoStatusOr();
114
115 template <typename... ArgTypes>
116 explicit TIoStatusOr(ArgTypes&&... Args);
117
118 template<typename U>
120
126
127 template<typename U>
129
130 const FIoStatus& Status() const;
131 bool IsOk() const;
132
133 const T& ValueOrDie();
135
136 void Reset();
137
138private:
139 FIoStatus StatusValue;
141};
142
144
174
180{
181private:
182 const TCHAR* NamespaceStr = nullptr;
183public:
187
190 const uint_least32_t Column = __builtin_COLUMN()) const
191 {
192 return FIoStatusBuilder(NamespaceStr, StatusCode, Line, Column);
193 }
194};
195
196CORE_API void StatusOrCrash(const FIoStatus& Status);
197
198template<typename T>
200{
201 EIoErrorCode ErrorCode = StatusValue.GetErrorCode();
202 StatusValue = EIoErrorCode::Unknown;
203
204 if (ErrorCode == EIoErrorCode::Ok)
205 {
206 ((T*)&Value)->~T();
207 }
208}
209
210template<typename T>
212{
213 if (!StatusValue.IsOk())
214 {
215 StatusOrCrash(StatusValue);
216 }
217
218 return *Value.GetTypedPtr();
219}
220
221template<typename T>
223{
224 if (!StatusValue.IsOk())
225 {
226 StatusOrCrash(StatusValue);
227 }
228
229 StatusValue = FIoStatus::Unknown;
230
231 return MoveTemp(*Value.GetTypedPtr());
232}
233
234template<typename T>
236{
237 StatusValue = Other.StatusValue;
238 if (StatusValue.IsOk())
239 {
240 new(&Value) T(*(const T*)&Other.Value);
241 }
242}
243
244template<typename T>
246{
247 StatusValue = Other.StatusValue;
248 if (StatusValue.IsOk())
249 {
250 new(&Value) T(MoveTempIfPossible(*(T*)&Other.Value));
251 Other.StatusValue = EIoErrorCode::Unknown;
252 }
253}
254
255template<typename T>
257{
258 check(!InStatus.IsOk());
259 StatusValue = InStatus;
260}
261
262template<typename T>
264{
265 StatusValue = FIoStatus::Ok;
266 new(&Value) T(InValue);
267}
268
269template<typename T>
271{
272 StatusValue = FIoStatus::Ok;
274}
275
276template <typename T>
277template <typename... ArgTypes>
279{
280 StatusValue = FIoStatus::Ok;
281 new(&Value) T(Forward<ArgTypes>(Args)...);
282}
283
284template<typename T>
289
290template<typename T>
292{
293 return StatusValue.IsOk();
294}
295
296template<typename T>
298{
299 return StatusValue;
300}
301
302template<typename T>
305{
306 if (&Other != this)
307 {
308 Reset();
309
310 if (Other.StatusValue.IsOk())
311 {
312 new(&Value) T(*(const T*)&Other.Value);
313 StatusValue = EIoErrorCode::Ok;
314 }
315 else
316 {
317 StatusValue = Other.StatusValue;
318 }
319 }
320
321 return *this;
322}
323
324template<typename T>
327{
328 if (&Other != this)
329 {
330 Reset();
331
332 if (Other.StatusValue.IsOk())
333 {
334 new(&Value) T(MoveTempIfPossible(*(T*)&Other.Value));
335 Other.StatusValue = EIoErrorCode::Unknown;
336 StatusValue = EIoErrorCode::Ok;
337 }
338 else
339 {
340 StatusValue = Other.StatusValue;
341 }
342 }
343
344 return *this;
345}
346
347template<typename T>
350{
351 check(!OtherStatus.IsOk());
352
353 Reset();
354 StatusValue = OtherStatus;
355
356 return *this;
357}
358
359template<typename T>
362{
363 if (&OtherValue != (T*)&Value)
364 {
365 Reset();
366
367 new(&Value) T(OtherValue);
368 StatusValue = EIoErrorCode::Ok;
369 }
370
371 return *this;
372}
373
374template<typename T>
377{
378 if (&OtherValue != (T*)&Value)
379 {
380 Reset();
381
383 StatusValue = EIoErrorCode::Ok;
384 }
385
386 return *this;
387}
388
389template<typename T>
390template<typename U>
392: StatusValue(Other.StatusValue)
393{
394 if (StatusValue.IsOk())
395 {
396 new(&Value) T(*(const U*)&Other.Value);
397 }
398}
399
400template<typename T>
401template<typename U>
403{
404 Reset();
405
406 if (Other.StatusValue.IsOk())
407 {
408 new(&Value) T(*(const U*)&Other.Value);
409 StatusValue = EIoErrorCode::Ok;
410 }
411 else
412 {
413 StatusValue = Other.StatusValue;
414 }
415
416 return *this;
417}
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
CORE_API const TCHAR * GetIoErrorText(EIoErrorCode ErrorCode)
Definition IoStatus.cpp:23
CORE_API void StatusOrCrash(const FIoStatus &Status)
Definition IoStatus.cpp:122
EIoErrorCode
Definition IoStatus.h:19
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTempIfPossible(T &&Obj) noexcept
Definition UnrealTemplate.h:538
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition CompactBinaryWriter.h:68
Definition IoStatus.h:149
CORE_API ~FIoStatusBuilder()
Definition IoStatus.cpp:151
CORE_API FIoStatusBuilder & operator<<(FStringView String)
Definition IoStatus.cpp:160
EIoErrorCode StatusCode
Definition IoStatus.h:151
uint32 SystemErrorCode
Definition IoStatus.h:152
TStringBuilder< 256 > Message
Definition IoStatus.h:153
Definition IoStatus.h:60
CORE_API FString ToString() const
Definition IoStatus.cpp:89
EIoErrorCode GetErrorCode() const
Definition IoStatus.h:77
CORE_API FIoStatus & operator=(const FIoStatus &Other)
Definition IoStatus.cpp:66
CORE_API ~FIoStatus()
Definition IoStatus.cpp:38
CORE_API bool operator==(const FIoStatus &Other) const
Definition IoStatus.cpp:84
bool IsOk() const
Definition IoStatus.h:75
CORE_API FIoStatus()
Definition IoStatus.cpp:34
static CORE_API const FIoStatus Unknown
Definition IoStatus.h:18
CORE_API friend void SerializeForLog(FCbWriter &Writer, const FIoStatus &Value)
Definition IoStatus.cpp:107
bool operator!=(const FIoStatus &Other) const
Definition IoStatus.h:73
const TCHAR * GetErrorMessage() const
Definition IoStatus.h:79
uint32 GetSystemErrorCode() const
Definition IoStatus.h:78
bool IsCompleted() const
Definition IoStatus.h:76
static CORE_API const FIoStatus Invalid
Definition IoStatus.h:19
static CORE_API const FIoStatus Ok
Definition IoStatus.h:17
Definition IoStatus.h:180
FIoStatusBuilder operator()(EIoErrorCode StatusCode, const uint_least32_t Line=__builtin_LINE(), const uint_least32_t Column=__builtin_COLUMN()) const
Definition IoStatus.h:188
FNamespacedIoStatusBuilderBuilder(const TCHAR *InNamespaceStr)
Definition IoStatus.h:184
Definition IoStatus.h:101
const T & ValueOrDie()
Definition IoStatus.h:211
bool IsOk() const
Definition IoStatus.h:291
void Reset()
Definition IoStatus.h:199
TIoStatusOr< T > & operator=(const TIoStatusOr< T > &Other)
Definition IoStatus.h:304
friend class TIoStatusOr
Definition IoStatus.h:102
const FIoStatus & Status() const
Definition IoStatus.h:297
T ConsumeValueOrDie()
Definition IoStatus.h:222
~TIoStatusOr()
Definition IoStatus.h:285
TIoStatusOr()
Definition IoStatus.h:105
Definition StringBuilder.h:79
Definition StringBuilder.h:509
constexpr bool IsEmpty() const
Definition StringView.h:180
Definition TypeCompatibleBytes.h:24