OptionValueFormat.cpp revision 321369
1254721Semaste//===-- OptionValueFormat.cpp -----------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/Interpreter/OptionValueFormat.h"
11254721Semaste
12254721Semaste// C Includes
13254721Semaste// C++ Includes
14254721Semaste// Other libraries and framework includes
15254721Semaste// Project includes
16254721Semaste#include "lldb/DataFormatters/FormatManager.h"
17254721Semaste#include "lldb/Interpreter/Args.h"
18321369Sdim#include "lldb/Utility/Stream.h"
19254721Semaste
20254721Semasteusing namespace lldb;
21254721Semasteusing namespace lldb_private;
22254721Semaste
23314564Sdimvoid OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
24314564Sdim                                  uint32_t dump_mask) {
25314564Sdim  if (dump_mask & eDumpOptionType)
26314564Sdim    strm.Printf("(%s)", GetTypeAsCString());
27314564Sdim  if (dump_mask & eDumpOptionValue) {
28254721Semaste    if (dump_mask & eDumpOptionType)
29314564Sdim      strm.PutCString(" = ");
30314564Sdim    strm.PutCString(FormatManager::GetFormatAsCString(m_current_value));
31314564Sdim  }
32254721Semaste}
33254721Semaste
34321369SdimStatus OptionValueFormat::SetValueFromString(llvm::StringRef value,
35321369Sdim                                             VarSetOperationType op) {
36321369Sdim  Status error;
37314564Sdim  switch (op) {
38314564Sdim  case eVarSetOperationClear:
39314564Sdim    Clear();
40314564Sdim    NotifyValueChanged();
41314564Sdim    break;
42314564Sdim
43314564Sdim  case eVarSetOperationReplace:
44314564Sdim  case eVarSetOperationAssign: {
45314564Sdim    Format new_format;
46314564Sdim    error = Args::StringToFormat(value.str().c_str(), new_format, nullptr);
47314564Sdim    if (error.Success()) {
48314564Sdim      m_value_was_set = true;
49314564Sdim      m_current_value = new_format;
50314564Sdim      NotifyValueChanged();
51254721Semaste    }
52314564Sdim  } break;
53314564Sdim
54314564Sdim  case eVarSetOperationInsertBefore:
55314564Sdim  case eVarSetOperationInsertAfter:
56314564Sdim  case eVarSetOperationRemove:
57314564Sdim  case eVarSetOperationAppend:
58314564Sdim  case eVarSetOperationInvalid:
59314564Sdim    error = OptionValue::SetValueFromString(value, op);
60314564Sdim    break;
61314564Sdim  }
62314564Sdim  return error;
63254721Semaste}
64254721Semaste
65314564Sdimlldb::OptionValueSP OptionValueFormat::DeepCopy() const {
66314564Sdim  return OptionValueSP(new OptionValueFormat(*this));
67254721Semaste}
68