cmDebuggerVariables.h 3.2 KB

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