1 //===-- SBFileSpecList.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBFileSpecList.h"
11 #include "lldb/API/SBFileSpec.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Host/PosixApi.h"
14 #include "lldb/Utility/FileSpec.h"
15 #include "lldb/Utility/FileSpecList.h"
16 #include "lldb/Utility/Instrumentation.h"
17 #include "lldb/Utility/Stream.h"
22 using namespace lldb_private
;
24 SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {
25 LLDB_INSTRUMENT_VA(this);
28 SBFileSpecList::SBFileSpecList(const SBFileSpecList
&rhs
) {
29 LLDB_INSTRUMENT_VA(this, rhs
);
31 m_opaque_up
= clone(rhs
.m_opaque_up
);
34 SBFileSpecList::~SBFileSpecList() = default;
36 const SBFileSpecList
&SBFileSpecList::operator=(const SBFileSpecList
&rhs
) {
37 LLDB_INSTRUMENT_VA(this, rhs
);
40 m_opaque_up
= clone(rhs
.m_opaque_up
);
44 uint32_t SBFileSpecList::GetSize() const {
45 LLDB_INSTRUMENT_VA(this);
47 return m_opaque_up
->GetSize();
50 void SBFileSpecList::Append(const SBFileSpec
&sb_file
) {
51 LLDB_INSTRUMENT_VA(this, sb_file
);
53 m_opaque_up
->Append(sb_file
.ref());
56 bool SBFileSpecList::AppendIfUnique(const SBFileSpec
&sb_file
) {
57 LLDB_INSTRUMENT_VA(this, sb_file
);
59 return m_opaque_up
->AppendIfUnique(sb_file
.ref());
62 void SBFileSpecList::Clear() {
63 LLDB_INSTRUMENT_VA(this);
68 uint32_t SBFileSpecList::FindFileIndex(uint32_t idx
, const SBFileSpec
&sb_file
,
70 LLDB_INSTRUMENT_VA(this, idx
, sb_file
, full
);
72 return m_opaque_up
->FindFileIndex(idx
, sb_file
.ref(), full
);
75 const SBFileSpec
SBFileSpecList::GetFileSpecAtIndex(uint32_t idx
) const {
76 LLDB_INSTRUMENT_VA(this, idx
);
79 new_spec
.SetFileSpec(m_opaque_up
->GetFileSpecAtIndex(idx
));
83 const lldb_private::FileSpecList
*SBFileSpecList::operator->() const {
84 return m_opaque_up
.get();
87 const lldb_private::FileSpecList
*SBFileSpecList::get() const {
88 return m_opaque_up
.get();
91 const lldb_private::FileSpecList
&SBFileSpecList::operator*() const {
95 const lldb_private::FileSpecList
&SBFileSpecList::ref() const {
99 bool SBFileSpecList::GetDescription(SBStream
&description
) const {
100 LLDB_INSTRUMENT_VA(this, description
);
102 Stream
&strm
= description
.ref();
105 uint32_t num_files
= m_opaque_up
->GetSize();
106 strm
.Printf("%d files: ", num_files
);
107 for (uint32_t i
= 0; i
< num_files
; i
++) {
109 if (m_opaque_up
->GetFileSpecAtIndex(i
).GetPath(path
, sizeof(path
)))
110 strm
.Printf("\n %s", path
);
113 strm
.PutCString("No value");