blob: 9f911b757e38601dfac9c0dda9705b95e6101120 [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"
Chris Lattner24943d22010-06-08 16:52:24 +000014
Caroline Tice7826c882010-10-26 03:11:13 +000015
16#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/ValueObjectList.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22SBValueList::SBValueList () :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25}
26
27SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000028 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000029{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000030 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000031
Chris Lattner24943d22010-06-08 16:52:24 +000032 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000033 m_opaque_ap.reset (new lldb_private::ValueObjectList (*rhs));
Caroline Tice7826c882010-10-26 03:11:13 +000034
35 if (log)
36 {
Caroline Tice61ba7ec2010-10-26 23:49:36 +000037 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
38 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), m_opaque_ap.get());
39
Caroline Tice7826c882010-10-26 03:11:13 +000040 uint32_t num_vars = GetSize();
41 for (uint32_t i = 0; i < num_vars; ++i)
42 {
43 SBValue value = GetValueAtIndex (i);
44 SBStream sstr;
45 value.GetDescription (sstr);
46 log->Printf (" %s", sstr.GetData());
47 }
48 }
Chris Lattner24943d22010-06-08 16:52:24 +000049}
50
51SBValueList::SBValueList (const lldb_private::ValueObjectList *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000052 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000053{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000054 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000055
Chris Lattner24943d22010-06-08 16:52:24 +000056 if (lldb_object_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000057 m_opaque_ap.reset (new lldb_private::ValueObjectList (*lldb_object_ptr));
Caroline Tice7826c882010-10-26 03:11:13 +000058
59 if (log)
60 {
Caroline Tice61ba7ec2010-10-26 23:49:36 +000061 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p", lldb_object_ptr,
62 m_opaque_ap.get());
63
64
Caroline Tice7826c882010-10-26 03:11:13 +000065 uint32_t num_vars = GetSize();
66 for (uint32_t i = 0; i < num_vars; ++i)
67 {
68 SBValue value = GetValueAtIndex (i);
69 SBStream sstr;
70 value.GetDescription (sstr);
71 log->Printf (" %s", sstr.GetData());
72 }
73 }
Chris Lattner24943d22010-06-08 16:52:24 +000074}
75
76SBValueList::~SBValueList ()
77{
78}
79
80bool
81SBValueList::IsValid () const
82{
Greg Clayton63094e02010-06-23 01:19:29 +000083 return (m_opaque_ap.get() != NULL);
Chris Lattner24943d22010-06-08 16:52:24 +000084}
85
86const SBValueList &
87SBValueList::operator = (const SBValueList &rhs)
88{
89 if (this != &rhs)
90 {
91 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000092 m_opaque_ap.reset (new lldb_private::ValueObjectList (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000093 else
Greg Clayton63094e02010-06-23 01:19:29 +000094 m_opaque_ap.reset ();
Chris Lattner24943d22010-06-08 16:52:24 +000095 }
96 return *this;
97}
98
99lldb_private::ValueObjectList *
100SBValueList::operator->()
101{
Greg Clayton63094e02010-06-23 01:19:29 +0000102 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000103}
104
105lldb_private::ValueObjectList &
106SBValueList::operator*()
107{
Greg Clayton63094e02010-06-23 01:19:29 +0000108 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000109}
110
111const lldb_private::ValueObjectList *
112SBValueList::operator->() const
113{
Greg Clayton63094e02010-06-23 01:19:29 +0000114 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000115}
116
117const lldb_private::ValueObjectList &
118SBValueList::operator*() const
119{
Greg Clayton63094e02010-06-23 01:19:29 +0000120 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123void
124SBValueList::Append (const SBValue &val_obj)
125{
126 if (val_obj.get())
127 {
128 CreateIfNeeded ();
Greg Clayton63094e02010-06-23 01:19:29 +0000129 m_opaque_ap->Append (*val_obj);
Chris Lattner24943d22010-06-08 16:52:24 +0000130 }
131}
132
133void
134SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
135{
136 if (val_obj_sp)
137 {
138 CreateIfNeeded ();
Greg Clayton63094e02010-06-23 01:19:29 +0000139 m_opaque_ap->Append (val_obj_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000140 }
141}
142
143
144SBValue
145SBValueList::GetValueAtIndex (uint32_t idx) const
146{
Caroline Tice7826c882010-10-26 03:11:13 +0000147 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
148
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000149 //if (log)
150 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000151
Chris Lattner24943d22010-06-08 16:52:24 +0000152 SBValue sb_value;
Greg Clayton63094e02010-06-23 01:19:29 +0000153 if (m_opaque_ap.get())
154 *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000155
156 if (log)
157 {
158 SBStream sstr;
159 sb_value.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000160 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000161 m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000162 }
163
Chris Lattner24943d22010-06-08 16:52:24 +0000164 return sb_value;
165}
166
167uint32_t
168SBValueList::GetSize () const
169{
Caroline Tice7826c882010-10-26 03:11:13 +0000170 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
171
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000172 //if (log)
173 // log->Printf ("SBValueList::GetSize ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000174
Chris Lattner24943d22010-06-08 16:52:24 +0000175 uint32_t size = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000176 if (m_opaque_ap.get())
177 size = m_opaque_ap->GetSize();
Caroline Tice7826c882010-10-26 03:11:13 +0000178
179 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000180 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
Caroline Tice7826c882010-10-26 03:11:13 +0000181
Chris Lattner24943d22010-06-08 16:52:24 +0000182 return size;
183}
184
185void
186SBValueList::CreateIfNeeded ()
187{
Greg Clayton63094e02010-06-23 01:19:29 +0000188 if (m_opaque_ap.get() == NULL)
189 m_opaque_ap.reset (new ValueObjectList());
Chris Lattner24943d22010-06-08 16:52:24 +0000190}
191
192
193SBValue
194SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
195{
196 SBValue sb_value;
Greg Clayton63094e02010-06-23 01:19:29 +0000197 if ( m_opaque_ap.get())
198 *sb_value = m_opaque_ap->FindValueObjectByUID (uid);
Chris Lattner24943d22010-06-08 16:52:24 +0000199 return sb_value;
200}
201
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000202lldb_private::ValueObjectList *
203SBValueList::get ()
204{
205 return m_opaque_ap.get();
206}
207