blob: d506410f6d80435b7a844c90bb48c04998dcd650 [file] [log] [blame]
Todd Fiala75930012016-08-19 04:21:48 +00001//===-- 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"
Todd Fiala75930012016-08-19 04:21:48 +000013#include "lldb/Core/Event.h"
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000014#include "lldb/Core/StructuredDataImpl.h"
Todd Fiala75930012016-08-19 04:21:48 +000015#include "lldb/Target/StructuredDataPlugin.h"
Zachary Turner97206d52017-05-12 04:51:55 +000016#include "lldb/Utility/Status.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000017#include "lldb/Utility/Stream.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000018#include "lldb/Utility/StructuredData.h"
Todd Fiala75930012016-08-19 04:21:48 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#pragma mark--
Todd Fiala75930012016-08-19 04:21:48 +000024#pragma mark SBStructuredData
25
Todd Fiala2ef442c2016-11-09 23:21:04 +000026SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {}
Todd Fiala75930012016-08-19 04:21:48 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
Todd Fiala2ef442c2016-11-09 23:21:04 +000029 : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {}
Kate Stoneb9c1b512016-09-06 20:57:50 +000030
31SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
Todd Fiala2ef442c2016-11-09 23:21:04 +000032 : m_impl_up(new StructuredDataImpl(event_sp)) {}
Kate Stoneb9c1b512016-09-06 20:57:50 +000033
34SBStructuredData::~SBStructuredData() {}
35
36SBStructuredData &SBStructuredData::
37operator=(const lldb::SBStructuredData &rhs) {
38 *m_impl_up = *rhs.m_impl_up;
39 return *this;
Todd Fiala75930012016-08-19 04:21:48 +000040}
41
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000042lldb::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
Abhishek Aggarwal5bfee5f2017-05-29 08:25:46 +000049 if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000050 error.SetErrorString("Invalid Syntax");
51 return error;
52}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); }
55
56void SBStructuredData::Clear() { m_impl_up->Clear(); }
57
58SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000059 SBError error;
60 error.SetError(m_impl_up->GetAsJSON(stream.ref()));
61 return error;
Todd Fiala75930012016-08-19 04:21:48 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
Zachary Turner97206d52017-05-12 04:51:55 +000065 Status error = m_impl_up->GetDescription(stream.ref());
Todd Fiala2ef442c2016-11-09 23:21:04 +000066 SBError sb_error;
67 sb_error.SetError(error);
68 return sb_error;
Todd Fiala75930012016-08-19 04:21:48 +000069}
Abhishek Aggarwal5bfee5f2017-05-29 08:25:46 +000070
71StructuredDataType SBStructuredData::GetType() const {
72 return (m_impl_up ? m_impl_up->GetType() : eStructuredDataTypeInvalid);
73}
74
75size_t SBStructuredData::GetSize() const {
76 return (m_impl_up ? m_impl_up->GetSize() : 0);
77}
78
79lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const {
80 if (!m_impl_up)
81 return SBStructuredData();
82
83 SBStructuredData result;
84 result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key));
85 return result;
86}
87
88lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const {
89 if (!m_impl_up)
90 return SBStructuredData();
91
92 SBStructuredData result;
93 result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx));
94 return result;
95}
96
97uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const {
98 return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value);
99}
100
101double SBStructuredData::GetFloatValue(double fail_value) const {
102 return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value);
103}
104
105bool SBStructuredData::GetBooleanValue(bool fail_value) const {
106 return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value);
107}
108
109size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const {
110 return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0);
111}