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"
17 #include "lldb/Host/StringConvert.h"
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 (" = ");
42         strm.Printf ("%" PRIu64, m_current_value);
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 ();
54             NotifyValueChanged();
55             break;
56 
57         case eVarSetOperationReplace:
58         case eVarSetOperationAssign:
59         {
60             bool success = false;
61             uint64_t value = StringConvert::ToUInt64 (value_cstr, 0, 0, &success);
62             if (success)
63             {
64                 m_value_was_set = true;
65                 m_current_value = value;
66                 NotifyValueChanged();
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 
92