Error.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef CORE_ERROR_HPP
  2. #define CORE_ERROR_HPP
  3. namespace Core {
  4. enum class Error {
  5. NONE = 0,
  6. NEGATIVE_ARGUMENT,
  7. CAPACITY_REACHED,
  8. BLOCKED_STDOUT,
  9. OUT_OF_MEMORY,
  10. INVALID_CHAR,
  11. NOT_FOUND,
  12. INVALID_STATE,
  13. INVALID_INDEX,
  14. INVALID_ARGUMENT,
  15. TIME_NOT_AVAILABLE,
  16. SLEEP_INTERRUPTED,
  17. THREAD_ERROR,
  18. EXISTING_KEY,
  19. CANNOT_OPEN_FILE,
  20. END_OF_FILE
  21. };
  22. const char* getErrorName(Error e);
  23. inline bool checkError(Error& storage, Error e) {
  24. return (storage = e) != Error::NONE;
  25. }
  26. #define CORE_RETURN_ERROR(checked) \
  27. { \
  28. Core::Error error = Core::Error::NONE; \
  29. if(checkError(error, checked)) [[unlikely]] { \
  30. return error; \
  31. } \
  32. }
  33. }
  34. #endif