/src/CMake/Source/cmConfigureLog.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include <cstddef> |
6 | | #include <map> |
7 | | #include <memory> |
8 | | #include <string> |
9 | | #include <vector> |
10 | | |
11 | | #include <cm/string_view> |
12 | | |
13 | | #include "cmsys/FStream.hxx" |
14 | | |
15 | | namespace Json { |
16 | | class StreamWriter; |
17 | | } |
18 | | |
19 | | class cmMakefile; |
20 | | |
21 | | class cmConfigureLog |
22 | | { |
23 | | public: |
24 | | /** Construct with the log directory and a sorted list of enabled log |
25 | | versions. The latest log version will be enabled regardless. */ |
26 | | cmConfigureLog(std::string logDir, std::vector<unsigned int> logVersions); |
27 | | ~cmConfigureLog(); |
28 | | |
29 | | /** Return true if at least one of the log versions in the given sorted |
30 | | list is enabled. */ |
31 | | bool IsAnyLogVersionEnabled(std::vector<unsigned int> const& v) const; |
32 | | |
33 | | void EnsureInit(); |
34 | | |
35 | | void BeginEvent(std::string const& kind, cmMakefile const& mf); |
36 | | void EndEvent(); |
37 | | |
38 | | void BeginArray(); |
39 | | void NextArrayElement(); |
40 | | void EndArray(); |
41 | | |
42 | | void BeginObject(cm::string_view key); |
43 | | void EndObject(); |
44 | | |
45 | | // TODO other value types |
46 | | void WriteValue(cm::string_view key, std::nullptr_t); |
47 | | void WriteValue(cm::string_view key, bool value); |
48 | | void WriteValue(cm::string_view key, int value); |
49 | | void WriteValue(cm::string_view key, std::string const& value); |
50 | | void WriteValue(cm::string_view key, std::vector<std::string> const& list); |
51 | | void WriteValue(cm::string_view key, |
52 | | std::map<std::string, std::string> const& map); |
53 | | |
54 | | void WriteTextBlock(cm::string_view key, cm::string_view text); |
55 | | void WriteLiteralTextBlock(cm::string_view key, cm::string_view text); |
56 | | |
57 | | void WriteLiteralTextBlock(cm::string_view key, std::string const& text) |
58 | 0 | { |
59 | 0 | this->WriteLiteralTextBlock(key, cm::string_view{ text }); |
60 | 0 | } |
61 | | |
62 | | private: |
63 | | std::string LogDir; |
64 | | std::vector<unsigned int> LogVersions; |
65 | | cmsys::ofstream Stream; |
66 | | unsigned Indent = 0; |
67 | | bool Opened = false; |
68 | | |
69 | | std::unique_ptr<Json::StreamWriter> Encoder; |
70 | | |
71 | | void WriteBacktrace(cmMakefile const& mf); |
72 | | void WriteChecks(cmMakefile const& mf); |
73 | | |
74 | | cmsys::ofstream& BeginLine(); |
75 | | void EndLine(); |
76 | | void WriteEscape(unsigned char c); |
77 | | }; |