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 liblldb_OptionValueString_h_
10 #define liblldb_OptionValueString_h_
11 
12 #include <string>
13 
14 #include "lldb/Utility/Flags.h"
15 
17 
18 namespace lldb_private {
19 
21 public:
22  typedef Status (*ValidatorCallback)(const char *string, void *baton);
23 
25 
29 
30  OptionValueString(ValidatorCallback validator, void *baton = nullptr)
32  m_validator(validator), m_validator_baton(baton) {}
33 
34  OptionValueString(const char *value)
37  if (value && value[0]) {
38  m_current_value.assign(value);
39  m_default_value.assign(value);
40  }
41  }
42 
43  OptionValueString(const char *current_value, const char *default_value)
46  if (current_value && current_value[0])
47  m_current_value.assign(current_value);
48  if (default_value && default_value[0])
49  m_default_value.assign(default_value);
50  }
51 
52  OptionValueString(const char *value, ValidatorCallback validator,
53  void *baton = nullptr)
55  m_validator(validator), m_validator_baton(baton) {
56  if (value && value[0]) {
57  m_current_value.assign(value);
58  m_default_value.assign(value);
59  }
60  }
61 
62  OptionValueString(const char *current_value, const char *default_value,
63  ValidatorCallback validator, void *baton = nullptr)
65  m_validator(validator), m_validator_baton(baton) {
66  if (current_value && current_value[0])
67  m_current_value.assign(current_value);
68  if (default_value && default_value[0])
69  m_default_value.assign(default_value);
70  }
71 
72  ~OptionValueString() override = default;
73 
74  // Virtual subclass pure virtual overrides
75 
76  OptionValue::Type GetType() const override { return eTypeString; }
77 
78  void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
79  uint32_t dump_mask) override;
80 
81  Status
82  SetValueFromString(llvm::StringRef value,
84  Status
85  SetValueFromString(const char *,
87 
88  bool Clear() override {
90  m_value_was_set = false;
91  return true;
92  }
93 
94  lldb::OptionValueSP DeepCopy() const override;
95 
96  // Subclass specific functions
97 
98  Flags &GetOptions() { return m_options; }
99 
100  const Flags &GetOptions() const { return m_options; }
101 
102  const char *operator=(const char *value) {
103  SetCurrentValue(llvm::StringRef::withNullAsEmpty(value));
104  return m_current_value.c_str();
105  }
106 
107  const char *GetCurrentValue() const { return m_current_value.c_str(); }
108  llvm::StringRef GetCurrentValueAsRef() const { return m_current_value; }
109 
110  const char *GetDefaultValue() const { return m_default_value.c_str(); }
111  llvm::StringRef GetDefaultValueAsRef() const { return m_default_value; }
112 
113  Status SetCurrentValue(const char *) = delete;
114  Status SetCurrentValue(llvm::StringRef value);
115 
116  Status AppendToCurrentValue(const char *value);
117 
118  void SetDefaultValue(const char *value) {
119  if (value && value[0])
120  m_default_value.assign(value);
121  else
122  m_default_value.clear();
123  }
124 
125  bool IsCurrentValueEmpty() const { return m_current_value.empty(); }
126 
127  bool IsDefaultValueEmpty() const { return m_default_value.empty(); }
128 
129 protected:
130  std::string m_current_value;
131  std::string m_default_value;
135 };
136 
137 } // namespace lldb_private
138 
139 #endif // liblldb_OptionValueString_h_
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
OptionValueString(ValidatorCallback validator, void *baton=nullptr)
void SetDefaultValue(const char *value)
OptionValue::Type GetType() const override
llvm::StringRef GetCurrentValueAsRef() const
OptionValueString(const char *current_value, const char *default_value, ValidatorCallback validator, void *baton=nullptr)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
OptionValueString(const char *current_value, const char *default_value)
~OptionValueString() override=default
const char * GetDefaultValue() const
Status(* ValidatorCallback)(const char *string, void *baton)
VarSetOperationType
Settable state variable types.
llvm::StringRef GetDefaultValueAsRef() const
const char * GetCurrentValue() const
Status AppendToCurrentValue(const char *value)
const Flags & GetOptions() const
A class to manage flags.
Definition: Flags.h:22
Status SetCurrentValue(const char *)=delete
OptionValueString(const char *value, ValidatorCallback validator, void *baton=nullptr)
const char * operator=(const char *value)
lldb::OptionValueSP DeepCopy() const override
OptionValueString(const char *value)
An error handling class.
Definition: Status.h:44