1 //===-- 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"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Core/Log.h"
15 #include "lldb/Core/ValueObjectList.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 SBValueList::SBValueList () :
21     m_opaque_ap ()
22 {
23 }
24 
25 SBValueList::SBValueList (const SBValueList &rhs) :
26     m_opaque_ap ()
27 {
28     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
29 
30     if (rhs.IsValid())
31         m_opaque_ap.reset (new ValueObjectList (*rhs));
32 
33     if (log)
34     {
35         log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
36                      (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
37                      m_opaque_ap.get());
38     }
39 }
40 
41 SBValueList::SBValueList (const ValueObjectList *lldb_object_ptr) :
42     m_opaque_ap ()
43 {
44     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
45 
46     if (lldb_object_ptr)
47         m_opaque_ap.reset (new ValueObjectList (*lldb_object_ptr));
48 
49     if (log)
50     {
51         log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
52                      lldb_object_ptr,
53                      m_opaque_ap.get());
54     }
55 }
56 
57 SBValueList::~SBValueList ()
58 {
59 }
60 
61 bool
62 SBValueList::IsValid () const
63 {
64     return (m_opaque_ap.get() != NULL);
65 }
66 
67 void
68 SBValueList::Clear()
69 {
70     m_opaque_ap.reset();
71 }
72 
73 const SBValueList &
74 SBValueList::operator = (const SBValueList &rhs)
75 {
76     if (this != &rhs)
77     {
78         if (rhs.IsValid())
79             m_opaque_ap.reset (new ValueObjectList (*rhs));
80         else
81             m_opaque_ap.reset ();
82     }
83     return *this;
84 }
85 
86 ValueObjectList *
87 SBValueList::operator->()
88 {
89     return m_opaque_ap.get();
90 }
91 
92 ValueObjectList &
93 SBValueList::operator*()
94 {
95     return *m_opaque_ap;
96 }
97 
98 const ValueObjectList *
99 SBValueList::operator->() const
100 {
101     return m_opaque_ap.get();
102 }
103 
104 const ValueObjectList &
105 SBValueList::operator*() const
106 {
107     return *m_opaque_ap;
108 }
109 
110 void
111 SBValueList::Append (const SBValue &val_obj)
112 {
113     ValueObjectSP value_sp (val_obj.GetSP());
114     if (value_sp)
115     {
116         CreateIfNeeded ();
117         m_opaque_ap->Append (value_sp);
118     }
119 }
120 
121 void
122 SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
123 {
124     if (val_obj_sp)
125     {
126         CreateIfNeeded ();
127         m_opaque_ap->Append (val_obj_sp);
128     }
129 }
130 
131 void
132 SBValueList::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 
141 
142 SBValue
143 SBValueList::GetValueAtIndex (uint32_t idx) const
144 {
145     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
146 
147     //if (log)
148     //    log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
149 
150     SBValue sb_value;
151     ValueObjectSP value_sp;
152     if (m_opaque_ap.get())
153     {
154         value_sp = m_opaque_ap->GetValueObjectAtIndex (idx);
155         sb_value.SetSP (value_sp);
156     }
157 
158     if (log)
159     {
160         SBStream sstr;
161         sb_value.GetDescription (sstr);
162         log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
163                      m_opaque_ap.get(), idx, value_sp.get(), sstr.GetData());
164     }
165 
166     return sb_value;
167 }
168 
169 uint32_t
170 SBValueList::GetSize () const
171 {
172     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
173 
174     //if (log)
175     //    log->Printf ("SBValueList::GetSize ()");
176 
177     uint32_t size = 0;
178     if (m_opaque_ap.get())
179         size = m_opaque_ap->GetSize();
180 
181     if (log)
182         log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
183 
184     return size;
185 }
186 
187 void
188 SBValueList::CreateIfNeeded ()
189 {
190     if (m_opaque_ap.get() == NULL)
191         m_opaque_ap.reset (new ValueObjectList());
192 }
193 
194 
195 SBValue
196 SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
197 {
198     SBValue sb_value;
199     if (m_opaque_ap.get())
200         sb_value.SetSP (m_opaque_ap->FindValueObjectByUID (uid));
201     return sb_value;
202 }
203 
204 ValueObjectList *
205 SBValueList::get ()
206 {
207     return m_opaque_ap.get();
208 }
209 
210 ValueObjectList &
211 SBValueList::ref ()
212 {
213     CreateIfNeeded();
214     return *m_opaque_ap.get();
215 }
216 
217 
218