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 | |
| 97 | |
| 98 | OptionValueFileSpec * |
| 99 | NamedOptionValue::GetFileSpecValue () |
| 100 | { |
| 101 | if (GetValueType() == OptionValue::eTypeFileSpec) |
| 102 | return static_cast<OptionValueFileSpec *>(m_value_sp.get()); |
| 103 | return NULL; |
| 104 | } |
| 105 | |
| 106 | OptionValueArray * |
| 107 | NamedOptionValue::GetArrayValue () |
| 108 | { |
| 109 | if (GetValueType() == OptionValue::eTypeArray) |
| 110 | return static_cast<OptionValueArray *>(m_value_sp.get()); |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | OptionValueDictionary * |
| 115 | NamedOptionValue::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 | //------------------------------------------------------------------------- |
| 125 | void |
| 126 | OptionValueBoolean::DumpValue (Stream &strm) |
| 127 | { |
| 128 | strm.PutCString (m_current_value ? "true" : "false"); |
| 129 | } |
| 130 | |
| 131 | bool |
| 132 | OptionValueBoolean::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 | //------------------------------------------------------------------------- |
| 147 | void |
| 148 | OptionValueSInt64::DumpValue (Stream &strm) |
| 149 | { |
| 150 | strm.Printf ("%lli", m_current_value); |
| 151 | } |
| 152 | |
| 153 | bool |
| 154 | OptionValueSInt64::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 | //------------------------------------------------------------------------- |
| 169 | void |
| 170 | OptionValueUInt64::DumpValue (Stream &strm) |
| 171 | { |
| 172 | strm.Printf ("0x%llx", m_current_value); |
| 173 | } |
| 174 | |
| 175 | bool |
| 176 | OptionValueUInt64::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 | //------------------------------------------------------------------------- |
| 191 | void |
| 192 | OptionValueFileSpec::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 | |
| 210 | bool |
| 211 | OptionValueFileSpec::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 | //------------------------------------------------------------------------- |
| 224 | void |
| 225 | OptionValueArray::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 | |
| 235 | bool |
| 236 | OptionValueArray::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 | //------------------------------------------------------------------------- |
| 245 | void |
| 246 | OptionValueDictionary::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 | |
| 257 | bool |
| 258 | OptionValueDictionary::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 | |