1 //===-- SBFileSpecListList.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 <limits.h>
11 
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBFileSpecList.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/Core/FileSpecList.h"
16 #include "lldb/Core/Log.h"
17 #include "lldb/Host/FileSpec.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 
23 
24 SBFileSpecList::SBFileSpecList () :
25     m_opaque_ap(new FileSpecList())
26 {
27 }
28 
29 SBFileSpecList::SBFileSpecList (const SBFileSpecList &rhs) :
30     m_opaque_ap()
31 {
32     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
33 
34     if (rhs.m_opaque_ap.get())
35         m_opaque_ap.reset (new FileSpecList (*(rhs.get())));
36 
37     if (log)
38     {
39         log->Printf ("SBFileSpecList::SBFileSpecList (const SBFileSpecList rhs.ap=%p) => SBFileSpecList(%p)",
40                      rhs.m_opaque_ap.get(), m_opaque_ap.get());
41     }
42 }
43 
44 SBFileSpecList::~SBFileSpecList ()
45 {
46 }
47 
48 const SBFileSpecList &
49 SBFileSpecList::operator = (const SBFileSpecList &rhs)
50 {
51     if (this != &rhs)
52     {
53         m_opaque_ap.reset (new lldb_private::FileSpecList(*(rhs.get())));
54     }
55     return *this;
56 }
57 
58 uint32_t
59 SBFileSpecList::GetSize () const
60 {
61     return m_opaque_ap->GetSize();
62 }
63 
64 void
65 SBFileSpecList::Append (const SBFileSpec &sb_file)
66 {
67     m_opaque_ap->Append (sb_file.ref());
68 }
69 
70 bool
71 SBFileSpecList::AppendIfUnique (const SBFileSpec &sb_file)
72 {
73     return m_opaque_ap->AppendIfUnique (sb_file.ref());
74 }
75 
76 void
77 SBFileSpecList::Clear()
78 {
79     m_opaque_ap->Clear();
80 }
81 
82 uint32_t
83 SBFileSpecList::FindFileIndex (uint32_t idx, const SBFileSpec &sb_file, bool full)
84 {
85     return m_opaque_ap->FindFileIndex (idx, sb_file.ref(), full);
86 }
87 
88 const SBFileSpec
89 SBFileSpecList::GetFileSpecAtIndex (uint32_t idx) const
90 {
91     SBFileSpec new_spec;
92     new_spec.SetFileSpec(m_opaque_ap->GetFileSpecAtIndex(idx));
93     return new_spec;
94 }
95 
96 const lldb_private::FileSpecList *
97 SBFileSpecList::operator->() const
98 {
99     return m_opaque_ap.get();
100 }
101 
102 const lldb_private::FileSpecList *
103 SBFileSpecList::get() const
104 {
105     return m_opaque_ap.get();
106 }
107 
108 
109 const lldb_private::FileSpecList &
110 SBFileSpecList::operator*() const
111 {
112     return *m_opaque_ap.get();
113 }
114 
115 const lldb_private::FileSpecList &
116 SBFileSpecList::ref() const
117 {
118     return *m_opaque_ap.get();
119 }
120 
121 bool
122 SBFileSpecList::GetDescription (SBStream &description) const
123 {
124     if (m_opaque_ap.get())
125     {
126         uint32_t num_files = m_opaque_ap->GetSize();
127         description.Printf ("%d files: ", num_files);
128         for (uint32_t i = 0; i < num_files; i++)
129         {
130             char path[PATH_MAX];
131             if (m_opaque_ap->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
132                 description.Printf ("\n    %s", path);
133         }
134     }
135     else
136         description.Printf ("No value");
137 
138     return true;
139 }
140