]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Interpreter/OptionValueString.h
Vendor import of stripped lldb trunk r256633:
[FreeBSD/FreeBSD.git] / include / lldb / Interpreter / OptionValueString.h
1 //===-- OptionValueString.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_OptionValueString_h_
11 #define liblldb_OptionValueString_h_
12
13 // C Includes
14 // C++ Includes
15 #include <string>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Core/Flags.h"
20 #include "lldb/Interpreter/OptionValue.h"
21
22 namespace lldb_private {
23
24 class OptionValueString : public OptionValue
25 {
26 public:
27     typedef Error (*ValidatorCallback) (const char* string,
28                                         void* baton);
29     
30     enum Options
31     {
32         eOptionEncodeCharacterEscapeSequences = (1u << 0)
33     };
34
35     OptionValueString () :
36         OptionValue(),
37         m_current_value (),
38         m_default_value (),
39         m_options(),
40         m_validator(),
41         m_validator_baton()
42     {
43     }
44     
45     OptionValueString(ValidatorCallback validator,
46                       void* baton = nullptr) :
47         OptionValue(),
48         m_current_value (),
49         m_default_value (),
50         m_options(),
51         m_validator(validator),
52         m_validator_baton(baton)
53     {
54     }
55
56     OptionValueString (const char *value) :
57         OptionValue(),
58         m_current_value (),
59         m_default_value (),
60         m_options(),
61         m_validator(),
62         m_validator_baton()
63     {
64         if  (value && value[0])
65         {
66             m_current_value.assign (value);
67             m_default_value.assign (value);
68         }
69     }
70
71     OptionValueString (const char *current_value,
72                        const char *default_value) :
73         OptionValue(),
74         m_current_value (),
75         m_default_value (),
76         m_options(),
77         m_validator(),
78         m_validator_baton()
79     {
80         if  (current_value && current_value[0])
81             m_current_value.assign (current_value);
82         if  (default_value && default_value[0])
83             m_default_value.assign (default_value);
84     }
85     
86     OptionValueString(const char *value,
87                       ValidatorCallback validator,
88                       void* baton = nullptr) :
89     OptionValue(),
90     m_current_value (),
91     m_default_value (),
92     m_options(),
93     m_validator(validator),
94     m_validator_baton(baton)
95     {
96         if  (value && value[0])
97         {
98             m_current_value.assign (value);
99             m_default_value.assign (value);
100         }
101     }
102     
103     OptionValueString(const char *current_value,
104                       const char *default_value,
105                       ValidatorCallback validator,
106                       void* baton = nullptr) :
107     OptionValue(),
108     m_current_value (),
109     m_default_value (),
110     m_options(),
111     m_validator(validator),
112     m_validator_baton(baton)
113     {
114         if  (current_value && current_value[0])
115             m_current_value.assign (current_value);
116         if  (default_value && default_value[0])
117             m_default_value.assign (default_value);
118     }
119     
120     ~OptionValueString() override = default;
121
122     //---------------------------------------------------------------------
123     // Virtual subclass pure virtual overrides
124     //---------------------------------------------------------------------
125     
126     OptionValue::Type
127     GetType() const override
128     {
129         return eTypeString;
130     }
131     
132     void
133     DumpValue(const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) override;
134     
135     Error
136     SetValueFromString(llvm::StringRef value,
137                        VarSetOperationType op = eVarSetOperationAssign) override;
138
139     bool
140     Clear() override
141     {
142         m_current_value = m_default_value;
143         m_value_was_set = false;
144         return true;
145     }
146
147     lldb::OptionValueSP
148     DeepCopy() const override;
149
150     //---------------------------------------------------------------------
151     // Subclass specific functions
152     //---------------------------------------------------------------------
153
154     Flags &
155     GetOptions ()
156     {
157         return m_options;
158     }
159
160     const Flags &
161     GetOptions () const
162     {
163         return m_options;
164     }
165     
166     const char *
167     operator = (const char *value)
168     {
169         SetCurrentValue(value);
170         return m_current_value.c_str();
171     }
172
173     const char *
174     GetCurrentValue() const
175     {
176         return m_current_value.c_str();
177     }
178     
179     const char *
180     GetDefaultValue() const
181     {
182         return m_default_value.c_str();
183     }
184     
185     Error
186     SetCurrentValue (const char *value);
187     
188     Error
189     AppendToCurrentValue (const char *value);
190
191     void
192     SetDefaultValue (const char *value)
193     {
194         if (value && value[0])
195             m_default_value.assign (value);
196         else
197             m_default_value.clear();
198     }
199
200     bool
201     IsCurrentValueEmpty () const
202     {
203         return m_current_value.empty();
204     }
205
206     bool
207     IsDefaultValueEmpty () const
208     {
209         return m_default_value.empty();
210     }
211
212 protected:
213     std::string m_current_value;
214     std::string m_default_value;
215     Flags m_options;
216     ValidatorCallback m_validator;
217     void* m_validator_baton;
218 };
219
220 } // namespace lldb_private
221
222 #endif // liblldb_OptionValueString_h_