blob: 1af14a4980ed9837c8224c0503e3aa50eb2239fe [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===-- 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
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02009#ifndef LLDB_INTERPRETER_OPTIONVALUEBOOLEAN_H
10#define LLDB_INTERPRETER_OPTIONVALUEBOOLEAN_H
Andrew Walbran3d2c1972020-04-07 12:24:26 +010011
12#include "lldb/Interpreter/OptionValue.h"
13
14namespace lldb_private {
15
16class OptionValueBoolean : public OptionValue {
17public:
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
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020040 void Clear() override {
Andrew Walbran3d2c1972020-04-07 12:24:26 +010041 m_current_value = m_default_value;
42 m_value_was_set = false;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010043 }
44
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020045 void AutoComplete(CommandInterpreter &interpreter,
46 CompletionRequest &request) override;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010047
48 // Subclass specific functions
49
50 /// Convert to bool operator.
51 ///
52 /// This allows code to check a OptionValueBoolean in conditions.
53 ///
54 /// \code
55 /// OptionValueBoolean bool_value(...);
56 /// if (bool_value)
57 /// { ...
58 /// \endcode
59 ///
60 /// \return
61 /// /b True this object contains a valid namespace decl, \b
62 /// false otherwise.
63 explicit operator bool() const { return m_current_value; }
64
65 const bool &operator=(bool b) {
66 m_current_value = b;
67 return m_current_value;
68 }
69
70 bool GetCurrentValue() const { return m_current_value; }
71
72 bool GetDefaultValue() const { return m_default_value; }
73
74 void SetCurrentValue(bool value) { m_current_value = value; }
75
76 void SetDefaultValue(bool value) { m_default_value = value; }
77
78 lldb::OptionValueSP DeepCopy() const override;
79
80protected:
81 bool m_current_value;
82 bool m_default_value;
83};
84
85} // namespace lldb_private
86
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020087#endif // LLDB_INTERPRETER_OPTIONVALUEBOOLEAN_H