175930019STodd Fiala //===-- SBStructuredData.cpp ------------------------------------*- C++ -*-===// 275930019STodd Fiala // 375930019STodd Fiala // The LLVM Compiler Infrastructure 475930019STodd Fiala // 575930019STodd Fiala // This file is distributed under the University of Illinois Open Source 675930019STodd Fiala // License. See LICENSE.TXT for details. 775930019STodd Fiala // 875930019STodd Fiala //===----------------------------------------------------------------------===// 975930019STodd Fiala 1075930019STodd Fiala #include "lldb/API/SBStructuredData.h" 1175930019STodd Fiala 1275930019STodd Fiala #include "lldb/API/SBStream.h" 1375930019STodd Fiala #include "lldb/Core/Event.h" 1475930019STodd Fiala #include "lldb/Core/StructuredData.h" 15*d5d8d91cSRavitheja Addepally #include "lldb/Core/StructuredDataImpl.h" 1675930019STodd Fiala #include "lldb/Target/StructuredDataPlugin.h" 17bf9a7730SZachary Turner #include "lldb/Utility/Error.h" 18bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 1975930019STodd Fiala 2075930019STodd Fiala using namespace lldb; 2175930019STodd Fiala using namespace lldb_private; 2275930019STodd Fiala 2375930019STodd Fiala #pragma mark-- 2475930019STodd Fiala #pragma mark SBStructuredData 2575930019STodd Fiala 262ef442c6STodd Fiala SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {} 2775930019STodd Fiala 28b9c1b51eSKate Stone SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs) 292ef442c6STodd Fiala : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {} 3075930019STodd Fiala 31b9c1b51eSKate Stone SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp) 322ef442c6STodd Fiala : m_impl_up(new StructuredDataImpl(event_sp)) {} 3375930019STodd Fiala 34b9c1b51eSKate Stone SBStructuredData::~SBStructuredData() {} 3575930019STodd Fiala 36b9c1b51eSKate Stone SBStructuredData &SBStructuredData:: 37b9c1b51eSKate Stone operator=(const lldb::SBStructuredData &rhs) { 3875930019STodd Fiala *m_impl_up = *rhs.m_impl_up; 3975930019STodd Fiala return *this; 4075930019STodd Fiala } 4175930019STodd Fiala 42*d5d8d91cSRavitheja Addepally lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) { 43*d5d8d91cSRavitheja Addepally lldb::SBError error; 44*d5d8d91cSRavitheja Addepally std::string json_str(stream.GetData()); 45*d5d8d91cSRavitheja Addepally 46*d5d8d91cSRavitheja Addepally StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str); 47*d5d8d91cSRavitheja Addepally m_impl_up->SetObjectSP(json_obj); 48*d5d8d91cSRavitheja Addepally 49*d5d8d91cSRavitheja Addepally if (!json_obj || json_obj->GetType() != StructuredData::Type::eTypeDictionary) 50*d5d8d91cSRavitheja Addepally error.SetErrorString("Invalid Syntax"); 51*d5d8d91cSRavitheja Addepally return error; 52*d5d8d91cSRavitheja Addepally } 53*d5d8d91cSRavitheja Addepally 54b9c1b51eSKate Stone bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); } 5575930019STodd Fiala 56b9c1b51eSKate Stone void SBStructuredData::Clear() { m_impl_up->Clear(); } 5775930019STodd Fiala 58b9c1b51eSKate Stone SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const { 59*d5d8d91cSRavitheja Addepally SBError error; 60*d5d8d91cSRavitheja Addepally error.SetError(m_impl_up->GetAsJSON(stream.ref())); 61*d5d8d91cSRavitheja Addepally return error; 6275930019STodd Fiala } 6375930019STodd Fiala 64b9c1b51eSKate Stone lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const { 652ef442c6STodd Fiala Error error = m_impl_up->GetDescription(stream.ref()); 662ef442c6STodd Fiala SBError sb_error; 672ef442c6STodd Fiala sb_error.SetError(error); 682ef442c6STodd Fiala return sb_error; 6975930019STodd Fiala } 70