/src/CMake/Source/cmExecutionStatus.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 <cmConfigure.h> // IWYU pragma: keep |
6 | | |
7 | | #include <string> |
8 | | #include <vector> |
9 | | |
10 | | #include <cm/optional> |
11 | | |
12 | | class cmMakefile; |
13 | | |
14 | | /** \class cmExecutionStatus |
15 | | * \brief Superclass for all command status classes |
16 | | * |
17 | | * when a command is involked it may set values on a command status instance |
18 | | */ |
19 | | class cmExecutionStatus |
20 | | { |
21 | | public: |
22 | | cmExecutionStatus(cmMakefile& makefile) |
23 | 0 | : Makefile(makefile) |
24 | 0 | , Error("unknown error.") |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | 0 | cmMakefile& GetMakefile() { return this->Makefile; } |
29 | | |
30 | 0 | void SetError(std::string const& e) { this->Error = e; } |
31 | 0 | std::string const& GetError() const { return this->Error; } |
32 | | |
33 | | void SetReturnInvoked() |
34 | 0 | { |
35 | 0 | this->Variables.clear(); |
36 | 0 | this->ReturnInvoked = true; |
37 | 0 | } |
38 | | void SetReturnInvoked(std::vector<std::string> variables) |
39 | 0 | { |
40 | 0 | this->Variables = std::move(variables); |
41 | 0 | this->ReturnInvoked = true; |
42 | 0 | } |
43 | 0 | bool GetReturnInvoked() const { return this->ReturnInvoked; } |
44 | | std::vector<std::string> const& GetReturnVariables() const |
45 | 0 | { |
46 | 0 | return this->Variables; |
47 | 0 | } |
48 | | |
49 | 0 | void SetBreakInvoked() { this->BreakInvoked = true; } |
50 | 0 | bool GetBreakInvoked() const { return this->BreakInvoked; } |
51 | | |
52 | 0 | void SetContinueInvoked() { this->ContinueInvoked = true; } |
53 | 0 | bool GetContinueInvoked() const { return this->ContinueInvoked; } |
54 | | |
55 | 0 | void SetNestedError() { this->NestedError = true; } |
56 | 0 | bool GetNestedError() const { return this->NestedError; } |
57 | | |
58 | 0 | void SetExitCode(int code) noexcept { this->ExitCode = code; } |
59 | 0 | bool HasExitCode() const noexcept { return this->ExitCode.has_value(); } |
60 | 0 | void CleanExitCode() noexcept { this->ExitCode.reset(); } |
61 | 0 | int GetExitCode() const noexcept { return this->ExitCode.value_or(-1); } |
62 | | |
63 | | private: |
64 | | cmMakefile& Makefile; |
65 | | std::string Error; |
66 | | bool ReturnInvoked = false; |
67 | | bool BreakInvoked = false; |
68 | | bool ContinueInvoked = false; |
69 | | bool NestedError = false; |
70 | | cm::optional<int> ExitCode; |
71 | | std::vector<std::string> Variables; |
72 | | }; |