blob: cba407befc120bea2f578aa48e434f70d7af160f [file] [log] [blame]
Greg Clayton73844aa2012-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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton73844aa2012-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
18#include "lldb/Core/FormatManager.h"
19#include "lldb/Core/Stream.h"
20#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();
46 break;
47
48 case eVarSetOperationReplace:
49 case eVarSetOperationAssign:
50 {
51 Format new_format;
52 error = Args::StringToFormat (value_cstr, new_format, NULL);
53 if (error.Success())
54 {
55 m_value_was_set = true;
56 m_current_value = new_format;
57 }
58 }
59 break;
60
61 case eVarSetOperationInsertBefore:
62 case eVarSetOperationInsertAfter:
63 case eVarSetOperationRemove:
64 case eVarSetOperationAppend:
65 case eVarSetOperationInvalid:
66 error = OptionValue::SetValueFromCString (value_cstr, op);
67 break;
68 }
69 return error;
70}
71
72
73lldb::OptionValueSP
74OptionValueFormat::DeepCopy () const
75{
76 return OptionValueSP(new OptionValueFormat(*this));
77}
78