1/*
2 * Log.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_LOG_H
9#define XSC_LOG_H
10
11
12#include "IndentHandler.h"
13#include "Report.h"
14#include <vector>
15#include <string>
16
17
18namespace Xsc
19{
20
21
22/* ===== Public classes ===== */
23
24//! Log base class.
25class XSC_EXPORT Log
26{
27
28 public:
29
30 //! Submits the specified report.
31 virtual void SubmitReport(const Report& report) = 0;
32
33 //! Sets the next indentation string. By default two spaces.
34 inline void SetIndent(const std::string& indent)
35 {
36 indentHandler_.SetIndent(indent);
37 }
38
39 //! Increments the indentation.
40 inline void IncIndent()
41 {
42 indentHandler_.IncIndent();
43 }
44
45 //! Decrements the indentation.
46 inline void DecIndent()
47 {
48 indentHandler_.DecIndent();
49 }
50
51 protected:
52
53 Log() = default;
54
55 //! Returns the current full indentation string.
56 inline const std::string& FullIndent() const
57 {
58 return indentHandler_.FullIndent();
59 }
60
61 private:
62
63 IndentHandler indentHandler_;
64
65};
66
67//! Standard output log (uses std::cout to submit a report).
68class XSC_EXPORT StdLog : public Log
69{
70
71 public:
72
73 //! Implements the base class interface.
74 void SubmitReport(const Report& report) override;
75
76 //! Prints all submitted reports to the standard output.
77 void PrintAll(bool verbose = true);
78
79 private:
80
81 struct IndentReport
82 {
83 std::string indent;
84 Report report;
85 };
86
87 using IndentReportList = std::vector<IndentReport>;
88
89 void PrintReport(const IndentReport& r, bool verbose);
90 void PrintAndClearReports(IndentReportList& reports, bool verbose, const std::string& headline = "");
91
92 IndentReportList infos_;
93 IndentReportList warnings_;
94 IndentReportList errors_;
95
96};
97
98
99} // /namespace Xsc
100
101
102#endif
103
104
105
106// ================================================================================