/src/CMake/Source/cmDebuggerVariables.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 <atomic> |
8 | | #include <cstdint> |
9 | | #include <functional> |
10 | | #include <memory> |
11 | | #include <string> |
12 | | #include <utility> |
13 | | #include <vector> |
14 | | |
15 | | #include <cm3p/cppdap/types.h> // IWYU pragma: keep |
16 | | |
17 | | namespace cmDebugger { |
18 | | class cmDebuggerVariablesManager; |
19 | | } |
20 | | |
21 | | namespace dap { |
22 | | struct Variable; |
23 | | } |
24 | | |
25 | | namespace cmDebugger { |
26 | | |
27 | | struct cmDebuggerVariableEntry |
28 | | { |
29 | | cmDebuggerVariableEntry() |
30 | | : cmDebuggerVariableEntry("", "", "") |
31 | 0 | { |
32 | 0 | } |
33 | | cmDebuggerVariableEntry(std::string name, std::string value, |
34 | | std::string type) |
35 | | : Name(std::move(name)) |
36 | | , Value(std::move(value)) |
37 | | , Type(std::move(type)) |
38 | 0 | { |
39 | 0 | } |
40 | | cmDebuggerVariableEntry(std::string name, std::string value) |
41 | 0 | : Name(std::move(name)) |
42 | 0 | , Value(std::move(value)) |
43 | 0 | , Type("string") |
44 | 0 | { |
45 | 0 | } |
46 | | cmDebuggerVariableEntry(std::string name, char const* value) |
47 | 0 | : Name(std::move(name)) |
48 | 0 | , Value(value ? value : "") |
49 | 0 | , Type("string") |
50 | 0 | { |
51 | 0 | } |
52 | | cmDebuggerVariableEntry(std::string name, bool value) |
53 | 0 | : Name(std::move(name)) |
54 | 0 | , Value(value ? "TRUE" : "FALSE") |
55 | 0 | , Type("bool") |
56 | 0 | { |
57 | 0 | } |
58 | | cmDebuggerVariableEntry(std::string name, int64_t value) |
59 | 0 | : Name(std::move(name)) |
60 | 0 | , Value(std::to_string(value)) |
61 | 0 | , Type("int") |
62 | 0 | { |
63 | 0 | } |
64 | | cmDebuggerVariableEntry(std::string name, int value) |
65 | | : Name(std::move(name)) |
66 | | , Value(std::to_string(value)) |
67 | | , Type("int") |
68 | 0 | { |
69 | 0 | } |
70 | | std::string const Name; |
71 | | std::string const Value; |
72 | | std::string const Type; |
73 | | }; |
74 | | |
75 | | class cmDebuggerVariables |
76 | | { |
77 | | static std::atomic<int64_t> NextId; |
78 | | int64_t Id; |
79 | | std::string Name; |
80 | | std::string Value; |
81 | | |
82 | | std::function<std::vector<cmDebuggerVariableEntry>()> GetKeyValuesFunction; |
83 | | std::vector<std::shared_ptr<cmDebuggerVariables>> SubVariables; |
84 | | bool IgnoreEmptyStringEntries = false; |
85 | | bool EnableSorting = true; |
86 | | |
87 | | virtual dap::array<dap::Variable> HandleVariablesRequest(); |
88 | | friend class cmDebuggerVariablesManager; |
89 | | |
90 | | protected: |
91 | | bool const SupportsVariableType; |
92 | | std::shared_ptr<cmDebuggerVariablesManager> VariablesManager; |
93 | | void EnumerateSubVariablesIfAny( |
94 | | dap::array<dap::Variable>& toBeReturned) const; |
95 | | void ClearSubVariables(); |
96 | | |
97 | | public: |
98 | | cmDebuggerVariables( |
99 | | std::shared_ptr<cmDebuggerVariablesManager> variablesManager, |
100 | | std::string name, bool supportsVariableType); |
101 | | cmDebuggerVariables( |
102 | | std::shared_ptr<cmDebuggerVariablesManager> variablesManager, |
103 | | std::string name, bool supportsVariableType, |
104 | | std::function<std::vector<cmDebuggerVariableEntry>()> getKeyValuesFunc); |
105 | 0 | int64_t GetId() const noexcept { return this->Id; } |
106 | 0 | std::string GetName() const noexcept { return this->Name; } |
107 | 0 | std::string GetValue() const noexcept { return this->Value; } |
108 | 0 | void SetValue(std::string const& value) noexcept { this->Value = value; } |
109 | | void AddSubVariables(std::shared_ptr<cmDebuggerVariables> const& variables); |
110 | | void SetIgnoreEmptyStringEntries(bool value) noexcept |
111 | 0 | { |
112 | 0 | this->IgnoreEmptyStringEntries = value; |
113 | 0 | } |
114 | 0 | void SetEnableSorting(bool value) noexcept { this->EnableSorting = value; } |
115 | | virtual ~cmDebuggerVariables(); |
116 | | }; |
117 | | |
118 | | } // namespace cmDebugger |