1 //===-- SBValueList.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBValueList.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
13 #include "lldb/Core/ValueObjectList.h"
14 #include "lldb/Utility/Log.h"
19 using namespace lldb_private;
23 ValueListImpl() : m_values() {}
25 ValueListImpl(const ValueListImpl &rhs) : m_values(rhs.m_values) {}
27 ValueListImpl &operator=(const ValueListImpl &rhs) {
30 m_values = rhs.m_values;
34 uint32_t GetSize() { return m_values.size(); }
36 void Append(const lldb::SBValue &sb_value) { m_values.push_back(sb_value); }
38 void Append(const ValueListImpl &list) {
39 for (auto val : list.m_values)
43 lldb::SBValue GetValueAtIndex(uint32_t index) {
44 if (index >= GetSize())
45 return lldb::SBValue();
46 return m_values[index];
49 lldb::SBValue FindValueByUID(lldb::user_id_t uid) {
50 for (auto val : m_values) {
51 if (val.IsValid() && val.GetID() == uid)
54 return lldb::SBValue();
57 lldb::SBValue GetFirstValueByName(const char *name) const {
59 for (auto val : m_values) {
60 if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0)
64 return lldb::SBValue();
68 std::vector<lldb::SBValue> m_values;
71 SBValueList::SBValueList() : m_opaque_ap() {}
73 SBValueList::SBValueList(const SBValueList &rhs) : m_opaque_ap() {
74 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
77 m_opaque_ap.reset(new ValueListImpl(*rhs));
81 "SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
82 static_cast<void *>(rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
83 static_cast<void *>(m_opaque_ap.get()));
87 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) : m_opaque_ap() {
88 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
91 m_opaque_ap.reset(new ValueListImpl(*lldb_object_ptr));
94 log->Printf("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
95 static_cast<const void *>(lldb_object_ptr),
96 static_cast<void *>(m_opaque_ap.get()));
100 SBValueList::~SBValueList() {}
102 bool SBValueList::IsValid() const { return (m_opaque_ap != NULL); }
104 void SBValueList::Clear() { m_opaque_ap.reset(); }
106 const SBValueList &SBValueList::operator=(const SBValueList &rhs) {
109 m_opaque_ap.reset(new ValueListImpl(*rhs));
116 ValueListImpl *SBValueList::operator->() { return m_opaque_ap.get(); }
118 ValueListImpl &SBValueList::operator*() { return *m_opaque_ap; }
120 const ValueListImpl *SBValueList::operator->() const {
121 return m_opaque_ap.get();
124 const ValueListImpl &SBValueList::operator*() const { return *m_opaque_ap; }
126 void SBValueList::Append(const SBValue &val_obj) {
128 m_opaque_ap->Append(val_obj);
131 void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
134 m_opaque_ap->Append(SBValue(val_obj_sp));
138 void SBValueList::Append(const lldb::SBValueList &value_list) {
139 if (value_list.IsValid()) {
141 m_opaque_ap->Append(*value_list);
145 SBValue SBValueList::GetValueAtIndex(uint32_t idx) const {
146 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
149 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d",
154 sb_value = m_opaque_ap->GetValueAtIndex(idx);
158 sb_value.GetDescription(sstr);
159 log->Printf("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue "
160 "(this.sp = %p, '%s')",
161 static_cast<void *>(m_opaque_ap.get()), idx,
162 static_cast<void *>(sb_value.GetSP().get()), sstr.GetData());
168 uint32_t SBValueList::GetSize() const {
169 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
172 // log->Printf ("SBValueList::GetSize ()");
176 size = m_opaque_ap->GetSize();
179 log->Printf("SBValueList::GetSize (this.ap=%p) => %d",
180 static_cast<void *>(m_opaque_ap.get()), size);
185 void SBValueList::CreateIfNeeded() {
186 if (m_opaque_ap == NULL)
187 m_opaque_ap.reset(new ValueListImpl());
190 SBValue SBValueList::FindValueObjectByUID(lldb::user_id_t uid) {
193 sb_value = m_opaque_ap->FindValueByUID(uid);
197 SBValue SBValueList::GetFirstValueByName(const char *name) const {
200 sb_value = m_opaque_ap->GetFirstValueByName(name);
204 void *SBValueList::opaque_ptr() { return m_opaque_ap.get(); }
206 ValueListImpl &SBValueList::ref() {