1 //===-- OptionValueFormat.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/OptionValueFormat.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/DataFormatters/FormatManager.h"
18 #include "lldb/Interpreter/Args.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
23 void
24 OptionValueFormat::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
25 {
26     if (dump_mask & eDumpOptionType)
27         strm.Printf ("(%s)", GetTypeAsCString ());
28     if (dump_mask & eDumpOptionValue)
29     {
30         if (dump_mask & eDumpOptionType)
31             strm.PutCString (" = ");
32         strm.PutCString (FormatManager::GetFormatAsCString (m_current_value));
33     }
34 }
35 
36 Error
37 OptionValueFormat::SetValueFromString (llvm::StringRef value, VarSetOperationType op)
38 {
39     Error error;
40     switch (op)
41     {
42     case eVarSetOperationClear:
43         Clear();
44         NotifyValueChanged();
45         break;
46 
47     case eVarSetOperationReplace:
48     case eVarSetOperationAssign:
49         {
50             Format new_format;
51             error = Args::StringToFormat (value.str().c_str(), new_format, nullptr);
52             if (error.Success())
53             {
54                 m_value_was_set = true;
55                 m_current_value = new_format;
56                 NotifyValueChanged();
57             }
58         }
59         break;
60 
61     case eVarSetOperationInsertBefore:
62     case eVarSetOperationInsertAfter:
63     case eVarSetOperationRemove:
64     case eVarSetOperationAppend:
65     case eVarSetOperationInvalid:
66         error = OptionValue::SetValueFromString (value, op);
67         break;
68     }
69     return error;
70 }
71 
72 
73 lldb::OptionValueSP
74 OptionValueFormat::DeepCopy () const
75 {
76     return OptionValueSP(new OptionValueFormat(*this));
77 }
78 
79