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