1//===-- ValueObjectList.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Core/ValueObjectList.h"
10
11#include "lldb/Core/ValueObject.h"
12#include "lldb/Utility/ConstString.h"
13
14#include <utility>
15
16using namespace lldb;
17using namespace lldb_private;
18
19const ValueObjectList &ValueObjectList::operator=(const ValueObjectList &rhs) {
20 if (this != &rhs)
21 m_value_objects = rhs.m_value_objects;
22 return *this;
23}
24
25void ValueObjectList::Append(const ValueObjectSP &val_obj_sp) {
26 m_value_objects.push_back(x: val_obj_sp);
27}
28
29void ValueObjectList::Append(const ValueObjectList &valobj_list) {
30 std::copy(first: valobj_list.m_value_objects.begin(), // source begin
31 last: valobj_list.m_value_objects.end(), // source end
32 result: back_inserter(x&: m_value_objects)); // destination
33}
34
35size_t ValueObjectList::GetSize() const { return m_value_objects.size(); }
36
37void ValueObjectList::Resize(size_t size) { m_value_objects.resize(new_size: size); }
38
39lldb::ValueObjectSP ValueObjectList::GetValueObjectAtIndex(size_t idx) {
40 lldb::ValueObjectSP valobj_sp;
41 if (idx < m_value_objects.size())
42 valobj_sp = m_value_objects[idx];
43 return valobj_sp;
44}
45
46lldb::ValueObjectSP ValueObjectList::RemoveValueObjectAtIndex(size_t idx) {
47 lldb::ValueObjectSP valobj_sp;
48 if (idx < m_value_objects.size()) {
49 valobj_sp = m_value_objects[idx];
50 m_value_objects.erase(position: m_value_objects.begin() + idx);
51 }
52 return valobj_sp;
53}
54
55void ValueObjectList::SetValueObjectAtIndex(size_t idx,
56 const ValueObjectSP &valobj_sp) {
57 if (idx >= m_value_objects.size())
58 m_value_objects.resize(new_size: idx + 1);
59 m_value_objects[idx] = valobj_sp;
60}
61
62ValueObjectSP ValueObjectList::FindValueObjectByValueName(const char *name) {
63 ConstString name_const_str(name);
64 ValueObjectSP val_obj_sp;
65 collection::iterator pos, end = m_value_objects.end();
66 for (pos = m_value_objects.begin(); pos != end; ++pos) {
67 ValueObject *valobj = (*pos).get();
68 if (valobj && valobj->GetName() == name_const_str) {
69 val_obj_sp = *pos;
70 break;
71 }
72 }
73 return val_obj_sp;
74}
75
76ValueObjectSP ValueObjectList::FindValueObjectByUID(lldb::user_id_t uid) {
77 ValueObjectSP valobj_sp;
78 collection::iterator pos, end = m_value_objects.end();
79
80 for (pos = m_value_objects.begin(); pos != end; ++pos) {
81 // Watch out for NULL objects in our list as the list might get resized to
82 // a specific size and lazily filled in
83 ValueObject *valobj = (*pos).get();
84 if (valobj && valobj->GetID() == uid) {
85 valobj_sp = *pos;
86 break;
87 }
88 }
89 return valobj_sp;
90}
91
92ValueObjectSP
93ValueObjectList::FindValueObjectByPointer(ValueObject *find_valobj) {
94 ValueObjectSP valobj_sp;
95 collection::iterator pos, end = m_value_objects.end();
96
97 for (pos = m_value_objects.begin(); pos != end; ++pos) {
98 ValueObject *valobj = (*pos).get();
99 if (valobj && valobj == find_valobj) {
100 valobj_sp = *pos;
101 break;
102 }
103 }
104 return valobj_sp;
105}
106
107void ValueObjectList::Swap(ValueObjectList &value_object_list) {
108 m_value_objects.swap(x&: value_object_list.m_value_objects);
109}
110

source code of lldb/source/Core/ValueObjectList.cpp