blob: c5932b02c86bfe18f1731debaaa62ab417ee3f50 [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{
113 if (val_obj.get())
114 {
115 CreateIfNeeded ();
Greg Clayton63094e02010-06-23 01:19:29 +0000116 m_opaque_ap->Append (*val_obj);
Chris Lattner24943d22010-06-08 16:52:24 +0000117 }
118}
119
120void
121SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
122{
123 if (val_obj_sp)
124 {
125 CreateIfNeeded ();
Greg Clayton63094e02010-06-23 01:19:29 +0000126 m_opaque_ap->Append (val_obj_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000127 }
128}
129
Greg Clayton917c0002011-06-29 22:09:02 +0000130void
131SBValueList::Append (const lldb::SBValueList& value_list)
132{
133 if (value_list.IsValid())
134 {
135 CreateIfNeeded ();
136 m_opaque_ap->Append (*value_list);
137 }
138}
139
Chris Lattner24943d22010-06-08 16:52:24 +0000140
141SBValue
142SBValueList::GetValueAtIndex (uint32_t idx) const
143{
Greg Clayton917c0002011-06-29 22:09:02 +0000144 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000145
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000146 //if (log)
147 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000148
Chris Lattner24943d22010-06-08 16:52:24 +0000149 SBValue sb_value;
Greg Clayton63094e02010-06-23 01:19:29 +0000150 if (m_opaque_ap.get())
151 *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000152
153 if (log)
154 {
155 SBStream sstr;
156 sb_value.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000157 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000158 m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000159 }
160
Chris Lattner24943d22010-06-08 16:52:24 +0000161 return sb_value;
162}
163
164uint32_t
165SBValueList::GetSize () const
166{
Greg Clayton917c0002011-06-29 22:09:02 +0000167 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000168
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000169 //if (log)
170 // log->Printf ("SBValueList::GetSize ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000171
Chris Lattner24943d22010-06-08 16:52:24 +0000172 uint32_t size = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000173 if (m_opaque_ap.get())
174 size = m_opaque_ap->GetSize();
Caroline Tice7826c882010-10-26 03:11:13 +0000175
176 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000177 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
Caroline Tice7826c882010-10-26 03:11:13 +0000178
Chris Lattner24943d22010-06-08 16:52:24 +0000179 return size;
180}
181
182void
183SBValueList::CreateIfNeeded ()
184{
Greg Clayton63094e02010-06-23 01:19:29 +0000185 if (m_opaque_ap.get() == NULL)
186 m_opaque_ap.reset (new ValueObjectList());
Chris Lattner24943d22010-06-08 16:52:24 +0000187}
188
189
190SBValue
191SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
192{
193 SBValue sb_value;
Greg Claytonbdcda462010-12-20 20:49:23 +0000194 if (m_opaque_ap.get())
Greg Clayton63094e02010-06-23 01:19:29 +0000195 *sb_value = m_opaque_ap->FindValueObjectByUID (uid);
Chris Lattner24943d22010-06-08 16:52:24 +0000196 return sb_value;
197}
198
Greg Clayton917c0002011-06-29 22:09:02 +0000199ValueObjectList *
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000200SBValueList::get ()
201{
202 return m_opaque_ap.get();
203}
204
Greg Clayton917c0002011-06-29 22:09:02 +0000205ValueObjectList &
206SBValueList::ref ()
207{
208 CreateIfNeeded();
209 return *m_opaque_ap.get();
210}
211
212