CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Report.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
13#include <stdexcept>
14
16
18 enum class ReportTypes {
20 Info,
21
23 Warning,
24
26 Error
27 };
28
31 class Report : public std::exception {
32 public:
33 Report(const Report&) = default;
34 Report& operator=(const Report&) = default;
35
36 inline Report(const ReportTypes type, const String& message, const String& context = "") : mType{type}, mContext{context}, mMessage{message} {}
37
38 inline Report(const ReportTypes type, const String& message, const String& line, const String& marker, const String& context = "")
39 : mType{type}, mContext{context}, mMessage{message}, mLine{line}, mMarker{marker} {
41 while(!mLine.empty() && (mLine.back() == '\n' || mLine.back() == '\r')) {
42 mLine.pop_back();
43 }
44 }
45
47 [[nodiscard]] inline const char* what() const noexcept override { return mMessage.c_str(); }
48
50 inline void takeHints(Vector<String>&& hints) { mHints = std::move(hints); }
51
53 [[nodiscard]] inline ReportTypes getType() const { return mType; }
54
56 [[nodiscard]] inline const String& getContext() const { return mContext; }
57
59 [[nodiscard]] inline const String& getMessage() const { return mMessage; }
60
62 [[nodiscard]] inline const String& getLine() const { return mLine; }
63
65 [[nodiscard]] inline const String& getMarker() const { return mMarker; }
66
68 [[nodiscard]] inline const Vector<String>& getHints() const { return mHints; }
69
73 [[nodiscard]] inline bool hasLine() const { return (!mLine.empty()); }
74
75 private:
82 };
83
84} // namespace CeresEngine::ShaderCompiler
Report exception class which contains a completely constructed message with optional line marker,...
Definition Report.hpp:31
Report(const Report &)=default
Report & operator=(const Report &)=default
String mContext
Definition Report.hpp:77
String mMessage
Definition Report.hpp:78
const char * what() const noexcept override
Overrides the 'std::exception::what' function.
Definition Report.hpp:47
Vector< String > mHints
Definition Report.hpp:81
const String & getLine() const
Returns the line string where the report occured. This line never has new-line characters at its end.
Definition Report.hpp:62
const String & getContext() const
Returns the context description string (e.g. a function name where the report occured)....
Definition Report.hpp:56
const String & getMarker() const
Returns the line marker string to highlight the area where the report occured.
Definition Report.hpp:65
String mMarker
Definition Report.hpp:80
Report(const ReportTypes type, const String &message, const String &line, const String &marker, const String &context="")
Definition Report.hpp:38
ReportTypes getType() const
Returns the type of this report.
Definition Report.hpp:53
void takeHints(Vector< String > &&hints)
Moves the specified hints into this report.
Definition Report.hpp:50
bool hasLine() const
Returns true if this report has a line with line marker.
Definition Report.hpp:73
const Vector< String > & getHints() const
Returns the list of optional hints of the report.
Definition Report.hpp:68
Report(const ReportTypes type, const String &message, const String &context="")
Definition Report.hpp:36
ReportTypes mType
Definition Report.hpp:76
String mLine
Definition Report.hpp:79
const String & getMessage() const
Returns the message string.
Definition Report.hpp:59
Definition AST.hpp:33
ReportTypes
Report types enumeration.
Definition Report.hpp:18
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25