AuroraRuntime/Include/Aurora/Debug/ErrorStack.hpp

102 lines
2.2 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ErrorStack.hpp
Date: 2022-11-29
Author: Reece
***/
#pragma once
namespace Aurora::Debug
{
struct ErrorStack;
struct ErrorStackAccessor;
struct ThreadMessage
{
AuSPtr<ThreadMessage> pNextThreadMesage;
AuSPtr<AuString> pStringMessage;
AuOptional<EFailureCategory> eFailureCategory;
AuOptional<StackTrace> optStackTrace;
AuOptional<AuUInt> optOsErrorCode;
AuUInt16 uDebugBuildSourceLineHint {};
AUKN_SYM const AuString &ToString();
};
struct ErrorStack
{
AUKN_SYM ErrorStack();
AUKN_SYM ~ErrorStack();
inline bool HasCapturedMessage()
{
CheckErrors();
return bool(this->pHead);
}
inline bool HasCaptured()
{
return HasCapturedMessage() || this->bOutOfMemory;
}
inline bool HasMultipleOccurred()
{
return this->HasCaptured() && bool(this->pHead->pNextThreadMesage);
}
inline AuOptional<const StackTrace &> ToStackTrace()
{
if (!this->HasCaptured())
{
return {};
}
if (!this->pHead->optStackTrace)
{
return {};
}
return this->pHead->optStackTrace.value();
}
inline AuOptional<const AuString&> ToString()
{
static const AuString kOutOfMemoryString = "Aurora: Out of Memory";
if (this->HasCaptured())
{
return this->pHead->ToString();
}
else if (this->HasOOMCondition())
{
return kOutOfMemoryString;
}
else
{
return {};
}
}
inline AuSPtr<ThreadMessage> FirstMessage()
{
return this->pHead;
}
inline bool HasOOMCondition()
{
return this->bOutOfMemory;
}
protected:
friend ErrorStackAccessor;
AuSPtr<ThreadMessage> pHead;
ErrorStack *pNext {};
bool bOutOfMemory {};
};
}
using AuErrorStack = Aurora::Debug::ErrorStack;