blob: 4e0fea5688c5dc2f4c100bfad8d1b92765921dce [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Ticeceb6b132010-10-26 03:11:13 +000013#include "lldb/API/SBStream.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/ValueObjectList.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20SBValueList::SBValueList () :
Greg Clayton66111032010-06-23 01:19:29 +000021 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022{
23}
24
25SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000026 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027{
Greg Claytondea8cb42011-06-29 22:09:02 +000028 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000029
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030 if (rhs.IsValid())
Greg Claytondea8cb42011-06-29 22:09:02 +000031 m_opaque_ap.reset (new ValueObjectList (*rhs));
Caroline Ticeceb6b132010-10-26 03:11:13 +000032
33 if (log)
34 {
Caroline Tice750cd172010-10-26 23:49:36 +000035 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
Greg Claytonaf67cec2010-12-20 20:49:23 +000036 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
37 m_opaque_ap.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +000038 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039}
40
Greg Claytondea8cb42011-06-29 22:09:02 +000041SBValueList::SBValueList (const ValueObjectList *lldb_object_ptr) :
Greg Clayton66111032010-06-23 01:19:29 +000042 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043{
Greg Claytondea8cb42011-06-29 22:09:02 +000044 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000045
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 if (lldb_object_ptr)
Greg Claytondea8cb42011-06-29 22:09:02 +000047 m_opaque_ap.reset (new ValueObjectList (*lldb_object_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +000048
49 if (log)
50 {
Greg Claytonaf67cec2010-12-20 20:49:23 +000051 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
52 lldb_object_ptr,
Caroline Tice750cd172010-10-26 23:49:36 +000053 m_opaque_ap.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +000054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055}
56
57SBValueList::~SBValueList ()
58{
59}
60
61bool
62SBValueList::IsValid () const
63{
Greg Clayton66111032010-06-23 01:19:29 +000064 return (m_opaque_ap.get() != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065}
66
67const SBValueList &
68SBValueList::operator = (const SBValueList &rhs)
69{
70 if (this != &rhs)
71 {
72 if (rhs.IsValid())
Greg Claytondea8cb42011-06-29 22:09:02 +000073 m_opaque_ap.reset (new ValueObjectList (*rhs));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074 else
Greg Clayton66111032010-06-23 01:19:29 +000075 m_opaque_ap.reset ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 }
77 return *this;
78}
79
Greg Claytondea8cb42011-06-29 22:09:02 +000080ValueObjectList *
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081SBValueList::operator->()
82{
Greg Clayton66111032010-06-23 01:19:29 +000083 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084}
85
Greg Claytondea8cb42011-06-29 22:09:02 +000086ValueObjectList &
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087SBValueList::operator*()
88{
Greg Clayton66111032010-06-23 01:19:29 +000089 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090}
91
Greg Claytondea8cb42011-06-29 22:09:02 +000092const ValueObjectList *
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093SBValueList::operator->() const
94{
Greg Clayton66111032010-06-23 01:19:29 +000095 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096}
97
Greg Claytondea8cb42011-06-29 22:09:02 +000098const ValueObjectList &
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099SBValueList::operator*() const
100{
Greg Clayton66111032010-06-23 01:19:29 +0000101 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102}
103
104void
105SBValueList::Append (const SBValue &val_obj)
106{
107 if (val_obj.get())
108 {
109 CreateIfNeeded ();
Greg Clayton66111032010-06-23 01:19:29 +0000110 m_opaque_ap->Append (*val_obj);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 }
112}
113
114void
115SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
116{
117 if (val_obj_sp)
118 {
119 CreateIfNeeded ();
Greg Clayton66111032010-06-23 01:19:29 +0000120 m_opaque_ap->Append (val_obj_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121 }
122}
123
Greg Claytondea8cb42011-06-29 22:09:02 +0000124void
125SBValueList::Append (const lldb::SBValueList& value_list)
126{
127 if (value_list.IsValid())
128 {
129 CreateIfNeeded ();
130 m_opaque_ap->Append (*value_list);
131 }
132}
133
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134
135SBValue
136SBValueList::GetValueAtIndex (uint32_t idx) const
137{
Greg Claytondea8cb42011-06-29 22:09:02 +0000138 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000139
Caroline Tice750cd172010-10-26 23:49:36 +0000140 //if (log)
141 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000142
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143 SBValue sb_value;
Greg Clayton66111032010-06-23 01:19:29 +0000144 if (m_opaque_ap.get())
145 *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000146
147 if (log)
148 {
149 SBStream sstr;
150 sb_value.GetDescription (sstr);
Caroline Tice750cd172010-10-26 23:49:36 +0000151 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Greg Clayton93aa84e2010-10-29 04:59:35 +0000152 m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000153 }
154
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155 return sb_value;
156}
157
158uint32_t
159SBValueList::GetSize () const
160{
Greg Claytondea8cb42011-06-29 22:09:02 +0000161 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000162
Caroline Tice750cd172010-10-26 23:49:36 +0000163 //if (log)
164 // log->Printf ("SBValueList::GetSize ()");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000165
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166 uint32_t size = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000167 if (m_opaque_ap.get())
168 size = m_opaque_ap->GetSize();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000169
170 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +0000171 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000172
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173 return size;
174}
175
176void
177SBValueList::CreateIfNeeded ()
178{
Greg Clayton66111032010-06-23 01:19:29 +0000179 if (m_opaque_ap.get() == NULL)
180 m_opaque_ap.reset (new ValueObjectList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181}
182
183
184SBValue
185SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
186{
187 SBValue sb_value;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000188 if (m_opaque_ap.get())
Greg Clayton66111032010-06-23 01:19:29 +0000189 *sb_value = m_opaque_ap->FindValueObjectByUID (uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 return sb_value;
191}
192
Greg Claytondea8cb42011-06-29 22:09:02 +0000193ValueObjectList *
Caroline Tice750cd172010-10-26 23:49:36 +0000194SBValueList::get ()
195{
196 return m_opaque_ap.get();
197}
198
Greg Claytondea8cb42011-06-29 22:09:02 +0000199ValueObjectList &
200SBValueList::ref ()
201{
202 CreateIfNeeded();
203 return *m_opaque_ap.get();
204}
205
206