1 //===-- SBStructuredData.cpp ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBStructuredData.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Event.h"
14 #include "lldb/Core/StructuredData.h"
15 #include "lldb/Core/StructuredDataImpl.h"
16 #include "lldb/Target/StructuredDataPlugin.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/Stream.h"
21 using namespace lldb_private;
24 #pragma mark SBStructuredData
26 SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {}
28 SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
29 : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {}
31 SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
32 : m_impl_up(new StructuredDataImpl(event_sp)) {}
34 SBStructuredData::~SBStructuredData() {}
36 SBStructuredData &SBStructuredData::
37 operator=(const lldb::SBStructuredData &rhs) {
38 *m_impl_up = *rhs.m_impl_up;
42 lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
44 std::string json_str(stream.GetData());
46 StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str);
47 m_impl_up->SetObjectSP(json_obj);
49 if (!json_obj || json_obj->GetType() != StructuredData::Type::eTypeDictionary)
50 error.SetErrorString("Invalid Syntax");
54 bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); }
56 void SBStructuredData::Clear() { m_impl_up->Clear(); }
58 SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
60 error.SetError(m_impl_up->GetAsJSON(stream.ref()));
64 lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
65 Status error = m_impl_up->GetDescription(stream.ref());
67 sb_error.SetError(error);