1//===-- SBFileSpecList.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//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBFileSpecList.h"
10#include "Utils.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"
18
19#include <climits>
20
21using namespace lldb;
22using namespace lldb_private;
23
24SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {
25 LLDB_INSTRUMENT_VA(this);
26}
27
28SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) {
29 LLDB_INSTRUMENT_VA(this, rhs);
30
31 m_opaque_up = clone(src: rhs.m_opaque_up);
32}
33
34SBFileSpecList::~SBFileSpecList() = default;
35
36const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
37 LLDB_INSTRUMENT_VA(this, rhs);
38
39 if (this != &rhs)
40 m_opaque_up = clone(src: rhs.m_opaque_up);
41 return *this;
42}
43
44uint32_t SBFileSpecList::GetSize() const {
45 LLDB_INSTRUMENT_VA(this);
46
47 return m_opaque_up->GetSize();
48}
49
50void SBFileSpecList::Append(const SBFileSpec &sb_file) {
51 LLDB_INSTRUMENT_VA(this, sb_file);
52
53 m_opaque_up->Append(file: sb_file.ref());
54}
55
56bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
57 LLDB_INSTRUMENT_VA(this, sb_file);
58
59 return m_opaque_up->AppendIfUnique(file: sb_file.ref());
60}
61
62void SBFileSpecList::Clear() {
63 LLDB_INSTRUMENT_VA(this);
64
65 m_opaque_up->Clear();
66}
67
68uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
69 bool full) {
70 LLDB_INSTRUMENT_VA(this, idx, sb_file, full);
71
72 return m_opaque_up->FindFileIndex(idx, file: sb_file.ref(), full);
73}
74
75const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
76 LLDB_INSTRUMENT_VA(this, idx);
77
78 SBFileSpec new_spec;
79 new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx));
80 return new_spec;
81}
82
83const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
84 return m_opaque_up.get();
85}
86
87const lldb_private::FileSpecList *SBFileSpecList::get() const {
88 return m_opaque_up.get();
89}
90
91const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
92 return *m_opaque_up;
93}
94
95const lldb_private::FileSpecList &SBFileSpecList::ref() const {
96 return *m_opaque_up;
97}
98
99bool SBFileSpecList::GetDescription(SBStream &description) const {
100 LLDB_INSTRUMENT_VA(this, description);
101
102 Stream &strm = description.ref();
103
104 if (m_opaque_up) {
105 uint32_t num_files = m_opaque_up->GetSize();
106 strm.Printf(format: "%d files: ", num_files);
107 for (uint32_t i = 0; i < num_files; i++) {
108 char path[PATH_MAX];
109 if (m_opaque_up->GetFileSpecAtIndex(idx: i).GetPath(path, max_path_length: sizeof(path)))
110 strm.Printf(format: "\n %s", path);
111 }
112 } else
113 strm.PutCString(cstr: "No value");
114
115 return true;
116}
117

source code of lldb/source/API/SBFileSpecList.cpp