LLDB  mainline
OptionValueString.h
Go to the documentation of this file.
1 //===-- OptionValueString.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_OPTIONVALUESTRING_H
10 #define LLDB_INTERPRETER_OPTIONVALUESTRING_H
11 
12 #include <string>
13 
14 #include "lldb/Utility/Flags.h"
15 
17 
18 namespace lldb_private {
19 
20 class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
21 public:
22  typedef Status (*ValidatorCallback)(const char *string, void *baton);
23 
25 
26  OptionValueString() = default;
27 
28  OptionValueString(ValidatorCallback validator, void *baton = nullptr)
29  : m_validator(validator), m_validator_baton(baton) {}
30 
31  OptionValueString(const char *value) {
32  if (value && value[0]) {
33  m_current_value.assign(value);
34  m_default_value.assign(value);
35  }
36  }
37 
38  OptionValueString(const char *current_value, const char *default_value) {
39  if (current_value && current_value[0])
40  m_current_value.assign(current_value);
41  if (default_value && default_value[0])
42  m_default_value.assign(default_value);
43  }
44 
45  OptionValueString(const char *value, ValidatorCallback validator,
46  void *baton = nullptr)
47  : m_validator(validator), m_validator_baton(baton) {
48  if (value && value[0]) {
49  m_current_value.assign(value);
50  m_default_value.assign(value);
51  }
52  }
53 
54  OptionValueString(const char *current_value, const char *default_value,
55  ValidatorCallback validator, void *baton = nullptr)
56  : m_validator(validator), m_validator_baton(baton) {
57  if (current_value && current_value[0])
58  m_current_value.assign(current_value);
59  if (default_value && default_value[0])
60  m_default_value.assign(default_value);
61  }
62 
63  ~OptionValueString() override = default;
64 
65  // Virtual subclass pure virtual overrides
66 
67  OptionValue::Type GetType() const override { return eTypeString; }
68 
69  void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
70  uint32_t dump_mask) override;
71 
72  Status
73  SetValueFromString(llvm::StringRef value,
75 
76  void Clear() override {
78  m_value_was_set = false;
79  }
80 
81  // Subclass specific functions
82 
83  Flags &GetOptions() { return m_options; }
84 
85  const Flags &GetOptions() const { return m_options; }
86 
87  const char *operator=(const char *value) {
88  SetCurrentValue(value);
89  return m_current_value.c_str();
90  }
91 
92  const char *GetCurrentValue() const { return m_current_value.c_str(); }
93  llvm::StringRef GetCurrentValueAsRef() const { return m_current_value; }
94 
95  const char *GetDefaultValue() const { return m_default_value.c_str(); }
96  llvm::StringRef GetDefaultValueAsRef() const { return m_default_value; }
97 
98  Status SetCurrentValue(llvm::StringRef value);
99 
100  Status AppendToCurrentValue(const char *value);
101 
102  void SetDefaultValue(const char *value) {
103  if (value && value[0])
104  m_default_value.assign(value);
105  else
106  m_default_value.clear();
107  }
108 
109  bool IsCurrentValueEmpty() const { return m_current_value.empty(); }
110 
111  bool IsDefaultValueEmpty() const { return m_default_value.empty(); }
112 
113 protected:
118  void *m_validator_baton = nullptr;
119 };
120 
121 } // namespace lldb_private
122 
123 #endif // LLDB_INTERPRETER_OPTIONVALUESTRING_H
lldb_private::OptionValueString::ValidatorCallback
Status(* ValidatorCallback)(const char *string, void *baton)
Definition: OptionValueString.h:22
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::OptionValueString::DumpValue
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
Definition: OptionValueString.cpp:18
lldb_private::OptionValueString::OptionValueString
OptionValueString(const char *value)
Definition: OptionValueString.h:31
lldb_private::OptionValueString::GetDefaultValue
const char * GetDefaultValue() const
Definition: OptionValueString.h:95
lldb_private::OptionValueString::GetOptions
const Flags & GetOptions() const
Definition: OptionValueString.h:85
lldb_private::OptionValueString::m_default_value
std::string m_default_value
Definition: OptionValueString.h:115
lldb_private::OptionValueString::SetValueFromString
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
Definition: OptionValueString.cpp:44
lldb_private::OptionValueString::OptionValueString
OptionValueString(const char *current_value, const char *default_value)
Definition: OptionValueString.h:38
lldb_private::Flags
Definition: Flags.h:22
lldb_private::OptionValueString::Options
Options
Definition: OptionValueString.h:24
lldb_private::OptionValueString::GetType
OptionValue::Type GetType() const override
Definition: OptionValueString.h:67
lldb_private::Stream
Definition: Stream.h:28
lldb_private::OptionValueString::OptionValueString
OptionValueString(const char *current_value, const char *default_value, ValidatorCallback validator, void *baton=nullptr)
Definition: OptionValueString.h:54
lldb_private::Cloneable
Definition: Cloneable.h:40
lldb_private::OptionValueString::GetCurrentValueAsRef
llvm::StringRef GetCurrentValueAsRef() const
Definition: OptionValueString.h:93
OptionValue.h
lldb_private::VarSetOperationType
VarSetOperationType
Settable state variable types.
Definition: lldb-private-enumerations.h:83
lldb_private::OptionValueString::m_options
Flags m_options
Definition: OptionValueString.h:116
lldb_private::OptionValueString::IsCurrentValueEmpty
bool IsCurrentValueEmpty() const
Definition: OptionValueString.h:109
lldb_private::OptionValueString::SetDefaultValue
void SetDefaultValue(const char *value)
Definition: OptionValueString.h:102
lldb_private::OptionValueString::OptionValueString
OptionValueString()=default
lldb_private::OptionValueString::IsDefaultValueEmpty
bool IsDefaultValueEmpty() const
Definition: OptionValueString.h:111
lldb_private::OptionValueString::m_validator
ValidatorCallback m_validator
Definition: OptionValueString.h:117
lldb_private::OptionValueString::OptionValueString
OptionValueString(const char *value, ValidatorCallback validator, void *baton=nullptr)
Definition: OptionValueString.h:45
lldb_private::OptionValueString::GetOptions
Flags & GetOptions()
Definition: OptionValueString.h:83
lldb_private::OptionValueString::eOptionEncodeCharacterEscapeSequences
@ eOptionEncodeCharacterEscapeSequences
Definition: OptionValueString.h:24
lldb_private::OptionValueString
Definition: OptionValueString.h:20
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::OptionValueString::AppendToCurrentValue
Status AppendToCurrentValue(const char *value)
Definition: OptionValueString.cpp:130
lldb_private::OptionValueString::GetCurrentValue
const char * GetCurrentValue() const
Definition: OptionValueString.h:92
lldb_private::OptionValueString::m_validator_baton
void * m_validator_baton
Definition: OptionValueString.h:118
lldb_private::OptionValueString::Clear
void Clear() override
Definition: OptionValueString.h:76
lldb_private::Status
Definition: Status.h:44
lldb_private::OptionValue::Type
Type
Definition: OptionValue.h:26
uint32_t
lldb_private::OptionValue::m_value_was_set
bool m_value_was_set
Definition: OptionValue.h:332
lldb_private::OptionValue::eTypeString
@ eTypeString
Definition: OptionValue.h:44
lldb_private::OptionValueString::operator=
const char * operator=(const char *value)
Definition: OptionValueString.h:87
lldb_private::OptionValueString::SetCurrentValue
Status SetCurrentValue(llvm::StringRef value)
Definition: OptionValueString.cpp:120
lldb_private::OptionValueString::OptionValueString
OptionValueString(ValidatorCallback validator, void *baton=nullptr)
Definition: OptionValueString.h:28
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::OptionValueString::m_current_value
std::string m_current_value
Definition: OptionValueString.h:114
lldb_private::OptionValueString::GetDefaultValueAsRef
llvm::StringRef GetDefaultValueAsRef() const
Definition: OptionValueString.h:96
Flags.h
lldb_private::OptionValueString::~OptionValueString
~OptionValueString() override=default
lldb_private::eVarSetOperationAssign
@ eVarSetOperationAssign
Definition: lldb-private-enumerations.h:90