Plasma Engine  2.0
Loading...
Searching...
No Matches
Status.h
1#pragma once
2
4
5#include <Foundation/Basics.h>
6#include <Foundation/Strings/StringBuilder.h>
7
9
11struct [[nodiscard]] PL_FOUNDATION_DLL plStatus
12{
13 PL_ALWAYS_INLINE explicit plStatus()
14 : m_Result(PL_FAILURE)
15 {
16 }
17
18 // const char* version is needed for disambiguation
19 explicit plStatus(const char* szError)
20 : m_Result(PL_FAILURE)
21 , m_sMessage(szError)
22 {
23 }
24
25 explicit plStatus(plResult r, plStringView sError)
26 : m_Result(r)
27 , m_sMessage(sError)
28 {
29 }
30
31 explicit plStatus(plStringView sError)
32 : m_Result(PL_FAILURE)
33 , m_sMessage(sError)
34 {
35 }
36
37 PL_ALWAYS_INLINE plStatus(plResult r)
38 : m_Result(r)
39 {
40 }
41
42 explicit plStatus(const plFormatString& fmt);
43
44 [[nodiscard]] PL_ALWAYS_INLINE bool Succeeded() const { return m_Result.Succeeded(); }
45 [[nodiscard]] PL_ALWAYS_INLINE bool Failed() const { return m_Result.Failed(); }
46
48 PL_ALWAYS_INLINE void IgnoreResult()
49 {
50 /* dummy to be called when a return value is [[nodiscard]] but the result is not needed */
51 }
52
56 bool LogFailure(plLogInterface* pLog = nullptr);
57
62 void AssertSuccess(const char* szMsg = nullptr) const;
63
64 plResult m_Result;
65 plString m_sMessage;
66};
67
68PL_ALWAYS_INLINE plResult plToResult(const plStatus& result)
69{
70 return result.m_Result;
71}
Implements formating of strings with placeholders and formatting options.
Definition FormatString.h:59
Base class for all logging classes.
Definition Log.h:77
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
An plResult with an additional message for the reason of failure.
Definition Status.h:12
PL_ALWAYS_INLINE void IgnoreResult()
Used to silence compiler warnings, when success or failure doesn't matter.
Definition Status.h:48