]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/OptionValueRegex.h
MFV 337214:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Interpreter / OptionValueRegex.h
1 //===-- OptionValueRegex.h --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_OptionValueRegex_h_
11 #define liblldb_OptionValueRegex_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Interpreter/OptionValue.h"
18 #include "lldb/Utility/RegularExpression.h"
19
20 namespace lldb_private {
21
22 class OptionValueRegex : public OptionValue {
23 public:
24   OptionValueRegex(const char *value = nullptr)
25       : OptionValue(), m_regex(llvm::StringRef::withNullAsEmpty(value)) {}
26
27   ~OptionValueRegex() override = default;
28
29   //---------------------------------------------------------------------
30   // Virtual subclass pure virtual overrides
31   //---------------------------------------------------------------------
32
33   OptionValue::Type GetType() const override { return eTypeRegex; }
34
35   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
36                  uint32_t dump_mask) override;
37
38   Status
39   SetValueFromString(llvm::StringRef value,
40                      VarSetOperationType op = eVarSetOperationAssign) override;
41   Status
42   SetValueFromString(const char *,
43                      VarSetOperationType = eVarSetOperationAssign) = delete;
44
45   bool Clear() override {
46     m_regex.Clear();
47     m_value_was_set = false;
48     return true;
49   }
50
51   lldb::OptionValueSP DeepCopy() const override;
52
53   //---------------------------------------------------------------------
54   // Subclass specific functions
55   //---------------------------------------------------------------------
56   const RegularExpression *GetCurrentValue() const {
57     return (m_regex.IsValid() ? &m_regex : nullptr);
58   }
59
60   void SetCurrentValue(const char *value) {
61     if (value && value[0])
62       m_regex.Compile(llvm::StringRef(value));
63     else
64       m_regex.Clear();
65   }
66
67   bool IsValid() const { return m_regex.IsValid(); }
68
69 protected:
70   RegularExpression m_regex;
71 };
72
73 } // namespace lldb_private
74
75 #endif // liblldb_OptionValueRegex_h_