1 //===-- Property.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_PROPERTY_H
10 #define LLDB_INTERPRETER_PROPERTY_H
11 
12 #include "lldb/Interpreter/OptionValue.h"
13 #include "lldb/Utility/Flags.h"
14 #include "lldb/lldb-defines.h"
15 #include "lldb/lldb-private-types.h"
16 
17 #include <string>
18 
19 namespace lldb_private {
20 
21 // A structure that can be used to create a global table for all properties.
22 // Property class instances can be constructed using one of these.
23 struct PropertyDefinition {
24   const char *name;
25   OptionValue::Type type;
26   bool global; // false == this setting is a global setting by default
27   uintptr_t default_uint_value;
28   const char *default_cstr_value;
29   OptionEnumValues enum_values;
30   const char *description;
31 };
32 
33 using PropertyDefinitions = llvm::ArrayRef<PropertyDefinition>;
34 
35 class Property {
36 public:
37   Property(const PropertyDefinition &definition);
38 
39   Property(llvm::StringRef name, llvm::StringRef desc, bool is_global,
40            const lldb::OptionValueSP &value_sp);
41 
42   llvm::StringRef GetName() const { return m_name; }
43   llvm::StringRef GetDescription() const { return m_description; }
44 
45   const lldb::OptionValueSP &GetValue() const { return m_value_sp; }
46 
47   void SetOptionValue(const lldb::OptionValueSP &value_sp) {
48     m_value_sp = value_sp;
49   }
50 
51   bool IsValid() const { return (bool)m_value_sp; }
52 
53   bool IsGlobal() const { return m_is_global; }
54 
55   void Dump(const ExecutionContext *exe_ctx, Stream &strm,
56             uint32_t dump_mask) const;
57 
58   bool DumpQualifiedName(Stream &strm) const;
59 
60   void DumpDescription(CommandInterpreter &interpreter, Stream &strm,
61                        uint32_t output_width,
62                        bool display_qualified_name) const;
63 
64   void SetValueChangedCallback(std::function<void()> callback);
65 
66 protected:
67   std::string m_name;
68   std::string m_description;
69   lldb::OptionValueSP m_value_sp;
70   bool m_is_global;
71 };
72 
73 } // namespace lldb_private
74 
75 #endif // LLDB_INTERPRETER_PROPERTY_H
76