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
18namespace lldb_private {
19
20class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
21public:
22 typedef Status (*ValidatorCallback)(const char *string, void *baton);
23
25
26 OptionValueString() = default;
27
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
46 void *baton = nullptr)
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)
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 llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
73 return m_current_value;
74 }
75
76 Status
77 SetValueFromString(llvm::StringRef value,
79
80 void Clear() override {
82 m_value_was_set = false;
83 }
84
85 // Subclass specific functions
86
87 Flags &GetOptions() { return m_options; }
88
89 const Flags &GetOptions() const { return m_options; }
90
91 const char *operator=(const char *value) {
92 SetCurrentValue(value);
93 return m_current_value.c_str();
94 }
95
96 const char *GetCurrentValue() const { return m_current_value.c_str(); }
97 llvm::StringRef GetCurrentValueAsRef() const { return m_current_value; }
98
99 const char *GetDefaultValue() const { return m_default_value.c_str(); }
100 llvm::StringRef GetDefaultValueAsRef() const { return m_default_value; }
101
102 Status SetCurrentValue(llvm::StringRef value);
103
104 Status AppendToCurrentValue(const char *value);
105
106 void SetDefaultValue(const char *value) {
107 if (value && value[0])
108 m_default_value.assign(value);
109 else
110 m_default_value.clear();
111 }
112
113 bool IsCurrentValueEmpty() const { return m_current_value.empty(); }
114
115 bool IsDefaultValueEmpty() const { return m_default_value.empty(); }
116
117 void SetValidator(ValidatorCallback validator, void *baton = nullptr) {
119 m_validator_baton = baton;
120 }
121
122protected:
123 std::string m_current_value;
124 std::string m_default_value;
127 void *m_validator_baton = nullptr;
128};
129
130} // namespace lldb_private
131
132#endif // LLDB_INTERPRETER_OPTIONVALUESTRING_H
A class that implements CRTP-based "virtual constructor" idiom.
Definition: Cloneable.h:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A class to manage flags.
Definition: Flags.h:22
void SetValidator(ValidatorCallback validator, void *baton=nullptr)
const char * GetDefaultValue() const
OptionValueString(const char *current_value, const char *default_value)
void SetDefaultValue(const char *value)
OptionValue::Type GetType() const override
OptionValueString(const char *value, ValidatorCallback validator, void *baton=nullptr)
~OptionValueString() override=default
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
llvm::StringRef GetDefaultValueAsRef() const
OptionValueString(const char *value)
llvm::StringRef GetCurrentValueAsRef() const
const char * GetCurrentValue() const
const Flags & GetOptions() const
OptionValueString(ValidatorCallback validator, void *baton=nullptr)
Status AppendToCurrentValue(const char *value)
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override
Status SetCurrentValue(llvm::StringRef value)
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override
const char * operator=(const char *value)
Status(* ValidatorCallback)(const char *string, void *baton)
OptionValueString(const char *current_value, const char *default_value, ValidatorCallback validator, void *baton=nullptr)
An error handling class.
Definition: Status.h:115
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
A class that represents a running process on the host machine.
TableValidator< 0 > validator
VarSetOperationType
Settable state variable types.