1 //====-- UserSettingsController.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_CORE_USERSETTINGSCONTROLLER_H 10 #define LLDB_CORE_USERSETTINGSCONTROLLER_H 11 12 #include "lldb/Interpreter/OptionValueProperties.h" 13 #include "lldb/Utility/Status.h" 14 #include "lldb/lldb-forward.h" 15 #include "lldb/lldb-private-enumerations.h" 16 17 #include "llvm/ADT/StringRef.h" 18 19 #include <vector> 20 21 #include <cstddef> 22 #include <cstdint> 23 24 namespace lldb_private { 25 class CommandInterpreter; 26 class ExecutionContext; 27 class Property; 28 class Stream; 29 } 30 31 namespace lldb_private { 32 33 class Properties { 34 public: 35 Properties() = default; 36 37 Properties(const lldb::OptionValuePropertiesSP &collection_sp) 38 : m_collection_sp(collection_sp) {} 39 40 virtual ~Properties() = default; 41 42 virtual lldb::OptionValuePropertiesSP GetValueProperties() const { 43 // This function is virtual in case subclasses want to lazily implement 44 // creating the properties. 45 return m_collection_sp; 46 } 47 48 virtual lldb::OptionValueSP GetPropertyValue(const ExecutionContext *exe_ctx, 49 llvm::StringRef property_path, 50 Status &error) const; 51 52 virtual Status SetPropertyValue(const ExecutionContext *exe_ctx, 53 VarSetOperationType op, 54 llvm::StringRef property_path, 55 llvm::StringRef value); 56 57 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx, 58 Stream &strm, llvm::StringRef property_path, 59 uint32_t dump_mask, bool is_json = false); 60 61 virtual void DumpAllPropertyValues(const ExecutionContext *exe_ctx, 62 Stream &strm, uint32_t dump_mask, 63 bool is_json = false); 64 65 virtual void DumpAllDescriptions(CommandInterpreter &interpreter, 66 Stream &strm) const; 67 68 size_t Apropos(llvm::StringRef keyword, 69 std::vector<const Property *> &matching_properties) const; 70 71 // We sometimes need to introduce a setting to enable experimental features, 72 // but then we don't want the setting for these to cause errors when the 73 // setting goes away. Add a sub-topic of the settings using this 74 // experimental name, and two things will happen. One is that settings that 75 // don't find the name will not be treated as errors. Also, if you decide to 76 // keep the settings just move them into the containing properties, and we 77 // will auto-forward the experimental settings to the real one. 78 static llvm::StringRef GetExperimentalSettingsName(); 79 80 static bool IsSettingExperimental(llvm::StringRef setting); 81 82 template <typename T> 83 T GetPropertyAtIndexAs(uint32_t idx, T default_value, 84 const ExecutionContext *exe_ctx = nullptr) const { 85 return m_collection_sp->GetPropertyAtIndexAs<T>(idx, exe_ctx) 86 .value_or(default_value); 87 } 88 89 template <typename T, typename U = typename std::remove_pointer<T>::type, 90 std::enable_if_t<std::is_pointer_v<T>, bool> = true> 91 const U * 92 GetPropertyAtIndexAs(uint32_t idx, 93 const ExecutionContext *exe_ctx = nullptr) const { 94 return m_collection_sp->GetPropertyAtIndexAs<T>(idx, exe_ctx); 95 } 96 97 template <typename T> 98 bool SetPropertyAtIndex(uint32_t idx, T t, 99 const ExecutionContext *exe_ctx = nullptr) const { 100 return m_collection_sp->SetPropertyAtIndex<T>(idx, t, exe_ctx); 101 } 102 103 protected: 104 lldb::OptionValuePropertiesSP m_collection_sp; 105 }; 106 107 } // namespace lldb_private 108 109 #endif // LLDB_CORE_USERSETTINGSCONTROLLER_H 110