blob: e3b6357b25ba6d845cf8ba66e7c5612fbcc55fdd [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
97
98OptionValueFileSpec *
99NamedOptionValue::GetFileSpecValue ()
100{
101 if (GetValueType() == OptionValue::eTypeFileSpec)
102 return static_cast<OptionValueFileSpec *>(m_value_sp.get());
103 return NULL;
104}
105
106OptionValueArray *
107NamedOptionValue::GetArrayValue ()
108{
109 if (GetValueType() == OptionValue::eTypeArray)
110 return static_cast<OptionValueArray *>(m_value_sp.get());
111 return NULL;
112}
113
114OptionValueDictionary *
115NamedOptionValue::GetDictionaryValue ()
116{
117 if (GetValueType() == OptionValue::eTypeDictionary)
118 return static_cast<OptionValueDictionary *>(m_value_sp.get());
119 return NULL;
120}
121
122//-------------------------------------------------------------------------
123// OptionValueBoolean
124//-------------------------------------------------------------------------
125void
126OptionValueBoolean::DumpValue (Stream &strm)
127{
128 strm.PutCString (m_current_value ? "true" : "false");
129}
130
131bool
132OptionValueBoolean::SetValueFromCString (const char *value_cstr)
133{
134 bool success = false;
135 bool value = Args::StringToBoolean(value_cstr, false, &success);
136 if (success)
137 {
138 m_current_value = value;
139 return true;
140 }
141 return false;
142}
143
144//-------------------------------------------------------------------------
145// OptionValueSInt64
146//-------------------------------------------------------------------------
147void
148OptionValueSInt64::DumpValue (Stream &strm)
149{
150 strm.Printf ("%lli", m_current_value);
151}
152
153bool
154OptionValueSInt64::SetValueFromCString (const char *value_cstr)
155{
156 bool success = false;
157 int64_t value = Args::StringToSInt64 (value_cstr, 0, 0, &success);
158 if (success)
159 {
160 m_current_value = value;
161 return true;
162 }
163 return false;
164}
165
166//-------------------------------------------------------------------------
167// OptionValueUInt64
168//-------------------------------------------------------------------------
169void
170OptionValueUInt64::DumpValue (Stream &strm)
171{
172 strm.Printf ("0x%llx", m_current_value);
173}
174
175bool
176OptionValueUInt64::SetValueFromCString (const char *value_cstr)
177{
178 bool success = false;
179 uint64_t value = Args::StringToUInt64 (value_cstr, 0, 0, &success);
180 if (success)
181 {
182 m_current_value = value;
183 return true;
184 }
185 return false;
186}
187
188//-------------------------------------------------------------------------
189// OptionValueFileSpec
190//-------------------------------------------------------------------------
191void
192OptionValueFileSpec::DumpValue (Stream &strm)
193{
194 if (m_current_value)
195 {
196 if (m_current_value.GetDirectory())
197 {
198 strm << '"' << m_current_value.GetDirectory();
199 if (m_current_value.GetFilename())
200 strm << '/' << m_current_value.GetFilename();
201 strm << '"';
202 }
203 else
204 {
205 strm << '"' << m_current_value.GetFilename() << '"';
206 }
207 }
208}
209
210bool
211OptionValueFileSpec::SetValueFromCString (const char *value_cstr)
212{
213 if (value_cstr && value_cstr[0])
214 m_current_value.SetFile(value_cstr, false);
215 else
216 m_current_value.Clear();
217 return true;
218}
219
220
221//-------------------------------------------------------------------------
222// OptionValueArray
223//-------------------------------------------------------------------------
224void
225OptionValueArray::DumpValue (Stream &strm)
226{
227 const uint32_t size = m_values.size();
228 for (uint32_t i = 0; i<size; ++i)
229 {
230 strm.Printf("[%u] ", i);
231 m_values[i]->DumpValue (strm);
232 }
233}
234
235bool
236OptionValueArray::SetValueFromCString (const char *value_cstr)
237{
238 // We must be able to set this using the array specific functions
239 return false;
240}
241
242//-------------------------------------------------------------------------
243// OptionValueDictionary
244//-------------------------------------------------------------------------
245void
246OptionValueDictionary::DumpValue (Stream &strm)
247{
248 collection::iterator pos, end = m_values.end();
249
250 for (pos = m_values.begin(); pos != end; ++pos)
251 {
252 strm.Printf("%s=", pos->first.GetCString());
253 pos->second->DumpValue (strm);
254 }
255}
256
257bool
258OptionValueDictionary::SetValueFromCString (const char *value_cstr)
259{
260 // We must be able to set this using the array specific functions
261 return false;
262}
263
264