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->SetValueFromString (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::SetValueFromString (llvm::StringRef value_ref, 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             std::string value_str = value_ref.trim().str();
62             uint64_t value = StringConvert::ToUInt64 (value_str.c_str(), 0, 0, &success);
63             if (success)
64             {
65                 m_value_was_set = true;
66                 m_current_value = value;
67                 NotifyValueChanged();
68             }
69             else
70             {
71                 error.SetErrorStringWithFormat ("invalid uint64_t string value: '%s'", value_str.c_str());
72             }
73         }
74             break;
75 
76         case eVarSetOperationInsertBefore:
77         case eVarSetOperationInsertAfter:
78         case eVarSetOperationRemove:
79         case eVarSetOperationAppend:
80         case eVarSetOperationInvalid:
81             error = OptionValue::SetValueFromString (value_ref, op);
82             break;
83     }
84     return error;
85 }
86 
87 lldb::OptionValueSP
88 OptionValueUInt64::DeepCopy () const
89 {
90     return OptionValueSP(new OptionValueUInt64(*this));
91 }
92 
93