Greg Clayton | 7406c39 | 2011-04-20 01:33:38 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | //------------------------------------------------------------------------- |
| 23 | // NamedOptionValue |
| 24 | //------------------------------------------------------------------------- |
| 25 | |
| 26 | void |
| 27 | NamedOptionValue::GetQualifiedName (Stream &strm) |
| 28 | { |
| 29 | if (m_parent) |
| 30 | { |
| 31 | m_parent->GetQualifiedName (strm); |
| 32 | strm.PutChar('.'); |
| 33 | } |
| 34 | strm << m_name; |
| 35 | } |
| 36 | |
| 37 | OptionValue::Type |
| 38 | NamedOptionValue::GetValueType () |
| 39 | { |
| 40 | if (m_value_sp) |
| 41 | return m_value_sp->GetType(); |
| 42 | return OptionValue::eTypeInvalid; |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | NamedOptionValue::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 | |
| 56 | bool |
| 57 | NamedOptionValue::SetValueFromCString (const char *value_cstr) |
| 58 | { |
| 59 | if (m_value_sp) |
| 60 | return m_value_sp->SetValueFromCString (value_cstr); |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | bool |
| 65 | NamedOptionValue::ResetValueToDefault () |
| 66 | { |
| 67 | if (m_value_sp) |
| 68 | return m_value_sp->ResetValueToDefault (); |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | OptionValueBoolean * |
| 74 | NamedOptionValue::GetBooleanValue () |
| 75 | { |
| 76 | if (GetValueType() == OptionValue::eTypeBoolean) |
| 77 | return static_cast<OptionValueBoolean *>(m_value_sp.get()); |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | OptionValueSInt64 * |
| 82 | NamedOptionValue::GetSInt64Value () |
| 83 | { |
| 84 | if (GetValueType() == OptionValue::eTypeSInt64) |
| 85 | return static_cast<OptionValueSInt64 *>(m_value_sp.get()); |
| 86 | return NULL; |
| 87 | } |
| 88 | |
| 89 | OptionValueUInt64 * |
| 90 | NamedOptionValue::GetUInt64Value () |
| 91 | { |
| 92 | if (GetValueType() == OptionValue::eTypeUInt64) |
| 93 | return static_cast<OptionValueUInt64 *>(m_value_sp.get()); |
| 94 | return NULL; |
| 95 | } |
| 96 | |
Greg Clayton | d12aeab | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 97 | OptionValueString * |
| 98 | NamedOptionValue::GetStringValue () |
| 99 | { |
| 100 | if (GetValueType() == OptionValue::eTypeString) |
| 101 | return static_cast<OptionValueString *>(m_value_sp.get()); |
| 102 | return NULL; |
| 103 | } |
Greg Clayton | 7406c39 | 2011-04-20 01:33:38 +0000 | [diff] [blame] | 104 | |
| 105 | OptionValueFileSpec * |
| 106 | NamedOptionValue::GetFileSpecValue () |
| 107 | { |
| 108 | if (GetValueType() == OptionValue::eTypeFileSpec) |
| 109 | return static_cast<OptionValueFileSpec *>(m_value_sp.get()); |
| 110 | return NULL; |
| 111 | } |
| 112 | |
| 113 | OptionValueArray * |
| 114 | NamedOptionValue::GetArrayValue () |
| 115 | { |
| 116 | if (GetValueType() == OptionValue::eTypeArray) |
| 117 | return static_cast<OptionValueArray *>(m_value_sp.get()); |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | OptionValueDictionary * |
| 122 | NamedOptionValue::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 | //------------------------------------------------------------------------- |
| 132 | void |
| 133 | OptionValueBoolean::DumpValue (Stream &strm) |
| 134 | { |
| 135 | strm.PutCString (m_current_value ? "true" : "false"); |
| 136 | } |
| 137 | |
| 138 | bool |
| 139 | OptionValueBoolean::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 | //------------------------------------------------------------------------- |
| 154 | void |
| 155 | OptionValueSInt64::DumpValue (Stream &strm) |
| 156 | { |
| 157 | strm.Printf ("%lli", m_current_value); |
| 158 | } |
| 159 | |
| 160 | bool |
| 161 | OptionValueSInt64::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 | //------------------------------------------------------------------------- |
| 176 | void |
| 177 | OptionValueUInt64::DumpValue (Stream &strm) |
| 178 | { |
| 179 | strm.Printf ("0x%llx", m_current_value); |
| 180 | } |
| 181 | |
| 182 | bool |
| 183 | OptionValueUInt64::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 Clayton | d12aeab | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 196 | // OptionValueDictionary |
| 197 | //------------------------------------------------------------------------- |
| 198 | void |
| 199 | OptionValueString::DumpValue (Stream &strm) |
| 200 | { |
| 201 | strm.Printf ("\"%s\"", m_current_value.c_str()); |
| 202 | } |
| 203 | |
| 204 | bool |
| 205 | OptionValueString::SetValueFromCString (const char *value_cstr) |
| 206 | { |
| 207 | SetCurrentValue (value_cstr); |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | |
| 213 | //------------------------------------------------------------------------- |
Greg Clayton | 7406c39 | 2011-04-20 01:33:38 +0000 | [diff] [blame] | 214 | // OptionValueFileSpec |
| 215 | //------------------------------------------------------------------------- |
| 216 | void |
| 217 | OptionValueFileSpec::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 | |
| 235 | bool |
| 236 | OptionValueFileSpec::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 | //------------------------------------------------------------------------- |
| 249 | void |
| 250 | OptionValueArray::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 | |
| 260 | bool |
| 261 | OptionValueArray::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 | //------------------------------------------------------------------------- |
| 270 | void |
| 271 | OptionValueDictionary::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 | |
| 282 | bool |
| 283 | OptionValueDictionary::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 | |