blob: 0400bea0ba4bc8947b7140bfa9e8adb392d654e0 [file] [log] [blame]
Greg Clayton7406c392011-04-20 01:33:38 +00001//===-- NamedOptionValue.cpp ------------------------------------*- 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#include "lldb/Interpreter/NamedOptionValue.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Stream.h"
17#include "lldb/Interpreter/Args.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22//-------------------------------------------------------------------------
23// NamedOptionValue
24//-------------------------------------------------------------------------
25
26void
27NamedOptionValue::GetQualifiedName (Stream &strm)
28{
29 if (m_parent)
30 {
31 m_parent->GetQualifiedName (strm);
32 strm.PutChar('.');
33 }
34 strm << m_name;
35}
36
37OptionValue::Type
38NamedOptionValue::GetValueType ()
39{
40 if (m_value_sp)
41 return m_value_sp->GetType();
42 return OptionValue::eTypeInvalid;
43}
44
45bool
46NamedOptionValue::DumpValue (Stream &strm)
47{
48 if (m_value_sp)
49 {
50 m_value_sp->DumpValue (strm);
51 return true;
52 }
53 return false;
54}
55
56bool
57NamedOptionValue::SetValueFromCString (const char *value_cstr)
58{
59 if (m_value_sp)
60 return m_value_sp->SetValueFromCString (value_cstr);
61 return false;
62}
63
64bool
65NamedOptionValue::ResetValueToDefault ()
66{
67 if (m_value_sp)
68 return m_value_sp->ResetValueToDefault ();
69 return false;
70}
71
72
73OptionValueBoolean *
74NamedOptionValue::GetBooleanValue ()
75{
76 if (GetValueType() == OptionValue::eTypeBoolean)
77 return static_cast<OptionValueBoolean *>(m_value_sp.get());
78 return NULL;
79}
80
81OptionValueSInt64 *
82NamedOptionValue::GetSInt64Value ()
83{
84 if (GetValueType() == OptionValue::eTypeSInt64)
85 return static_cast<OptionValueSInt64 *>(m_value_sp.get());
86 return NULL;
87}
88
89OptionValueUInt64 *
90NamedOptionValue::GetUInt64Value ()
91{
92 if (GetValueType() == OptionValue::eTypeUInt64)
93 return static_cast<OptionValueUInt64 *>(m_value_sp.get());
94 return NULL;
95}
96
Greg Claytond12aeab2011-04-20 16:37:46 +000097OptionValueString *
98NamedOptionValue::GetStringValue ()
99{
100 if (GetValueType() == OptionValue::eTypeString)
101 return static_cast<OptionValueString *>(m_value_sp.get());
102 return NULL;
103}
Greg Clayton7406c392011-04-20 01:33:38 +0000104
105OptionValueFileSpec *
106NamedOptionValue::GetFileSpecValue ()
107{
108 if (GetValueType() == OptionValue::eTypeFileSpec)
109 return static_cast<OptionValueFileSpec *>(m_value_sp.get());
110 return NULL;
111}
112
113OptionValueArray *
114NamedOptionValue::GetArrayValue ()
115{
116 if (GetValueType() == OptionValue::eTypeArray)
117 return static_cast<OptionValueArray *>(m_value_sp.get());
118 return NULL;
119}
120
121OptionValueDictionary *
122NamedOptionValue::GetDictionaryValue ()
123{
124 if (GetValueType() == OptionValue::eTypeDictionary)
125 return static_cast<OptionValueDictionary *>(m_value_sp.get());
126 return NULL;
127}
128
129//-------------------------------------------------------------------------
130// OptionValueBoolean
131//-------------------------------------------------------------------------
132void
133OptionValueBoolean::DumpValue (Stream &strm)
134{
135 strm.PutCString (m_current_value ? "true" : "false");
136}
137
138bool
139OptionValueBoolean::SetValueFromCString (const char *value_cstr)
140{
141 bool success = false;
142 bool value = Args::StringToBoolean(value_cstr, false, &success);
143 if (success)
144 {
145 m_current_value = value;
146 return true;
147 }
148 return false;
149}
150
151//-------------------------------------------------------------------------
152// OptionValueSInt64
153//-------------------------------------------------------------------------
154void
155OptionValueSInt64::DumpValue (Stream &strm)
156{
157 strm.Printf ("%lli", m_current_value);
158}
159
160bool
161OptionValueSInt64::SetValueFromCString (const char *value_cstr)
162{
163 bool success = false;
164 int64_t value = Args::StringToSInt64 (value_cstr, 0, 0, &success);
165 if (success)
166 {
167 m_current_value = value;
168 return true;
169 }
170 return false;
171}
172
173//-------------------------------------------------------------------------
174// OptionValueUInt64
175//-------------------------------------------------------------------------
176void
177OptionValueUInt64::DumpValue (Stream &strm)
178{
179 strm.Printf ("0x%llx", m_current_value);
180}
181
182bool
183OptionValueUInt64::SetValueFromCString (const char *value_cstr)
184{
185 bool success = false;
186 uint64_t value = Args::StringToUInt64 (value_cstr, 0, 0, &success);
187 if (success)
188 {
189 m_current_value = value;
190 return true;
191 }
192 return false;
193}
194
195//-------------------------------------------------------------------------
Greg Claytond12aeab2011-04-20 16:37:46 +0000196// OptionValueDictionary
197//-------------------------------------------------------------------------
198void
199OptionValueString::DumpValue (Stream &strm)
200{
201 strm.Printf ("\"%s\"", m_current_value.c_str());
202}
203
204bool
205OptionValueString::SetValueFromCString (const char *value_cstr)
206{
207 SetCurrentValue (value_cstr);
208 return true;
209}
210
211
212
213//-------------------------------------------------------------------------
Greg Clayton7406c392011-04-20 01:33:38 +0000214// OptionValueFileSpec
215//-------------------------------------------------------------------------
216void
217OptionValueFileSpec::DumpValue (Stream &strm)
218{
219 if (m_current_value)
220 {
221 if (m_current_value.GetDirectory())
222 {
223 strm << '"' << m_current_value.GetDirectory();
224 if (m_current_value.GetFilename())
225 strm << '/' << m_current_value.GetFilename();
226 strm << '"';
227 }
228 else
229 {
230 strm << '"' << m_current_value.GetFilename() << '"';
231 }
232 }
233}
234
235bool
236OptionValueFileSpec::SetValueFromCString (const char *value_cstr)
237{
238 if (value_cstr && value_cstr[0])
239 m_current_value.SetFile(value_cstr, false);
240 else
241 m_current_value.Clear();
242 return true;
243}
244
245
246//-------------------------------------------------------------------------
247// OptionValueArray
248//-------------------------------------------------------------------------
249void
250OptionValueArray::DumpValue (Stream &strm)
251{
252 const uint32_t size = m_values.size();
253 for (uint32_t i = 0; i<size; ++i)
254 {
255 strm.Printf("[%u] ", i);
256 m_values[i]->DumpValue (strm);
257 }
258}
259
260bool
261OptionValueArray::SetValueFromCString (const char *value_cstr)
262{
263 // We must be able to set this using the array specific functions
264 return false;
265}
266
267//-------------------------------------------------------------------------
268// OptionValueDictionary
269//-------------------------------------------------------------------------
270void
271OptionValueDictionary::DumpValue (Stream &strm)
272{
273 collection::iterator pos, end = m_values.end();
274
275 for (pos = m_values.begin(); pos != end; ++pos)
276 {
277 strm.Printf("%s=", pos->first.GetCString());
278 pos->second->DumpValue (strm);
279 }
280}
281
282bool
283OptionValueDictionary::SetValueFromCString (const char *value_cstr)
284{
285 // We must be able to set this using the array specific functions
286 return false;
287}
288
289