1 //===-- 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 
9 #ifndef LLDB_INTERPRETER_OPTIONVALUEENUMERATION_H
10 #define LLDB_INTERPRETER_OPTIONVALUEENUMERATION_H
11 
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 
20 namespace lldb_private {
21 
22 class OptionValueEnumeration
23     : public Cloneable<OptionValueEnumeration, OptionValue> {
24 public:
25   typedef int64_t enum_type;
26   struct EnumeratorInfo {
27     enum_type value;
28     const char *description;
29   };
30   typedef UniqueCStringMap<EnumeratorInfo> EnumerationMap;
31   typedef EnumerationMap::Entry EnumerationMapEntry;
32 
33   OptionValueEnumeration(const OptionEnumValues &enumerators, enum_type value);
34 
35   ~OptionValueEnumeration() override = default;
36 
37   // Virtual subclass pure virtual overrides
38 
39   OptionValue::Type GetType() const override { return eTypeEnum; }
40 
41   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
42                  uint32_t dump_mask) override;
43 
44   Status
45   SetValueFromString(llvm::StringRef value,
46                      VarSetOperationType op = eVarSetOperationAssign) override;
47 
48   void Clear() override {
49     m_current_value = m_default_value;
50     m_value_was_set = false;
51   }
52 
53   void AutoComplete(CommandInterpreter &interpreter,
54                     CompletionRequest &request) override;
55 
56   // Subclass specific functions
57 
58   enum_type operator=(enum_type value) {
59     m_current_value = value;
60     return m_current_value;
61   }
62 
63   enum_type GetCurrentValue() const { return m_current_value; }
64 
65   enum_type GetDefaultValue() const { return m_default_value; }
66 
67   void SetCurrentValue(enum_type value) { m_current_value = value; }
68 
69   void SetDefaultValue(enum_type value) { m_default_value = value; }
70 
71 protected:
72   void SetEnumerations(const OptionEnumValues &enumerators);
73 
74   enum_type m_current_value;
75   enum_type m_default_value;
76   EnumerationMap m_enumerations;
77 };
78 
79 } // namespace lldb_private
80 
81 #endif // LLDB_INTERPRETER_OPTIONVALUEENUMERATION_H
82