1 //===-- ValueObjectList.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 #include "lldb/Core/ValueObjectList.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Core/ValueObjectChild.h"
17 #include "lldb/Core/ValueObjectRegister.h"
18 #include "lldb/Core/ValueObjectVariable.h"
19 #include "lldb/Target/ExecutionContext.h"
20 #include "lldb/Target/Process.h"
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 
25 ValueObjectList::ValueObjectList () :
26     m_value_objects()
27 {
28 }
29 
30 ValueObjectList::ValueObjectList (const ValueObjectList &rhs) :
31     m_value_objects(rhs.m_value_objects)
32 {
33 }
34 
35 
36 ValueObjectList::~ValueObjectList ()
37 {
38 }
39 
40 const ValueObjectList &
41 ValueObjectList::operator = (const ValueObjectList &rhs)
42 {
43     if (this != &rhs)
44         m_value_objects = rhs.m_value_objects;
45     return *this;
46 }
47 
48 void
49 ValueObjectList::Append (const ValueObjectSP &val_obj_sp)
50 {
51     m_value_objects.push_back(val_obj_sp);
52 }
53 
54 void
55 ValueObjectList::Append (const ValueObjectList &valobj_list)
56 {
57     std::copy(valobj_list.m_value_objects.begin(),  // source begin
58               valobj_list.m_value_objects.end(),    // source end
59               back_inserter(m_value_objects));      // destination
60 
61 }
62 
63 
64 uint32_t
65 ValueObjectList::GetSize() const
66 {
67     return m_value_objects.size();
68 }
69 
70 void
71 ValueObjectList::Resize (uint32_t size)
72 {
73     m_value_objects.resize (size);
74 }
75 
76 lldb::ValueObjectSP
77 ValueObjectList::GetValueObjectAtIndex (uint32_t idx)
78 {
79     lldb::ValueObjectSP valobj_sp;
80     if (idx < m_value_objects.size())
81         valobj_sp = m_value_objects[idx];
82     return valobj_sp;
83 }
84 
85 void
86 ValueObjectList::SetValueObjectAtIndex (uint32_t idx, const ValueObjectSP &valobj_sp)
87 {
88     if (idx >= m_value_objects.size())
89         m_value_objects.resize (idx + 1);
90     m_value_objects[idx] = valobj_sp;
91 }
92 
93 ValueObjectSP
94 ValueObjectList::FindValueObjectByValueName (const char *name)
95 {
96     ConstString name_const_str(name);
97     ValueObjectSP val_obj_sp;
98     collection::iterator pos, end = m_value_objects.end();
99     for (pos = m_value_objects.begin(); pos != end; ++pos)
100     {
101         ValueObject *valobj = (*pos).get();
102         if (valobj && valobj->GetName() == name_const_str)
103         {
104             val_obj_sp = *pos;
105             break;
106         }
107     }
108     return val_obj_sp;
109 }
110 
111 ValueObjectSP
112 ValueObjectList::FindValueObjectByUID (lldb::user_id_t uid)
113 {
114     ValueObjectSP valobj_sp;
115     collection::iterator pos, end = m_value_objects.end();
116 
117     for (pos = m_value_objects.begin(); pos != end; ++pos)
118     {
119         // Watch out for NULL objects in our list as the list
120         // might get resized to a specific size and lazily filled in
121         ValueObject *valobj = (*pos).get();
122         if (valobj && valobj->GetID() == uid)
123         {
124             valobj_sp = *pos;
125             break;
126         }
127     }
128     return valobj_sp;
129 }
130 
131 
132 ValueObjectSP
133 ValueObjectList::FindValueObjectByPointer (ValueObject *find_valobj)
134 {
135     ValueObjectSP valobj_sp;
136     collection::iterator pos, end = m_value_objects.end();
137 
138     for (pos = m_value_objects.begin(); pos != end; ++pos)
139     {
140         ValueObject *valobj = (*pos).get();
141         if (valobj && valobj == find_valobj)
142         {
143             valobj_sp = *pos;
144             break;
145         }
146     }
147     return valobj_sp;
148 }
149 
150 void
151 ValueObjectList::Swap (ValueObjectList &value_object_list)
152 {
153     m_value_objects.swap (value_object_list.m_value_objects);
154 }
155