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 : public OptionValue {
23 public:
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 
50   void Clear() override {
51     m_current_value = m_default_value;
52     m_value_was_set = false;
53   }
54 
55   lldb::OptionValueSP DeepCopy() const override;
56 
57   void AutoComplete(CommandInterpreter &interpreter,
58                     CompletionRequest &request) override;
59 
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 
75 protected:
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 
85 #endif // LLDB_INTERPRETER_OPTIONVALUEENUMERATION_H
86