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