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 liblldb_OptionValueEnumeration_h_
10 #define liblldb_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   bool Clear() override {
51     m_current_value = m_default_value;
52     m_value_was_set = false;
53     return true;
54   }
55 
56   lldb::OptionValueSP DeepCopy() const override;
57 
58   void AutoComplete(CommandInterpreter &interpreter,
59                     CompletionRequest &request) override;
60 
61   // Subclass specific functions
62 
63   enum_type operator=(enum_type value) {
64     m_current_value = value;
65     return m_current_value;
66   }
67 
68   enum_type GetCurrentValue() const { return m_current_value; }
69 
70   enum_type GetDefaultValue() const { return m_default_value; }
71 
72   void SetCurrentValue(enum_type value) { m_current_value = value; }
73 
74   void SetDefaultValue(enum_type value) { m_default_value = value; }
75 
76 protected:
77   void SetEnumerations(const OptionEnumValues &enumerators);
78 
79   enum_type m_current_value;
80   enum_type m_default_value;
81   EnumerationMap m_enumerations;
82 };
83 
84 } // namespace lldb_private
85 
86 #endif // liblldb_OptionValueEnumeration_h_
87