llvm-project
109 строк · 3.3 Кб
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) {
20if (this != &rhs)
21m_value_objects = rhs.m_value_objects;
22return *this;
23}
24
25void ValueObjectList::Append(const ValueObjectSP &val_obj_sp) {
26m_value_objects.push_back(val_obj_sp);
27}
28
29void ValueObjectList::Append(const ValueObjectList &valobj_list) {
30std::copy(valobj_list.m_value_objects.begin(), // source begin
31valobj_list.m_value_objects.end(), // source end
32back_inserter(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(size); }
38
39lldb::ValueObjectSP ValueObjectList::GetValueObjectAtIndex(size_t idx) {
40lldb::ValueObjectSP valobj_sp;
41if (idx < m_value_objects.size())
42valobj_sp = m_value_objects[idx];
43return valobj_sp;
44}
45
46lldb::ValueObjectSP ValueObjectList::RemoveValueObjectAtIndex(size_t idx) {
47lldb::ValueObjectSP valobj_sp;
48if (idx < m_value_objects.size()) {
49valobj_sp = m_value_objects[idx];
50m_value_objects.erase(m_value_objects.begin() + idx);
51}
52return valobj_sp;
53}
54
55void ValueObjectList::SetValueObjectAtIndex(size_t idx,
56const ValueObjectSP &valobj_sp) {
57if (idx >= m_value_objects.size())
58m_value_objects.resize(idx + 1);
59m_value_objects[idx] = valobj_sp;
60}
61
62ValueObjectSP ValueObjectList::FindValueObjectByValueName(const char *name) {
63ConstString name_const_str(name);
64ValueObjectSP val_obj_sp;
65collection::iterator pos, end = m_value_objects.end();
66for (pos = m_value_objects.begin(); pos != end; ++pos) {
67ValueObject *valobj = (*pos).get();
68if (valobj && valobj->GetName() == name_const_str) {
69val_obj_sp = *pos;
70break;
71}
72}
73return val_obj_sp;
74}
75
76ValueObjectSP ValueObjectList::FindValueObjectByUID(lldb::user_id_t uid) {
77ValueObjectSP valobj_sp;
78collection::iterator pos, end = m_value_objects.end();
79
80for (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
83ValueObject *valobj = (*pos).get();
84if (valobj && valobj->GetID() == uid) {
85valobj_sp = *pos;
86break;
87}
88}
89return valobj_sp;
90}
91
92ValueObjectSP
93ValueObjectList::FindValueObjectByPointer(ValueObject *find_valobj) {
94ValueObjectSP valobj_sp;
95collection::iterator pos, end = m_value_objects.end();
96
97for (pos = m_value_objects.begin(); pos != end; ++pos) {
98ValueObject *valobj = (*pos).get();
99if (valobj && valobj == find_valobj) {
100valobj_sp = *pos;
101break;
102}
103}
104return valobj_sp;
105}
106
107void ValueObjectList::Swap(ValueObjectList &value_object_list) {
108m_value_objects.swap(value_object_list.m_value_objects);
109}
110