diff --git a/src/lib/error.h++ b/src/lib/error.h++ index e60af52..a675363 100644 --- a/src/lib/error.h++ +++ b/src/lib/error.h++ @@ -15,22 +15,59 @@ #pragma once +#include + template struct ErrorOr { bool isError; + uint8_t errorCode; T value; ErrorOr(); ErrorOr(T); + ErrorOr(bool); + ErrorOr(bool, uint8_t); + ErrorOr(bool, uint8_t, T); }; template ErrorOr::ErrorOr() { this->isError = false; + this->errorCode = 0; } template ErrorOr::ErrorOr(T value) { this->isError = false; + this->errorCode = 0; this->value = value; } + +template +ErrorOr::ErrorOr(bool isError) { + this->isError = isError; + this->errorCode = 0; +} + +template +ErrorOr::ErrorOr(bool isError, uint8_t errorCode) { + this->isError = isError; + this->errorCode = errorCode; +} + +template +ErrorOr::ErrorOr(bool isError, uint8_t errorCode, T value) { + this->isError = isError; + this->errorCode = errorCode; + this->value = value; +} + +namespace ErrorCodes { + // These are all arbitrary values used to assign error codes to different + // kinds of errors. + // Using them is optional as ErrorOr<> accepts any uint8_t value as + // error code, but they are useful for readability. + + // IndexOutOfRangeException equivalent + const uint8_t RANGE_ERROR = 1; +}