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 const SBValueList &
68 SBValueList::operator = (const SBValueList &rhs)
69 {
70     if (this != &rhs)
71     {
72         if (rhs.IsValid())
73             m_opaque_ap.reset (new ValueObjectList (*rhs));
74         else
75             m_opaque_ap.reset ();
76     }
77     return *this;
78 }
79 
80 ValueObjectList *
81 SBValueList::operator->()
82 {
83     return m_opaque_ap.get();
84 }
85 
86 ValueObjectList &
87 SBValueList::operator*()
88 {
89     return *m_opaque_ap;
90 }
91 
92 const ValueObjectList *
93 SBValueList::operator->() const
94 {
95     return m_opaque_ap.get();
96 }
97 
98 const ValueObjectList &
99 SBValueList::operator*() const
100 {
101     return *m_opaque_ap;
102 }
103 
104 void
105 SBValueList::Append (const SBValue &val_obj)
106 {
107     if (val_obj.get())
108     {
109         CreateIfNeeded ();
110         m_opaque_ap->Append (*val_obj);
111     }
112 }
113 
114 void
115 SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
116 {
117     if (val_obj_sp)
118     {
119         CreateIfNeeded ();
120         m_opaque_ap->Append (val_obj_sp);
121     }
122 }
123 
124 void
125 SBValueList::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 
134 
135 SBValue
136 SBValueList::GetValueAtIndex (uint32_t idx) const
137 {
138     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
139 
140     //if (log)
141     //    log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
142 
143     SBValue sb_value;
144     if (m_opaque_ap.get())
145         *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx);
146 
147     if (log)
148     {
149         SBStream sstr;
150         sb_value.GetDescription (sstr);
151         log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
152                      m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData());
153     }
154 
155     return sb_value;
156 }
157 
158 uint32_t
159 SBValueList::GetSize () const
160 {
161     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
162 
163     //if (log)
164     //    log->Printf ("SBValueList::GetSize ()");
165 
166     uint32_t size = 0;
167     if (m_opaque_ap.get())
168         size = m_opaque_ap->GetSize();
169 
170     if (log)
171         log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
172 
173     return size;
174 }
175 
176 void
177 SBValueList::CreateIfNeeded ()
178 {
179     if (m_opaque_ap.get() == NULL)
180         m_opaque_ap.reset (new ValueObjectList());
181 }
182 
183 
184 SBValue
185 SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
186 {
187     SBValue sb_value;
188     if (m_opaque_ap.get())
189         *sb_value = m_opaque_ap->FindValueObjectByUID (uid);
190     return sb_value;
191 }
192 
193 ValueObjectList *
194 SBValueList::get ()
195 {
196     return m_opaque_ap.get();
197 }
198 
199 ValueObjectList &
200 SBValueList::ref ()
201 {
202     CreateIfNeeded();
203     return *m_opaque_ap.get();
204 }
205 
206 
207