blob: b414802b963b5d682df28544e8c6607c34ffac36 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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 Harron5275aaa2015-01-15 20:08:35 +000017#include "lldb/Host/StringConvert.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000018
19using namespace lldb;
20using namespace lldb_private;
21
22lldb::OptionValueSP
23OptionValueUInt64::Create (const char *value_cstr, Error &error)
24{
25 lldb::OptionValueSP value_sp (new OptionValueUInt64());
Pavel Labathc95f7e22015-02-20 11:14:59 +000026 error = value_sp->SetValueFromString (value_cstr);
Greg Clayton67cc0632012-08-22 17:17:09 +000027 if (error.Fail())
28 value_sp.reset();
29 return value_sp;
30}
31
32
33void
34OptionValueUInt64::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 Malead01b2952012-11-29 21:49:15 +000042 strm.Printf ("%" PRIu64, m_current_value);
Greg Clayton67cc0632012-08-22 17:17:09 +000043 }
44}
45
46Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000047OptionValueUInt64::SetValueFromString (llvm::StringRef value_ref, VarSetOperationType op)
Greg Clayton67cc0632012-08-22 17:17:09 +000048{
49 Error error;
50 switch (op)
51 {
52 case eVarSetOperationClear:
53 Clear ();
Greg Clayton332e8b12015-01-13 21:13:08 +000054 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000055 break;
56
57 case eVarSetOperationReplace:
58 case eVarSetOperationAssign:
59 {
60 bool success = false;
Pavel Labathc95f7e22015-02-20 11:14:59 +000061 std::string value_str = value_ref.trim().str();
Pavel Labathdf50f942015-02-16 13:13:39 +000062 uint64_t value = StringConvert::ToUInt64 (value_str.c_str(), 0, 0, &success);
Greg Clayton67cc0632012-08-22 17:17:09 +000063 if (success)
64 {
65 m_value_was_set = true;
66 m_current_value = value;
Greg Clayton332e8b12015-01-13 21:13:08 +000067 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000068 }
69 else
70 {
Pavel Labathc95f7e22015-02-20 11:14:59 +000071 error.SetErrorStringWithFormat ("invalid uint64_t string value: '%s'", value_str.c_str());
Greg Clayton67cc0632012-08-22 17:17:09 +000072 }
73 }
74 break;
75
76 case eVarSetOperationInsertBefore:
77 case eVarSetOperationInsertAfter:
78 case eVarSetOperationRemove:
79 case eVarSetOperationAppend:
80 case eVarSetOperationInvalid:
Pavel Labathc95f7e22015-02-20 11:14:59 +000081 error = OptionValue::SetValueFromString (value_ref, op);
Greg Clayton67cc0632012-08-22 17:17:09 +000082 break;
83 }
84 return error;
85}
86
87lldb::OptionValueSP
88OptionValueUInt64::DeepCopy () const
89{
90 return OptionValueSP(new OptionValueUInt64(*this));
91}
92