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 #include "lldb/Interpreter/OptionValue.h" 14 #include "lldb/Utility/RegularExpression.h" 15 16 namespace lldb_private { 17 18 class OptionValueRegex : public OptionValue { 19 public: 20 OptionValueRegex(const char *value = nullptr) OptionValue()21 : OptionValue(), m_regex(llvm::StringRef::withNullAsEmpty(value)) {} 22 23 ~OptionValueRegex() override = default; 24 25 //--------------------------------------------------------------------- 26 // Virtual subclass pure virtual overrides 27 //--------------------------------------------------------------------- 28 GetType()29 OptionValue::Type GetType() const override { return eTypeRegex; } 30 31 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 32 uint32_t dump_mask) override; 33 34 Status 35 SetValueFromString(llvm::StringRef value, 36 VarSetOperationType op = eVarSetOperationAssign) override; 37 Status 38 SetValueFromString(const char *, 39 VarSetOperationType = eVarSetOperationAssign) = delete; 40 Clear()41 bool Clear() override { 42 m_regex.Clear(); 43 m_value_was_set = false; 44 return true; 45 } 46 47 lldb::OptionValueSP DeepCopy() const override; 48 49 //--------------------------------------------------------------------- 50 // Subclass specific functions 51 //--------------------------------------------------------------------- GetCurrentValue()52 const RegularExpression *GetCurrentValue() const { 53 return (m_regex.IsValid() ? &m_regex : nullptr); 54 } 55 SetCurrentValue(const char * value)56 void SetCurrentValue(const char *value) { 57 if (value && value[0]) 58 m_regex.Compile(llvm::StringRef(value)); 59 else 60 m_regex.Clear(); 61 } 62 IsValid()63 bool IsValid() const { return m_regex.IsValid(); } 64 65 protected: 66 RegularExpression m_regex; 67 }; 68 69 } // namespace lldb_private 70 71 #endif // liblldb_OptionValueRegex_h_ 72