1 //===-- OptionValue.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_OptionValue_h_
11 #define liblldb_OptionValue_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-defines.h"
18 #include "lldb/Core/ConstString.h"
19 #include "lldb/Core/Error.h"
21 namespace lldb_private {
23 //---------------------------------------------------------------------
25 //---------------------------------------------------------------------
52 eDumpOptionName = (1u << 0),
53 eDumpOptionType = (1u << 1),
54 eDumpOptionValue = (1u << 2),
55 eDumpOptionDescription = (1u << 3),
56 eDumpOptionRaw = (1u << 4),
57 eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue),
58 eDumpGroupHelp = (eDumpOptionName | eDumpOptionType | eDumpOptionDescription)
65 m_value_was_set (false)
69 OptionValue (const OptionValue &rhs) :
70 m_callback (rhs.m_callback),
71 m_baton (rhs.m_baton),
72 m_value_was_set (rhs.m_value_was_set)
76 virtual ~OptionValue ()
79 //-----------------------------------------------------------------
80 // Subclasses should override these functions
81 //-----------------------------------------------------------------
85 // If this value is always hidden, the avoid showing any info on this
86 // value, just show the info for the child values.
88 ValueIsTransparent () const
90 return GetType() == eTypeProperties;
94 GetTypeAsCString () const
96 return GetBuiltinTypeAsCString(GetType());
101 GetBuiltinTypeAsCString (Type t);
104 DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) = 0;
107 SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign);
112 virtual lldb::OptionValueSP
113 DeepCopy () const = 0;
116 AutoComplete (CommandInterpreter &interpreter,
118 int match_start_point,
119 int max_return_elements,
121 StringList &matches);
123 //-----------------------------------------------------------------
124 // Subclasses can override these functions
125 //-----------------------------------------------------------------
126 virtual lldb::OptionValueSP
127 GetSubValue (const ExecutionContext *exe_ctx,
132 error.SetErrorStringWithFormat("'%s' is not a value subvalue", name);
133 return lldb::OptionValueSP();
137 SetSubValue (const ExecutionContext *exe_ctx,
138 VarSetOperationType op,
143 IsAggregateValue () const
151 return ConstString();
155 DumpQualifiedName (Stream &strm) const;
156 //-----------------------------------------------------------------
157 // Subclasses should NOT override these functions as they use the
158 // above functions to implement functionality
159 //-----------------------------------------------------------------
163 return 1u << GetType();
167 ConvertTypeToMask (OptionValue::Type type)
172 static OptionValue::Type
173 ConvertTypeMaskToType (uint32_t type_mask)
175 // If only one bit is set, then return an appropriate enumeration
178 case 1u << eTypeArch: return eTypeArch;
179 case 1u << eTypeArgs: return eTypeArgs;
180 case 1u << eTypeArray: return eTypeArray;
181 case 1u << eTypeBoolean: return eTypeBoolean;
182 case 1u << eTypeChar: return eTypeChar;
183 case 1u << eTypeDictionary: return eTypeDictionary;
184 case 1u << eTypeEnum: return eTypeEnum;
185 case 1u << eTypeFileSpec: return eTypeFileSpec;
186 case 1u << eTypeFileSpecList: return eTypeFileSpecList;
187 case 1u << eTypeFormat: return eTypeFormat;
188 case 1u << eTypePathMap: return eTypePathMap;
189 case 1u << eTypeProperties: return eTypeProperties;
190 case 1u << eTypeRegex: return eTypeRegex;
191 case 1u << eTypeSInt64: return eTypeSInt64;
192 case 1u << eTypeString: return eTypeString;
193 case 1u << eTypeUInt64: return eTypeUInt64;
194 case 1u << eTypeUUID: return eTypeUUID;
196 // Else return invalid
200 static lldb::OptionValueSP
201 CreateValueFromCStringForTypeMask (const char *value_cstr,
205 // Get this value as a uint64_t value if it is encoded as a boolean,
206 // uint64_t or int64_t. Other types will cause "fail_value" to be
209 GetUInt64Value (uint64_t fail_value, bool *success_ptr);
214 const OptionValueArch *
220 const OptionValueArray *
226 const OptionValueArgs *
235 const OptionValueBoolean *
236 GetAsBoolean () const;
238 const OptionValueChar *
241 OptionValueDictionary *
244 const OptionValueDictionary *
245 GetAsDictionary () const;
247 OptionValueEnumeration *
250 const OptionValueEnumeration *
251 GetAsEnumeration () const;
253 OptionValueFileSpec *
256 const OptionValueFileSpec *
257 GetAsFileSpec () const;
259 OptionValueFileSpecList *
260 GetAsFileSpecList ();
262 const OptionValueFileSpecList *
263 GetAsFileSpecList () const;
268 const OptionValueFormat *
269 GetAsFormat () const;
271 OptionValuePathMappings *
272 GetAsPathMappings ();
274 const OptionValuePathMappings *
275 GetAsPathMappings () const;
277 OptionValueProperties *
280 const OptionValueProperties *
281 GetAsProperties () const;
286 const OptionValueRegex *
292 const OptionValueSInt64 *
293 GetAsSInt64 () const;
298 const OptionValueString *
299 GetAsString () const;
304 const OptionValueUInt64 *
305 GetAsUInt64 () const;
310 const OptionValueUUID *
314 GetBooleanValue (bool fail_value = false) const;
317 SetBooleanValue (bool new_value);
319 char GetCharValue(char fail_value) const;
321 char SetCharValue(char new_value);
324 GetEnumerationValue (int64_t fail_value = -1) const;
327 SetEnumerationValue (int64_t value);
330 GetFileSpecValue () const;
333 SetFileSpecValue (const FileSpec &file_spec);
336 GetFileSpecListValue () const;
339 GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault) const;
342 SetFormatValue (lldb::Format new_value);
344 const RegularExpression *
345 GetRegexValue () const;
348 GetSInt64Value (int64_t fail_value = 0) const;
351 SetSInt64Value (int64_t new_value);
354 GetStringValue (const char *fail_value = NULL) const;
357 SetStringValue (const char *new_value);
360 GetUInt64Value (uint64_t fail_value = 0) const;
363 SetUInt64Value (uint64_t new_value);
366 GetUUIDValue () const;
369 SetUUIDValue (const UUID &uuid);
372 OptionWasSet () const
374 return m_value_was_set;
380 m_value_was_set = true;
384 SetParent (const lldb::OptionValueSP &parent_sp)
386 m_parent_wp = parent_sp;
390 SetValueChangedCallback (OptionValueChangedCallback callback,
393 assert (m_callback == NULL);
394 m_callback = callback;
399 NotifyValueChanged ()
402 m_callback (m_baton, this);
405 lldb::OptionValueWP m_parent_wp;
406 OptionValueChangedCallback m_callback;
408 bool m_value_was_set; // This can be used to see if a value has been set
409 // by a call to SetValueFromCString(). It is often
410 // handy to know if an option value was set from
411 // the command line or as a setting, versus if we
412 // just have the default value that was already
413 // populated in the option value.
417 } // namespace lldb_private
419 #endif // liblldb_OptionValue_h_