[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / source / ValueObject / ValueObjectList.cpp
bloba79a040bdf7fd1f3d483192b7d8f6d6ede05f13b
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 //===----------------------------------------------------------------------===//
9 #include "lldb/ValueObject/ValueObjectList.h"
11 #include "lldb/Utility/ConstString.h"
12 #include "lldb/ValueObject/ValueObject.h"
14 #include <utility>
16 using namespace lldb;
17 using namespace lldb_private;
19 const ValueObjectList &ValueObjectList::operator=(const ValueObjectList &rhs) {
20 if (this != &rhs)
21 m_value_objects = rhs.m_value_objects;
22 return *this;
25 void ValueObjectList::Append(const ValueObjectSP &val_obj_sp) {
26 m_value_objects.push_back(val_obj_sp);
29 void ValueObjectList::Append(const ValueObjectList &valobj_list) {
30 std::copy(valobj_list.m_value_objects.begin(), // source begin
31 valobj_list.m_value_objects.end(), // source end
32 back_inserter(m_value_objects)); // destination
35 size_t ValueObjectList::GetSize() const { return m_value_objects.size(); }
37 void ValueObjectList::Resize(size_t size) { m_value_objects.resize(size); }
39 lldb::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;
46 lldb::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(m_value_objects.begin() + idx);
52 return valobj_sp;
55 void ValueObjectList::SetValueObjectAtIndex(size_t idx,
56 const ValueObjectSP &valobj_sp) {
57 if (idx >= m_value_objects.size())
58 m_value_objects.resize(idx + 1);
59 m_value_objects[idx] = valobj_sp;
62 ValueObjectSP 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;
73 return val_obj_sp;
76 ValueObjectSP ValueObjectList::FindValueObjectByUID(lldb::user_id_t uid) {
77 ValueObjectSP valobj_sp;
78 collection::iterator pos, end = m_value_objects.end();
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;
89 return valobj_sp;
92 ValueObjectSP
93 ValueObjectList::FindValueObjectByPointer(ValueObject *find_valobj) {
94 ValueObjectSP valobj_sp;
95 collection::iterator pos, end = m_value_objects.end();
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;
104 return valobj_sp;
107 void ValueObjectList::Swap(ValueObjectList &value_object_list) {
108 m_value_objects.swap(value_object_list.m_value_objects);