blob: a00114573ea802b1914edd17493d11f4a2bc11dc [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05007
Brian Silverman26e4e522015-12-17 01:56:40 -05008#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
23class ErrorBase;
24
25/**
26 * Error object represents a library error.
27 */
28class 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};