blob: 12c6473c7f1c2138616a9cc74b9cfbf10e0fc31b [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===-- OptionValueEnumeration.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_OPTIONVALUEENUMERATION_H
10#define LLDB_INTERPRETER_OPTIONVALUEENUMERATION_H
Andrew Walbran3d2c1972020-04-07 12:24:26 +010011
12#include "lldb/Core/UniqueCStringMap.h"
13#include "lldb/Interpreter/OptionValue.h"
14#include "lldb/Utility/ConstString.h"
15#include "lldb/Utility/Status.h"
16#include "lldb/Utility/Stream.h"
17#include "lldb/Utility/StreamString.h"
18#include "lldb/lldb-private-types.h"
19
20namespace lldb_private {
21
22class OptionValueEnumeration : public OptionValue {
23public:
24 typedef int64_t enum_type;
25 struct EnumeratorInfo {
26 enum_type value;
27 const char *description;
28 };
29 typedef UniqueCStringMap<EnumeratorInfo> EnumerationMap;
30 typedef EnumerationMap::Entry EnumerationMapEntry;
31
32 OptionValueEnumeration(const OptionEnumValues &enumerators, enum_type value);
33
34 ~OptionValueEnumeration() override;
35
36 // Virtual subclass pure virtual overrides
37
38 OptionValue::Type GetType() const override { return eTypeEnum; }
39
40 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
41 uint32_t dump_mask) override;
42
43 Status
44 SetValueFromString(llvm::StringRef value,
45 VarSetOperationType op = eVarSetOperationAssign) override;
46 Status
47 SetValueFromString(const char *,
48 VarSetOperationType = eVarSetOperationAssign) = delete;
49
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020050 void Clear() override {
Andrew Walbran3d2c1972020-04-07 12:24:26 +010051 m_current_value = m_default_value;
52 m_value_was_set = false;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010053 }
54
55 lldb::OptionValueSP DeepCopy() const override;
56
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020057 void AutoComplete(CommandInterpreter &interpreter,
58 CompletionRequest &request) override;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010059
60 // Subclass specific functions
61
62 enum_type operator=(enum_type value) {
63 m_current_value = value;
64 return m_current_value;
65 }
66
67 enum_type GetCurrentValue() const { return m_current_value; }
68
69 enum_type GetDefaultValue() const { return m_default_value; }
70
71 void SetCurrentValue(enum_type value) { m_current_value = value; }
72
73 void SetDefaultValue(enum_type value) { m_default_value = value; }
74
75protected:
76 void SetEnumerations(const OptionEnumValues &enumerators);
77
78 enum_type m_current_value;
79 enum_type m_default_value;
80 EnumerationMap m_enumerations;
81};
82
83} // namespace lldb_private
84
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020085#endif // LLDB_INTERPRETER_OPTIONVALUEENUMERATION_H