CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmDebuggerVariables.h
blobeaaf2a8f486af5d0b7cd0e68e451da3f246135a4
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <atomic>
8 #include <cstdint>
9 #include <functional>
10 #include <memory>
11 #include <string>
12 #include <utility>
13 #include <vector>
15 #include <cm3p/cppdap/types.h> // IWYU pragma: keep
17 namespace cmDebugger {
18 class cmDebuggerVariablesManager;
21 namespace dap {
22 struct Variable;
25 namespace cmDebugger {
27 struct cmDebuggerVariableEntry
29 cmDebuggerVariableEntry()
30 : cmDebuggerVariableEntry("", "", "")
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))
40 cmDebuggerVariableEntry(std::string name, std::string value)
41 : Name(std::move(name))
42 , Value(std::move(value))
43 , Type("string")
46 cmDebuggerVariableEntry(std::string name, const char* value)
47 : Name(std::move(name))
48 , Value(value == nullptr ? "" : value)
49 , Type("string")
52 cmDebuggerVariableEntry(std::string name, bool value)
53 : Name(std::move(name))
54 , Value(value ? "TRUE" : "FALSE")
55 , Type("bool")
58 cmDebuggerVariableEntry(std::string name, int64_t value)
59 : Name(std::move(name))
60 , Value(std::to_string(value))
61 , Type("int")
64 cmDebuggerVariableEntry(std::string name, int value)
65 : Name(std::move(name))
66 , Value(std::to_string(value))
67 , Type("int")
70 std::string const Name;
71 std::string const Value;
72 std::string const Type;
75 class cmDebuggerVariables
77 static std::atomic<int64_t> NextId;
78 int64_t Id;
79 std::string Name;
80 std::string Value;
82 std::function<std::vector<cmDebuggerVariableEntry>()> GetKeyValuesFunction;
83 std::vector<std::shared_ptr<cmDebuggerVariables>> SubVariables;
84 bool IgnoreEmptyStringEntries = false;
85 bool EnableSorting = true;
87 virtual dap::array<dap::Variable> HandleVariablesRequest();
88 friend class cmDebuggerVariablesManager;
90 protected:
91 const bool SupportsVariableType;
92 std::shared_ptr<cmDebuggerVariablesManager> VariablesManager;
93 void EnumerateSubVariablesIfAny(
94 dap::array<dap::Variable>& toBeReturned) const;
95 void ClearSubVariables();
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 inline int64_t GetId() const noexcept { return this->Id; }
106 inline std::string GetName() const noexcept { return this->Name; }
107 inline std::string GetValue() const noexcept { return this->Value; }
108 inline void SetValue(std::string const& value) noexcept
110 this->Value = value;
112 void AddSubVariables(std::shared_ptr<cmDebuggerVariables> const& variables);
113 inline void SetIgnoreEmptyStringEntries(bool value) noexcept
115 this->IgnoreEmptyStringEntries = value;
117 inline void SetEnableSorting(bool value) noexcept
119 this->EnableSorting = value;
121 virtual ~cmDebuggerVariables();
124 } // namespace cmDebugger