blob: 56c95196d898bfeeb555564433a7fb526abd7c37 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
Caroline Ticeceb6b132010-10-26 03:11:13 +000015
16#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/ValueObjectList.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22SBValueList::SBValueList () :
Greg Clayton66111032010-06-23 01:19:29 +000023 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024{
Caroline Ticeceb6b132010-10-26 03:11:13 +000025 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
26
27 if (log)
28 log->Printf ("SBValueList::SBValueList () ==> this = %p", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029}
30
31SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000032 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033{
Caroline Ticeceb6b132010-10-26 03:11:13 +000034 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
35
36 if (log)
37 log->Printf ("SBValueList::SBValueList (const SBValueList &rhs) rhs.m_opaque_ap.get() = %p ==> this = %p",
38 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), this);
39
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040 if (rhs.IsValid())
Greg Clayton66111032010-06-23 01:19:29 +000041 m_opaque_ap.reset (new lldb_private::ValueObjectList (*rhs));
Caroline Ticeceb6b132010-10-26 03:11:13 +000042
43 if (log)
44 {
45 uint32_t num_vars = GetSize();
46 for (uint32_t i = 0; i < num_vars; ++i)
47 {
48 SBValue value = GetValueAtIndex (i);
49 SBStream sstr;
50 value.GetDescription (sstr);
51 log->Printf (" %s", sstr.GetData());
52 }
53 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054}
55
56SBValueList::SBValueList (const lldb_private::ValueObjectList *lldb_object_ptr) :
Greg Clayton66111032010-06-23 01:19:29 +000057 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058{
Caroline Ticeceb6b132010-10-26 03:11:13 +000059 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
60
61 if (log)
62 log->Printf ("SBValueList::SBValueList (const lldb_private::ValueObjectList *lldb_object_ptr) "
63 "lldb_object_ptr = %p ==> this = %p", lldb_object_ptr, this);
64
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 if (lldb_object_ptr)
Greg Clayton66111032010-06-23 01:19:29 +000066 m_opaque_ap.reset (new lldb_private::ValueObjectList (*lldb_object_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +000067
68 if (log)
69 {
70 uint32_t num_vars = GetSize();
71 for (uint32_t i = 0; i < num_vars; ++i)
72 {
73 SBValue value = GetValueAtIndex (i);
74 SBStream sstr;
75 value.GetDescription (sstr);
76 log->Printf (" %s", sstr.GetData());
77 }
78 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079}
80
81SBValueList::~SBValueList ()
82{
83}
84
85bool
86SBValueList::IsValid () const
87{
Greg Clayton66111032010-06-23 01:19:29 +000088 return (m_opaque_ap.get() != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089}
90
91const SBValueList &
92SBValueList::operator = (const SBValueList &rhs)
93{
94 if (this != &rhs)
95 {
96 if (rhs.IsValid())
Greg Clayton66111032010-06-23 01:19:29 +000097 m_opaque_ap.reset (new lldb_private::ValueObjectList (*rhs));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098 else
Greg Clayton66111032010-06-23 01:19:29 +000099 m_opaque_ap.reset ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100 }
101 return *this;
102}
103
104lldb_private::ValueObjectList *
105SBValueList::operator->()
106{
Greg Clayton66111032010-06-23 01:19:29 +0000107 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108}
109
110lldb_private::ValueObjectList &
111SBValueList::operator*()
112{
Greg Clayton66111032010-06-23 01:19:29 +0000113 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114}
115
116const lldb_private::ValueObjectList *
117SBValueList::operator->() const
118{
Greg Clayton66111032010-06-23 01:19:29 +0000119 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120}
121
122const lldb_private::ValueObjectList &
123SBValueList::operator*() const
124{
Greg Clayton66111032010-06-23 01:19:29 +0000125 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126}
127
128void
129SBValueList::Append (const SBValue &val_obj)
130{
131 if (val_obj.get())
132 {
133 CreateIfNeeded ();
Greg Clayton66111032010-06-23 01:19:29 +0000134 m_opaque_ap->Append (*val_obj);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 }
136}
137
138void
139SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
140{
141 if (val_obj_sp)
142 {
143 CreateIfNeeded ();
Greg Clayton66111032010-06-23 01:19:29 +0000144 m_opaque_ap->Append (val_obj_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 }
146}
147
148
149SBValue
150SBValueList::GetValueAtIndex (uint32_t idx) const
151{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000152 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
153
154 if (log)
155 log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
156
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157 SBValue sb_value;
Greg Clayton66111032010-06-23 01:19:29 +0000158 if (m_opaque_ap.get())
159 *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000160
161 if (log)
162 {
163 SBStream sstr;
164 sb_value.GetDescription (sstr);
165 log->Printf ("SBValueList::GetValueAtIndex ==> SBValue (this = %p, '%s')", &sb_value, sstr.GetData());
166 }
167
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168 return sb_value;
169}
170
171uint32_t
172SBValueList::GetSize () const
173{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000174 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
175
176 if (log)
177 log->Printf ("SBValueList::GetSize ()");
178
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179 uint32_t size = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000180 if (m_opaque_ap.get())
181 size = m_opaque_ap->GetSize();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000182
183 if (log)
184 log->Printf ("SBValueList::GetSize ==> %d", size);
185
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 return size;
187}
188
189void
190SBValueList::CreateIfNeeded ()
191{
Greg Clayton66111032010-06-23 01:19:29 +0000192 if (m_opaque_ap.get() == NULL)
193 m_opaque_ap.reset (new ValueObjectList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194}
195
196
197SBValue
198SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
199{
200 SBValue sb_value;
Greg Clayton66111032010-06-23 01:19:29 +0000201 if ( m_opaque_ap.get())
202 *sb_value = m_opaque_ap->FindValueObjectByUID (uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203 return sb_value;
204}
205