blob: 2142f476adc17fc8f26c06e58d72d2afda398eb6 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBValueList.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
11#include "lldb/API/SBValueList.h"
12#include "lldb/API/SBValue.h"
Caroline Tice7826c882010-10-26 03:11:13 +000013#include "lldb/API/SBStream.h"
Caroline Tice7826c882010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/ValueObjectList.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20SBValueList::SBValueList () :
Greg Clayton63094e02010-06-23 01:19:29 +000021 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000022{
23}
24
25SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000026 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000027{
Greg Clayton917c0002011-06-29 22:09:02 +000028 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000029
Chris Lattner24943d22010-06-08 16:52:24 +000030 if (rhs.IsValid())
Greg Clayton917c0002011-06-29 22:09:02 +000031 m_opaque_ap.reset (new ValueObjectList (*rhs));
Caroline Tice7826c882010-10-26 03:11:13 +000032
33 if (log)
34 {
Caroline Tice61ba7ec2010-10-26 23:49:36 +000035 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
Greg Claytonbdcda462010-12-20 20:49:23 +000036 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
37 m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +000038 }
Chris Lattner24943d22010-06-08 16:52:24 +000039}
40
Greg Clayton917c0002011-06-29 22:09:02 +000041SBValueList::SBValueList (const ValueObjectList *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000042 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000043{
Greg Clayton917c0002011-06-29 22:09:02 +000044 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000045
Chris Lattner24943d22010-06-08 16:52:24 +000046 if (lldb_object_ptr)
Greg Clayton917c0002011-06-29 22:09:02 +000047 m_opaque_ap.reset (new ValueObjectList (*lldb_object_ptr));
Caroline Tice7826c882010-10-26 03:11:13 +000048
49 if (log)
50 {
Greg Claytonbdcda462010-12-20 20:49:23 +000051 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
52 lldb_object_ptr,
Caroline Tice61ba7ec2010-10-26 23:49:36 +000053 m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +000054 }
Chris Lattner24943d22010-06-08 16:52:24 +000055}
56
57SBValueList::~SBValueList ()
58{
59}
60
61bool
62SBValueList::IsValid () const
63{
Greg Clayton63094e02010-06-23 01:19:29 +000064 return (m_opaque_ap.get() != NULL);
Chris Lattner24943d22010-06-08 16:52:24 +000065}
66
Jim Inghame0bd5712011-12-19 20:39:44 +000067void
68SBValueList::Clear()
69{
70 m_opaque_ap.reset();
71}
72
Chris Lattner24943d22010-06-08 16:52:24 +000073const SBValueList &
74SBValueList::operator = (const SBValueList &rhs)
75{
76 if (this != &rhs)
77 {
78 if (rhs.IsValid())
Greg Clayton917c0002011-06-29 22:09:02 +000079 m_opaque_ap.reset (new ValueObjectList (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000080 else
Greg Clayton63094e02010-06-23 01:19:29 +000081 m_opaque_ap.reset ();
Chris Lattner24943d22010-06-08 16:52:24 +000082 }
83 return *this;
84}
85
Greg Clayton917c0002011-06-29 22:09:02 +000086ValueObjectList *
Chris Lattner24943d22010-06-08 16:52:24 +000087SBValueList::operator->()
88{
Greg Clayton63094e02010-06-23 01:19:29 +000089 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +000090}
91
Greg Clayton917c0002011-06-29 22:09:02 +000092ValueObjectList &
Chris Lattner24943d22010-06-08 16:52:24 +000093SBValueList::operator*()
94{
Greg Clayton63094e02010-06-23 01:19:29 +000095 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +000096}
97
Greg Clayton917c0002011-06-29 22:09:02 +000098const ValueObjectList *
Chris Lattner24943d22010-06-08 16:52:24 +000099SBValueList::operator->() const
100{
Greg Clayton63094e02010-06-23 01:19:29 +0000101 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000102}
103
Greg Clayton917c0002011-06-29 22:09:02 +0000104const ValueObjectList &
Chris Lattner24943d22010-06-08 16:52:24 +0000105SBValueList::operator*() const
106{
Greg Clayton63094e02010-06-23 01:19:29 +0000107 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000108}
109
110void
111SBValueList::Append (const SBValue &val_obj)
112{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000113 ValueObjectSP value_sp (val_obj.GetSP());
114 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000115 {
116 CreateIfNeeded ();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000117 m_opaque_ap->Append (value_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000118 }
119}
120
121void
122SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
123{
124 if (val_obj_sp)
125 {
126 CreateIfNeeded ();
Greg Clayton63094e02010-06-23 01:19:29 +0000127 m_opaque_ap->Append (val_obj_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000128 }
129}
130
Greg Clayton917c0002011-06-29 22:09:02 +0000131void
132SBValueList::Append (const lldb::SBValueList& value_list)
133{
134 if (value_list.IsValid())
135 {
136 CreateIfNeeded ();
137 m_opaque_ap->Append (*value_list);
138 }
139}
140
Chris Lattner24943d22010-06-08 16:52:24 +0000141
142SBValue
143SBValueList::GetValueAtIndex (uint32_t idx) const
144{
Greg Clayton917c0002011-06-29 22:09:02 +0000145 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000146
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000147 //if (log)
148 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000149
Chris Lattner24943d22010-06-08 16:52:24 +0000150 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000151 ValueObjectSP value_sp;
Greg Clayton63094e02010-06-23 01:19:29 +0000152 if (m_opaque_ap.get())
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000153 {
154 value_sp = m_opaque_ap->GetValueObjectAtIndex (idx);
155 sb_value.SetSP (value_sp);
156 }
Caroline Tice7826c882010-10-26 03:11:13 +0000157
158 if (log)
159 {
160 SBStream sstr;
161 sb_value.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000162 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000163 m_opaque_ap.get(), idx, value_sp.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000164 }
165
Chris Lattner24943d22010-06-08 16:52:24 +0000166 return sb_value;
167}
168
169uint32_t
170SBValueList::GetSize () const
171{
Greg Clayton917c0002011-06-29 22:09:02 +0000172 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000173
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000174 //if (log)
175 // log->Printf ("SBValueList::GetSize ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000176
Chris Lattner24943d22010-06-08 16:52:24 +0000177 uint32_t size = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000178 if (m_opaque_ap.get())
179 size = m_opaque_ap->GetSize();
Caroline Tice7826c882010-10-26 03:11:13 +0000180
181 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000182 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
Caroline Tice7826c882010-10-26 03:11:13 +0000183
Chris Lattner24943d22010-06-08 16:52:24 +0000184 return size;
185}
186
187void
188SBValueList::CreateIfNeeded ()
189{
Greg Clayton63094e02010-06-23 01:19:29 +0000190 if (m_opaque_ap.get() == NULL)
191 m_opaque_ap.reset (new ValueObjectList());
Chris Lattner24943d22010-06-08 16:52:24 +0000192}
193
194
195SBValue
196SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
197{
198 SBValue sb_value;
Greg Claytonbdcda462010-12-20 20:49:23 +0000199 if (m_opaque_ap.get())
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000200 sb_value.SetSP (m_opaque_ap->FindValueObjectByUID (uid));
Chris Lattner24943d22010-06-08 16:52:24 +0000201 return sb_value;
202}
203
Greg Clayton917c0002011-06-29 22:09:02 +0000204ValueObjectList *
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000205SBValueList::get ()
206{
207 return m_opaque_ap.get();
208}
209
Greg Clayton917c0002011-06-29 22:09:02 +0000210ValueObjectList &
211SBValueList::ref ()
212{
213 CreateIfNeeded();
214 return *m_opaque_ap.get();
215}
216
217