blob: d91f10b0edeb151e5e32e5e94220c7b345853049 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton67cc0632012-08-22 17:17:09 +000012#include "lldb/Interpreter/OptionValueFormat.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Greg Clayton67cc0632012-08-22 17:17:09 +000018#include "lldb/Core/Stream.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000019#include "lldb/DataFormatters/FormatManager.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000020#include "lldb/Interpreter/Args.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
25void
26OptionValueFormat::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
27{
28 if (dump_mask & eDumpOptionType)
29 strm.Printf ("(%s)", GetTypeAsCString ());
30 if (dump_mask & eDumpOptionValue)
31 {
32 if (dump_mask & eDumpOptionType)
33 strm.PutCString (" = ");
34 strm.PutCString (FormatManager::GetFormatAsCString (m_current_value));
35 }
36}
37
38Error
39OptionValueFormat::SetValueFromCString (const char *value_cstr, VarSetOperationType op)
40{
41 Error error;
42 switch (op)
43 {
44 case eVarSetOperationClear:
45 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000046 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000047 break;
48
49 case eVarSetOperationReplace:
50 case eVarSetOperationAssign:
51 {
52 Format new_format;
Ed Masted78c9572014-04-20 00:31:37 +000053 error = Args::StringToFormat (value_cstr, new_format, nullptr);
Greg Clayton67cc0632012-08-22 17:17:09 +000054 if (error.Success())
55 {
56 m_value_was_set = true;
57 m_current_value = new_format;
Greg Clayton332e8b12015-01-13 21:13:08 +000058 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000059 }
60 }
61 break;
62
63 case eVarSetOperationInsertBefore:
64 case eVarSetOperationInsertAfter:
65 case eVarSetOperationRemove:
66 case eVarSetOperationAppend:
67 case eVarSetOperationInvalid:
68 error = OptionValue::SetValueFromCString (value_cstr, op);
69 break;
70 }
71 return error;
72}
73
74
75lldb::OptionValueSP
76OptionValueFormat::DeepCopy () const
77{
78 return OptionValueSP(new OptionValueFormat(*this));
79}
80