PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/3rdParty/SlonEngine/3rdParty/SimpleGL/sgl/Utility/Error.h

https://bitbucket.org/DikobrAz/motioneditor
C Header | 151 lines | 98 code | 28 blank | 25 comment | 0 complexity | c462783abeb818f0d0034799cced4245 MD5 | raw file
Possible License(s): LGPL-2.1
  1. #ifndef SIMPLE_GL_UTILITY_ERROR_H
  2. #define SIMPLE_GL_UTILITY_ERROR_H
  3. #include "../Config.h"
  4. #include "Referenced.h"
  5. namespace sgl {
  6. /** Used to determine the result or status of the executed operation */
  7. enum SGL_HRESULT
  8. {
  9. SGL_OK, /// operation succeeded
  10. SGLERR_INVALID_CALL, /// function call with invalid arguments
  11. SGLERR_OUT_OF_MEMORY, /// couldn't allocate memory
  12. SGLERR_FILE_NOT_FOUND, /// couldn't find specified file
  13. SGLERR_IO, /// error in input/output operation
  14. SGLERR_UNSUPPORTED, /// operation not supported by the hardware
  15. SGLERR_UNAVAILABLE, /// resource is unavailable at the moment
  16. SGLERR_UNKNOWN /// unknow error
  17. };
  18. /** Handler to handle simple gl errors. For example log it into the file */
  19. class SGL_DLLEXPORT ErrorHandler
  20. {
  21. public:
  22. /** Handle sgl error
  23. * @param result - type of the error
  24. * @param msg - error message
  25. */
  26. virtual void HandleError(SGL_HRESULT result, const char* msg) = 0;
  27. virtual ~ErrorHandler() {}
  28. };
  29. } // namespace sgl
  30. /** Get last occured error */
  31. extern "C" SGL_DLLEXPORT sgl::SGL_HRESULT SGL_DLLCALL sglGetLastError();
  32. /** Get last error message */
  33. extern "C" SGL_DLLEXPORT const char* SGL_DLLCALL sglGetErrorMsg();
  34. /** Set error handler to the sgl */
  35. extern "C" SGL_DLLEXPORT void SGL_DLLCALL sglSetErrorHandler(sgl::ErrorHandler* _handler);
  36. /** Get error handler of the sgl */
  37. extern "C" SGL_DLLEXPORT sgl::ErrorHandler* SGL_DLLCALL sglGetErrorHandler();
  38. /* Set sgl error */
  39. extern "C" SGL_DLLEXPORT void SGL_DLLCALL sglSetError(sgl::SGL_HRESULT _type, const char* _msg);
  40. namespace sgl {
  41. /** Error handler that logs errors to the platform specific log (cerr, android log, ...). */
  42. class SGL_DLLEXPORT PrintErrorHandler :
  43. public ErrorHandler
  44. {
  45. public:
  46. // Override ErrorHandler
  47. void HandleError(SGL_HRESULT type, const char* msg);
  48. virtual ~PrintErrorHandler() {}
  49. };
  50. /** Error occurs when calling function with invalid arguments */
  51. inline SGL_HRESULT EInvalidCall()
  52. {
  53. sglSetError(SGLERR_INVALID_CALL, "Invalid function call");
  54. return SGLERR_INVALID_CALL;
  55. }
  56. /** Error occurs when calling function with invalid arguments */
  57. inline SGL_HRESULT EInvalidCall(const char* msg)
  58. {
  59. sglSetError(SGLERR_INVALID_CALL, msg);
  60. return SGLERR_INVALID_CALL;
  61. }
  62. /** Error occurs when we are out of memory */
  63. inline SGL_HRESULT EOutOfMemory()
  64. {
  65. sglSetError(SGLERR_OUT_OF_MEMORY, "Out of memory");
  66. return SGLERR_OUT_OF_MEMORY;
  67. }
  68. /** Error occurs when we are out of memory */
  69. inline SGL_HRESULT EOutOfMemory(const char* msg)
  70. {
  71. sglSetError(SGLERR_OUT_OF_MEMORY, msg);
  72. return SGLERR_OUT_OF_MEMORY;
  73. }
  74. /** Error occurs when we are trying to open unexisted file for reading */
  75. inline SGL_HRESULT EFileNotFound()
  76. {
  77. sglSetError(SGLERR_FILE_NOT_FOUND, "File not found");
  78. return SGLERR_FILE_NOT_FOUND;
  79. }
  80. /** Error occurs when we are trying to open unexisted file for reading */
  81. inline SGL_HRESULT EFileNotFound(const char* msg)
  82. {
  83. sglSetError(SGLERR_FILE_NOT_FOUND, msg);
  84. return SGLERR_FILE_NOT_FOUND;
  85. }
  86. /** Error occured during IO operation */
  87. inline SGL_HRESULT EIOError()
  88. {
  89. sglSetError(SGLERR_IO, "IO error");
  90. return SGLERR_IO;
  91. }
  92. /** Error occured during IO operation */
  93. inline SGL_HRESULT EIOError(const char* msg)
  94. {
  95. sglSetError(SGLERR_IO, msg);
  96. return SGLERR_IO;
  97. }
  98. /** Error occurs when we are trying to perform operation unsupported by the hardware */
  99. inline SGL_HRESULT EUnsupported()
  100. {
  101. sglSetError(SGLERR_UNSUPPORTED, "Operation unsupported by the hardware");
  102. return SGLERR_UNSUPPORTED;
  103. }
  104. /** Error occurs when we are trying to perform operation unsupported by the hardware */
  105. inline SGL_HRESULT EUnsupported(const char* msg)
  106. {
  107. sglSetError(SGLERR_UNSUPPORTED, msg);
  108. return SGLERR_UNSUPPORTED;
  109. }
  110. /** Mystic error */
  111. inline SGL_HRESULT EUnknown()
  112. {
  113. sglSetError(SGLERR_UNKNOWN, "Unknown error");
  114. return SGLERR_UNKNOWN;
  115. }
  116. /** Mystic error */
  117. inline SGL_HRESULT EUnknown(const char* msg)
  118. {
  119. sglSetError(SGLERR_UNKNOWN, msg);
  120. return SGLERR_UNKNOWN;
  121. }
  122. } // namespace sgl
  123. #endif // SIMPLE_GL_UTILITY_ERROR_H