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() != eStructuredDataTypeDictionary)
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);
71 StructuredDataType SBStructuredData::GetType() const {
72 return (m_impl_up ? m_impl_up->GetType() : eStructuredDataTypeInvalid);
75 size_t SBStructuredData::GetSize() const {
76 return (m_impl_up ? m_impl_up->GetSize() : 0);
79 lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const {
81 return SBStructuredData();
83 SBStructuredData result;
84 result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key));
88 lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const {
90 return SBStructuredData();
92 SBStructuredData result;
93 result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx));
97 uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const {
98 return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value);
101 double SBStructuredData::GetFloatValue(double fail_value) const {
102 return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value);
105 bool SBStructuredData::GetBooleanValue(bool fail_value) const {
106 return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value);
109 size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const {
110 return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0);