1 //===-- SBStructuredData.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/API/SBStructuredData.h" 11 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/Error.h" 18 #include "lldb/Utility/Stream.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 #pragma mark-- 24 #pragma mark SBStructuredData 25 26 SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {} 27 28 SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs) 29 : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {} 30 31 SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp) 32 : m_impl_up(new StructuredDataImpl(event_sp)) {} 33 34 SBStructuredData::~SBStructuredData() {} 35 36 SBStructuredData &SBStructuredData:: 37 operator=(const lldb::SBStructuredData &rhs) { 38 *m_impl_up = *rhs.m_impl_up; 39 return *this; 40 } 41 42 lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) { 43 lldb::SBError error; 44 std::string json_str(stream.GetData()); 45 46 StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str); 47 m_impl_up->SetObjectSP(json_obj); 48 49 if (!json_obj || json_obj->GetType() != StructuredData::Type::eTypeDictionary) 50 error.SetErrorString("Invalid Syntax"); 51 return error; 52 } 53 54 bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); } 55 56 void SBStructuredData::Clear() { m_impl_up->Clear(); } 57 58 SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const { 59 SBError error; 60 error.SetError(m_impl_up->GetAsJSON(stream.ref())); 61 return error; 62 } 63 64 lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const { 65 Error error = m_impl_up->GetDescription(stream.ref()); 66 SBError sb_error; 67 sb_error.SetError(error); 68 return sb_error; 69 } 70