1 //===-- OptionValueBoolean.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 liblldb_OptionValueBoolean_h_ 10 #define liblldb_OptionValueBoolean_h_ 11 12 #include "lldb/Interpreter/OptionValue.h" 13 14 namespace lldb_private { 15 16 class OptionValueBoolean : public OptionValue { 17 public: 18 OptionValueBoolean(bool value) 19 : OptionValue(), m_current_value(value), m_default_value(value) {} 20 OptionValueBoolean(bool current_value, bool default_value) 21 : OptionValue(), m_current_value(current_value), 22 m_default_value(default_value) {} 23 24 ~OptionValueBoolean() override {} 25 26 // Virtual subclass pure virtual overrides 27 28 OptionValue::Type GetType() const override { return eTypeBoolean; } 29 30 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 31 uint32_t dump_mask) override; 32 33 Status 34 SetValueFromString(llvm::StringRef value, 35 VarSetOperationType op = eVarSetOperationAssign) override; 36 Status 37 SetValueFromString(const char *, 38 VarSetOperationType = eVarSetOperationAssign) = delete; 39 40 bool Clear() override { 41 m_current_value = m_default_value; 42 m_value_was_set = false; 43 return true; 44 } 45 46 void AutoComplete(CommandInterpreter &interpreter, 47 CompletionRequest &request) override; 48 49 // Subclass specific functions 50 51 /// Convert to bool operator. 52 /// 53 /// This allows code to check a OptionValueBoolean in conditions. 54 /// 55 /// \code 56 /// OptionValueBoolean bool_value(...); 57 /// if (bool_value) 58 /// { ... 59 /// \endcode 60 /// 61 /// \return 62 /// /b True this object contains a valid namespace decl, \b 63 /// false otherwise. 64 explicit operator bool() const { return m_current_value; } 65 66 const bool &operator=(bool b) { 67 m_current_value = b; 68 return m_current_value; 69 } 70 71 bool GetCurrentValue() const { return m_current_value; } 72 73 bool GetDefaultValue() const { return m_default_value; } 74 75 void SetCurrentValue(bool value) { m_current_value = value; } 76 77 void SetDefaultValue(bool value) { m_default_value = value; } 78 79 lldb::OptionValueSP DeepCopy() const override; 80 81 protected: 82 bool m_current_value; 83 bool m_default_value; 84 }; 85 86 } // namespace lldb_private 87 88 #endif // liblldb_OptionValueBoolean_h_ 89