| 1 | /*
|
| 2 | * Report.h
|
| 3 | *
|
| 4 | * This file is part of the XShaderCompiler project (Copyright (c) 2014-2017 by Lukas Hermanns)
|
| 5 | * See "LICENSE.txt" for license information.
|
| 6 | */
|
| 7 |
|
| 8 | #ifndef XSC_REPORT_H
|
| 9 | #define XSC_REPORT_H
|
| 10 |
|
| 11 |
|
| 12 | #include "Export.h"
|
| 13 | #include <stdexcept>
|
| 14 | #include <string>
|
| 15 | #include <vector>
|
| 16 |
|
| 17 |
|
| 18 | namespace Xsc
|
| 19 | {
|
| 20 |
|
| 21 |
|
| 22 | //! Report types enumeration.
|
| 23 | enum class ReportTypes
|
| 24 | {
|
| 25 | Info, //!< Standard information.
|
| 26 | Warning, //!< Warning message.
|
| 27 | Error //!< Error message.
|
| 28 | };
|
| 29 |
|
| 30 | //! Report exception class which contains a completely constructed message with optional line marker, hints, and context description.
|
| 31 | class XSC_EXPORT Report : public std::exception
|
| 32 | {
|
| 33 |
|
| 34 | public:
|
| 35 |
|
| 36 | Report(const Report&) = default;
|
| 37 | Report& operator = (const Report&) = default;
|
| 38 |
|
| 39 | Report(const ReportTypes type, const std::string& message, const std::string& context = "" );
|
| 40 | Report(const ReportTypes type, const std::string& message, const std::string& line, const std::string& marker, const std::string& context = "" );
|
| 41 |
|
| 42 | //! Overrides the 'std::exception::what' function.
|
| 43 | const char* what() const throw() override;
|
| 44 |
|
| 45 | //! Moves the specified hints into this report.
|
| 46 | void TakeHints(std::vector<std::string>&& hints);
|
| 47 |
|
| 48 | //! Returns the type of this report.
|
| 49 | inline ReportTypes Type() const
|
| 50 | {
|
| 51 | return type_;
|
| 52 | }
|
| 53 |
|
| 54 | //! Returns the context description string (e.g. a function name where the report occured). This may also be empty.
|
| 55 | inline const std::string& Context() const
|
| 56 | {
|
| 57 | return context_;
|
| 58 | }
|
| 59 |
|
| 60 | //! Returns the message string.
|
| 61 | inline const std::string& Message() const
|
| 62 | {
|
| 63 | return message_;
|
| 64 | }
|
| 65 |
|
| 66 | //! Returns the line string where the report occured. This line never has new-line characters at its end.
|
| 67 | inline const std::string& Line() const
|
| 68 | {
|
| 69 | return line_;
|
| 70 | }
|
| 71 |
|
| 72 | //! Returns the line marker string to highlight the area where the report occured.
|
| 73 | inline const std::string& Marker() const
|
| 74 | {
|
| 75 | return marker_;
|
| 76 | }
|
| 77 |
|
| 78 | //! Returns the list of optional hints of the report.
|
| 79 | inline const std::vector<std::string>& GetHints() const
|
| 80 | {
|
| 81 | return hints_;
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | \brief Returns true if this report has a line with line marker.
|
| 86 | \see Line
|
| 87 | \see Marker
|
| 88 | */
|
| 89 | inline bool HasLine() const
|
| 90 | {
|
| 91 | return (!line_.empty());
|
| 92 | }
|
| 93 |
|
| 94 | private:
|
| 95 |
|
| 96 | ReportTypes type_ = ReportTypes::Info;
|
| 97 | std::string context_;
|
| 98 | std::string message_;
|
| 99 | std::string line_;
|
| 100 | std::string marker_;
|
| 101 | std::vector<std::string> hints_;
|
| 102 |
|
| 103 | };
|
| 104 |
|
| 105 |
|
| 106 | } // /namespace Xsc
|
| 107 |
|
| 108 |
|
| 109 | #endif
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 | // ================================================================================ |