1*7aa51b79SEd Maste //===-- SBThreadCollection.cpp ----------------------------------*- C++ -*-===//
2*7aa51b79SEd Maste //
3*7aa51b79SEd Maste //                     The LLVM Compiler Infrastructure
4*7aa51b79SEd Maste //
5*7aa51b79SEd Maste // This file is distributed under the University of Illinois Open Source
6*7aa51b79SEd Maste // License. See LICENSE.TXT for details.
7*7aa51b79SEd Maste //
8*7aa51b79SEd Maste //===----------------------------------------------------------------------===//
9*7aa51b79SEd Maste 
10*7aa51b79SEd Maste #include "lldb/API/SBThreadCollection.h"
11*7aa51b79SEd Maste #include "lldb/API/SBThread.h"
12*7aa51b79SEd Maste #include "lldb/Target/ThreadList.h"
13*7aa51b79SEd Maste 
14*7aa51b79SEd Maste using namespace lldb;
15*7aa51b79SEd Maste using namespace lldb_private;
16*7aa51b79SEd Maste 
17*7aa51b79SEd Maste 
18*7aa51b79SEd Maste SBThreadCollection::SBThreadCollection () :
19*7aa51b79SEd Maste     m_opaque_sp()
20*7aa51b79SEd Maste {
21*7aa51b79SEd Maste }
22*7aa51b79SEd Maste 
23*7aa51b79SEd Maste SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs) :
24*7aa51b79SEd Maste     m_opaque_sp (rhs.m_opaque_sp)
25*7aa51b79SEd Maste {
26*7aa51b79SEd Maste }
27*7aa51b79SEd Maste 
28*7aa51b79SEd Maste const SBThreadCollection &
29*7aa51b79SEd Maste SBThreadCollection::operator = (const SBThreadCollection &rhs)
30*7aa51b79SEd Maste {
31*7aa51b79SEd Maste     if (this != &rhs)
32*7aa51b79SEd Maste         m_opaque_sp = rhs.m_opaque_sp;
33*7aa51b79SEd Maste     return *this;
34*7aa51b79SEd Maste }
35*7aa51b79SEd Maste 
36*7aa51b79SEd Maste SBThreadCollection::SBThreadCollection (const ThreadCollectionSP &threads) :
37*7aa51b79SEd Maste     m_opaque_sp(threads)
38*7aa51b79SEd Maste {
39*7aa51b79SEd Maste }
40*7aa51b79SEd Maste 
41*7aa51b79SEd Maste SBThreadCollection::~SBThreadCollection ()
42*7aa51b79SEd Maste {
43*7aa51b79SEd Maste }
44*7aa51b79SEd Maste 
45*7aa51b79SEd Maste void
46*7aa51b79SEd Maste SBThreadCollection::SetOpaque (const lldb::ThreadCollectionSP &threads)
47*7aa51b79SEd Maste {
48*7aa51b79SEd Maste     m_opaque_sp = threads;
49*7aa51b79SEd Maste }
50*7aa51b79SEd Maste 
51*7aa51b79SEd Maste lldb_private::ThreadCollection *
52*7aa51b79SEd Maste SBThreadCollection::get() const
53*7aa51b79SEd Maste {
54*7aa51b79SEd Maste     return m_opaque_sp.get();
55*7aa51b79SEd Maste }
56*7aa51b79SEd Maste 
57*7aa51b79SEd Maste lldb_private::ThreadCollection *
58*7aa51b79SEd Maste SBThreadCollection::operator->() const
59*7aa51b79SEd Maste {
60*7aa51b79SEd Maste     return m_opaque_sp.operator->();
61*7aa51b79SEd Maste }
62*7aa51b79SEd Maste 
63*7aa51b79SEd Maste lldb::ThreadCollectionSP &
64*7aa51b79SEd Maste SBThreadCollection::operator*()
65*7aa51b79SEd Maste {
66*7aa51b79SEd Maste     return m_opaque_sp;
67*7aa51b79SEd Maste }
68*7aa51b79SEd Maste 
69*7aa51b79SEd Maste const lldb::ThreadCollectionSP &
70*7aa51b79SEd Maste SBThreadCollection::operator*() const
71*7aa51b79SEd Maste {
72*7aa51b79SEd Maste     return m_opaque_sp;
73*7aa51b79SEd Maste }
74*7aa51b79SEd Maste 
75*7aa51b79SEd Maste 
76*7aa51b79SEd Maste bool
77*7aa51b79SEd Maste SBThreadCollection::IsValid () const
78*7aa51b79SEd Maste {
79*7aa51b79SEd Maste     return m_opaque_sp.get() != NULL;
80*7aa51b79SEd Maste }
81*7aa51b79SEd Maste 
82*7aa51b79SEd Maste size_t
83*7aa51b79SEd Maste SBThreadCollection::GetSize ()
84*7aa51b79SEd Maste {
85*7aa51b79SEd Maste     if (m_opaque_sp)
86*7aa51b79SEd Maste         return m_opaque_sp->GetSize();
87*7aa51b79SEd Maste     return 0;
88*7aa51b79SEd Maste }
89*7aa51b79SEd Maste 
90*7aa51b79SEd Maste SBThread
91*7aa51b79SEd Maste SBThreadCollection::GetThreadAtIndex(size_t idx)
92*7aa51b79SEd Maste {
93*7aa51b79SEd Maste     SBThread thread;
94*7aa51b79SEd Maste     if (m_opaque_sp && idx < m_opaque_sp->GetSize())
95*7aa51b79SEd Maste         thread = m_opaque_sp->GetThreadAtIndex(idx);
96*7aa51b79SEd Maste     return thread;
97*7aa51b79SEd Maste }
98