Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1 | //===-- OptionValueUInt64.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/OptionValueUInt64.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/Stream.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 17 | #include "lldb/Host/StringConvert.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | lldb::OptionValueSP |
| 23 | OptionValueUInt64::Create (const char *value_cstr, Error &error) |
| 24 | { |
| 25 | lldb::OptionValueSP value_sp (new OptionValueUInt64()); |
| 26 | error = value_sp->SetValueFromCString (value_cstr); |
| 27 | if (error.Fail()) |
| 28 | value_sp.reset(); |
| 29 | return value_sp; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | void |
| 34 | OptionValueUInt64::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) |
| 35 | { |
| 36 | if (dump_mask & eDumpOptionType) |
| 37 | strm.Printf ("(%s)", GetTypeAsCString ()); |
| 38 | if (dump_mask & eDumpOptionValue) |
| 39 | { |
| 40 | if (dump_mask & eDumpOptionType) |
| 41 | strm.PutCString (" = "); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 42 | strm.Printf ("%" PRIu64, m_current_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | Error |
| 47 | OptionValueUInt64::SetValueFromCString (const char *value_cstr, VarSetOperationType op) |
| 48 | { |
| 49 | Error error; |
| 50 | switch (op) |
| 51 | { |
| 52 | case eVarSetOperationClear: |
| 53 | Clear (); |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 54 | NotifyValueChanged(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 55 | break; |
| 56 | |
| 57 | case eVarSetOperationReplace: |
| 58 | case eVarSetOperationAssign: |
| 59 | { |
| 60 | bool success = false; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 61 | uint64_t value = StringConvert::ToUInt64 (value_cstr, 0, 0, &success); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 62 | if (success) |
| 63 | { |
| 64 | m_value_was_set = true; |
| 65 | m_current_value = value; |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 66 | NotifyValueChanged(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 67 | } |
| 68 | else |
| 69 | { |
| 70 | error.SetErrorStringWithFormat ("invalid uint64_t string value: '%s'", value_cstr); |
| 71 | } |
| 72 | } |
| 73 | break; |
| 74 | |
| 75 | case eVarSetOperationInsertBefore: |
| 76 | case eVarSetOperationInsertAfter: |
| 77 | case eVarSetOperationRemove: |
| 78 | case eVarSetOperationAppend: |
| 79 | case eVarSetOperationInvalid: |
| 80 | error = OptionValue::SetValueFromCString (value_cstr, op); |
| 81 | break; |
| 82 | } |
| 83 | return error; |
| 84 | } |
| 85 | |
| 86 | lldb::OptionValueSP |
| 87 | OptionValueUInt64::DeepCopy () const |
| 88 | { |
| 89 | return OptionValueSP(new OptionValueUInt64(*this)); |
| 90 | } |
| 91 | |