LLDB mainline
OptionValueProperties.h
Go to the documentation of this file.
1//===-- OptionValueProperties.h ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H
10#define LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H
11
12#include <vector>
13
18
19namespace lldb_private {
20class Properties;
21
23 : public Cloneable<OptionValueProperties, OptionValue>,
24 public std::enable_shared_from_this<OptionValueProperties> {
25public:
27
28 OptionValueProperties(llvm::StringRef name);
29
30 ~OptionValueProperties() override = default;
31
32 Type GetType() const override { return eTypeProperties; }
33
34 void Clear() override;
35
37 CreateLocalCopy(const Properties &global_properties);
38
40 DeepCopy(const lldb::OptionValueSP &new_parent) const override;
41
42 Status
43 SetValueFromString(llvm::StringRef value,
45
46 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
47 uint32_t dump_mask) override;
48
49 llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
50
51 llvm::StringRef GetName() const override { return m_name; }
52
53 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
54 Stream &strm, llvm::StringRef property_path,
55 uint32_t dump_mask, bool is_json = false);
56
57 virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
58 Stream &strm) const;
59
60 void Apropos(llvm::StringRef keyword,
61 std::vector<const Property *> &matching_properties) const;
62
63 void Initialize(const PropertyDefinitions &setting_definitions);
64
65 // Subclass specific functions
66
67 // Get the index of a property given its exact name in this property
68 // collection, "name" can't be a path to a property path that refers to a
69 // property within a property
70 virtual size_t GetPropertyIndex(llvm::StringRef name) const;
71
72 // Get a property by exact name exists in this property collection, name can
73 // not be a path to a property path that refers to a property within a
74 // property
75 virtual const Property *
76 GetProperty(llvm::StringRef name,
77 const ExecutionContext *exe_ctx = nullptr) const;
78
79 virtual const Property *
81 const ExecutionContext *exe_ctx = nullptr) const {
83 }
84
85 // Property can be a property path like
86 // "target.process.extra-startup-command"
87 virtual const Property *
89 llvm::StringRef property_path) const;
90
92 GetPropertyValueAtIndex(size_t idx, const ExecutionContext *exe_ctx) const;
93
95 llvm::StringRef key) const;
96
98 llvm::StringRef name,
99 Status &error) const override;
100
102 llvm::StringRef path, llvm::StringRef value) override;
103
104 bool
105 GetPropertyAtIndexAsArgs(size_t idx, Args &args,
106 const ExecutionContext *exe_ctx = nullptr) const;
107
108 bool SetPropertyAtIndexFromArgs(size_t idx, const Args &args,
109 const ExecutionContext *exe_ctx = nullptr);
110
112 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
113
115 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
116
118 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
119
121 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
122
124 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
125
127 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
128
130 size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
131
132 void AppendProperty(llvm::StringRef name, llvm::StringRef desc,
133 bool is_global, const lldb::OptionValueSP &value_sp);
134
136 llvm::StringRef name);
137
138 void SetValueChangedCallback(size_t property_idx,
139 std::function<void()> callback);
140
141 template <typename T>
142 auto GetPropertyAtIndexAs(size_t idx,
143 const ExecutionContext *exe_ctx = nullptr) const {
144 if (const Property *property = GetPropertyAtIndex(idx, exe_ctx)) {
145 if (OptionValue *value = property->GetValue().get())
146 return value->GetValueAs<T>();
147 }
148 if constexpr (std::is_pointer_v<T>)
149 return T{nullptr};
150 else
151 return std::optional<T>{std::nullopt};
152 }
153
154 template <typename T>
155 bool SetPropertyAtIndex(size_t idx, T t,
156 const ExecutionContext *exe_ctx = nullptr) const {
157 if (const Property *property = GetPropertyAtIndex(idx, exe_ctx)) {
158 if (OptionValue *value = property->GetValue().get()) {
159 value->SetValueAs(t);
160 return true;
161 }
162 }
163 return false;
164 }
165
166protected:
168 assert(idx < m_properties.size() && "invalid property index");
169 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
170 }
171
172 const Property *ProtectedGetPropertyAtIndex(size_t idx) const {
173 assert(idx < m_properties.size() && "invalid property index");
174 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
175 }
176
177 std::string m_name;
178 std::vector<Property> m_properties;
179 llvm::StringMap<size_t> m_name_to_index;
180};
181
182} // namespace lldb_private
183
184#endif // LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
Definition: Args.h:33
A class that implements CRTP-based "virtual constructor" idiom.
Definition: Cloneable.h:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void AppendProperty(llvm::StringRef name, llvm::StringRef desc, bool is_global, const lldb::OptionValueSP &value_sp)
llvm::StringMap< size_t > m_name_to_index
Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, llvm::StringRef path, llvm::StringRef value) override
void Initialize(const PropertyDefinitions &setting_definitions)
OptionValueFileSpec * GetPropertyAtIndexAsOptionValueFileSpec(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
auto GetPropertyAtIndexAs(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
void Apropos(llvm::StringRef keyword, std::vector< const Property * > &matching_properties) const
lldb::OptionValueSP DeepCopy(const lldb::OptionValueSP &new_parent) const override
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
virtual void DumpAllDescriptions(CommandInterpreter &interpreter, Stream &strm) const
OptionValueFileSpecList * GetPropertyAtIndexAsOptionValueFileSpecList(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
Property * ProtectedGetPropertyAtIndex(size_t idx)
OptionValueString * GetPropertyAtIndexAsOptionValueString(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
bool SetPropertyAtIndex(size_t idx, T t, const ExecutionContext *exe_ctx=nullptr) const
virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx, Stream &strm, llvm::StringRef property_path, uint32_t dump_mask, bool is_json=false)
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override
OptionValueDictionary * GetPropertyAtIndexAsOptionValueDictionary(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
llvm::StringRef GetName() const override
static lldb::OptionValuePropertiesSP CreateLocalCopy(const Properties &global_properties)
lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx, llvm::StringRef name, Status &error) const override
void SetValueChangedCallback(size_t property_idx, std::function< void()> callback)
const Property * ProtectedGetPropertyAtIndex(size_t idx) const
bool SetPropertyAtIndexFromArgs(size_t idx, const Args &args, const ExecutionContext *exe_ctx=nullptr)
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
virtual const Property * GetPropertyAtPath(const ExecutionContext *exe_ctx, llvm::StringRef property_path) const
virtual const Property * GetPropertyAtIndex(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx, llvm::StringRef key) const
lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx, llvm::StringRef name)
virtual lldb::OptionValueSP GetPropertyValueAtIndex(size_t idx, const ExecutionContext *exe_ctx) const
OptionValueUInt64 * GetPropertyAtIndexAsOptionValueUInt64(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
OptionValuePathMappings * GetPropertyAtIndexAsOptionValuePathMappings(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
OptionValueSInt64 * GetPropertyAtIndexAsOptionValueSInt64(size_t idx, const ExecutionContext *exe_ctx=nullptr) const
virtual const Property * GetProperty(llvm::StringRef name, const ExecutionContext *exe_ctx=nullptr) const
bool GetPropertyAtIndexAsArgs(size_t idx, Args &args, const ExecutionContext *exe_ctx=nullptr) const
virtual size_t GetPropertyIndex(llvm::StringRef name) const
~OptionValueProperties() override=default
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
A class that represents a running process on the host machine.
llvm::ArrayRef< PropertyDefinition > PropertyDefinitions
Definition: Property.h:33
VarSetOperationType
Settable state variable types.
std::shared_ptr< lldb_private::OptionValueProperties > OptionValuePropertiesSP
Definition: lldb-forward.h:383
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
Definition: lldb-forward.h:380