Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. |
| 3 | */ |
| 4 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 5 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "Base.h" |
| 10 | |
| 11 | #ifdef _WIN32 |
| 12 | #include <Windows.h> |
| 13 | //Windows.h defines #define GetMessage GetMessageW, which is stupid and we don't want it. |
| 14 | #undef GetMessage |
| 15 | #endif |
| 16 | |
| 17 | #include <string> |
| 18 | #include <stdint.h> |
| 19 | #include "llvm/StringRef.h" |
| 20 | |
| 21 | // Forward declarations |
| 22 | class ErrorBase; |
| 23 | |
| 24 | /** |
| 25 | * Error object represents a library error. |
| 26 | */ |
| 27 | class Error { |
| 28 | public: |
| 29 | typedef int32_t Code; |
| 30 | |
| 31 | Error() = default; |
| 32 | |
| 33 | Error(const Error&) = delete; |
| 34 | Error& operator=(const Error&) = delete; |
| 35 | |
| 36 | void Clone(const Error& error); |
| 37 | Code GetCode() const; |
| 38 | std::string GetMessage() const; |
| 39 | std::string GetFilename() const; |
| 40 | std::string GetFunction() const; |
| 41 | uint32_t GetLineNumber() const; |
| 42 | const ErrorBase* GetOriginatingObject() const; |
| 43 | double GetTimestamp() const; |
| 44 | void Clear(); |
| 45 | void Set(Code code, llvm::StringRef contextMessage, |
| 46 | llvm::StringRef filename, llvm::StringRef function, |
| 47 | uint32_t lineNumber, const ErrorBase* originatingObject); |
| 48 | |
| 49 | private: |
| 50 | void Report(); |
| 51 | |
| 52 | Code m_code = 0; |
| 53 | std::string m_message; |
| 54 | std::string m_filename; |
| 55 | std::string m_function; |
| 56 | uint32_t m_lineNumber = 0; |
| 57 | const ErrorBase* m_originatingObject = nullptr; |
| 58 | double m_timestamp = 0.0; |
| 59 | }; |