-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97a48f4
commit f296827
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#pragma once | ||
|
||
#include <string_view> // string_view | ||
|
||
namespace tactile { | ||
|
||
/** | ||
* Provides common error codes. | ||
*/ | ||
enum class ErrorCode : int | ||
{ | ||
/** An unknown error occurred. */ | ||
kUnknown, | ||
|
||
/** An operation or feature isn't supported. */ | ||
kNotSupported, | ||
|
||
/** Not enough memory. */ | ||
kOutOfMemory, | ||
|
||
/** A stack overflow was detected. */ | ||
kStackOverflow, | ||
|
||
/** A stack underflow was detected. */ | ||
kStackUnderflow, | ||
|
||
/** Initialization failed. */ | ||
kBadInit, | ||
|
||
/** A given parameter is invalid. */ | ||
kBadParam, | ||
|
||
/** An invalid state was detected. */ | ||
kBadState, | ||
|
||
/** An invalid operation was attempted. */ | ||
kBadOperation, | ||
|
||
/** A file doesn't exist. */ | ||
kNoSuchFile, | ||
|
||
/** A file stream couldn't be created. */ | ||
kBadFileStream, | ||
|
||
/** A file couldn't be copied. */ | ||
kBadFileCopy, | ||
|
||
/** An invalid image was detected. */ | ||
kBadImage, | ||
|
||
/** An invalid save file was detected. */ | ||
kBadSaveFile, | ||
|
||
/** A compression operation failed. */ | ||
kCouldNotCompress, | ||
|
||
/** A decompression operation failed. */ | ||
kCouldNotDecompress, | ||
}; | ||
|
||
[[nodiscard]] | ||
constexpr auto to_string(const ErrorCode errc) noexcept -> std::string_view | ||
{ | ||
switch (errc) { | ||
case ErrorCode::kUnknown: return "unknown"; | ||
case ErrorCode::kNotSupported: return "not supported"; | ||
case ErrorCode::kOutOfMemory: return "out of memory"; | ||
case ErrorCode::kStackOverflow: return "stack overflow"; | ||
case ErrorCode::kStackUnderflow: return "stack underflow"; | ||
case ErrorCode::kBadInit: return "initialization error"; | ||
case ErrorCode::kBadParam: return "invalid parameter"; | ||
case ErrorCode::kBadState: return "invalid state"; | ||
case ErrorCode::kBadOperation: return "invalid operation"; | ||
case ErrorCode::kNoSuchFile: return "no such file"; | ||
case ErrorCode::kBadFileStream: return "file stream error"; | ||
case ErrorCode::kBadFileCopy: return "file copy error"; | ||
case ErrorCode::kBadImage: return "invalid image"; | ||
case ErrorCode::kBadSaveFile: return "invalid save file"; | ||
case ErrorCode::kCouldNotCompress: return "could not compress"; | ||
case ErrorCode::kCouldNotDecompress: return "could not decompress"; | ||
} | ||
|
||
return "?"; | ||
} | ||
|
||
} // namespace tactile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters