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