1cfca06d7SDimitry Andric //===-- SBFileSpecList.cpp ------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/API/SBFileSpecList.h"
105f29bb8aSDimitry Andric #include "Utils.h"
115f29bb8aSDimitry Andric #include "lldb/API/SBFileSpec.h"
12f034231aSEd Maste #include "lldb/API/SBStream.h"
1374a628f7SDimitry Andric #include "lldb/Host/PosixApi.h"
1474a628f7SDimitry Andric #include "lldb/Utility/FileSpec.h"
157fa27ce4SDimitry Andric #include "lldb/Utility/FileSpecList.h"
166f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
1774a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
18f034231aSEd Maste
19344a3780SDimitry Andric #include <climits>
205f29bb8aSDimitry Andric
21f034231aSEd Maste using namespace lldb;
22f034231aSEd Maste using namespace lldb_private;
23f034231aSEd Maste
SBFileSpecList()245f29bb8aSDimitry Andric SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {
256f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
26f034231aSEd Maste }
275f29bb8aSDimitry Andric
SBFileSpecList(const SBFileSpecList & rhs)286f8fc217SDimitry Andric SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) {
296f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
305f29bb8aSDimitry Andric
315f29bb8aSDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
32f034231aSEd Maste }
33f034231aSEd Maste
34cfca06d7SDimitry Andric SBFileSpecList::~SBFileSpecList() = default;
35f034231aSEd Maste
operator =(const SBFileSpecList & rhs)3614f1b3e8SDimitry Andric const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
376f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
385f29bb8aSDimitry Andric
395f29bb8aSDimitry Andric if (this != &rhs)
405f29bb8aSDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
416f8fc217SDimitry Andric return *this;
42f034231aSEd Maste }
43f034231aSEd Maste
GetSize() const445f29bb8aSDimitry Andric uint32_t SBFileSpecList::GetSize() const {
456f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
465f29bb8aSDimitry Andric
475f29bb8aSDimitry Andric return m_opaque_up->GetSize();
485f29bb8aSDimitry Andric }
49f034231aSEd Maste
Append(const SBFileSpec & sb_file)5014f1b3e8SDimitry Andric void SBFileSpecList::Append(const SBFileSpec &sb_file) {
516f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_file);
525f29bb8aSDimitry Andric
535f29bb8aSDimitry Andric m_opaque_up->Append(sb_file.ref());
54f034231aSEd Maste }
55f034231aSEd Maste
AppendIfUnique(const SBFileSpec & sb_file)5614f1b3e8SDimitry Andric bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
576f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_file);
585f29bb8aSDimitry Andric
595f29bb8aSDimitry Andric return m_opaque_up->AppendIfUnique(sb_file.ref());
60f034231aSEd Maste }
61f034231aSEd Maste
Clear()625f29bb8aSDimitry Andric void SBFileSpecList::Clear() {
636f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
645f29bb8aSDimitry Andric
655f29bb8aSDimitry Andric m_opaque_up->Clear();
665f29bb8aSDimitry Andric }
67f034231aSEd Maste
FindFileIndex(uint32_t idx,const SBFileSpec & sb_file,bool full)6814f1b3e8SDimitry Andric uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
6914f1b3e8SDimitry Andric bool full) {
706f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, idx, sb_file, full);
715f29bb8aSDimitry Andric
725f29bb8aSDimitry Andric return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full);
73f034231aSEd Maste }
74f034231aSEd Maste
GetFileSpecAtIndex(uint32_t idx) const7514f1b3e8SDimitry Andric const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
766f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, idx);
775f29bb8aSDimitry Andric
78f034231aSEd Maste SBFileSpec new_spec;
795f29bb8aSDimitry Andric new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx));
806f8fc217SDimitry Andric return new_spec;
81f034231aSEd Maste }
82f034231aSEd Maste
operator ->() const8314f1b3e8SDimitry Andric const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
845f29bb8aSDimitry Andric return m_opaque_up.get();
85f034231aSEd Maste }
86f034231aSEd Maste
get() const8714f1b3e8SDimitry Andric const lldb_private::FileSpecList *SBFileSpecList::get() const {
885f29bb8aSDimitry Andric return m_opaque_up.get();
89f034231aSEd Maste }
90f034231aSEd Maste
operator *() const9114f1b3e8SDimitry Andric const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
925f29bb8aSDimitry Andric return *m_opaque_up;
93f034231aSEd Maste }
94f034231aSEd Maste
ref() const9514f1b3e8SDimitry Andric const lldb_private::FileSpecList &SBFileSpecList::ref() const {
965f29bb8aSDimitry Andric return *m_opaque_up;
97f034231aSEd Maste }
98f034231aSEd Maste
GetDescription(SBStream & description) const9914f1b3e8SDimitry Andric bool SBFileSpecList::GetDescription(SBStream &description) const {
1006f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, description);
1015f29bb8aSDimitry Andric
102f034231aSEd Maste Stream &strm = description.ref();
103f034231aSEd Maste
1045f29bb8aSDimitry Andric if (m_opaque_up) {
1055f29bb8aSDimitry Andric uint32_t num_files = m_opaque_up->GetSize();
106f034231aSEd Maste strm.Printf("%d files: ", num_files);
10714f1b3e8SDimitry Andric for (uint32_t i = 0; i < num_files; i++) {
108f034231aSEd Maste char path[PATH_MAX];
1095f29bb8aSDimitry Andric if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
110f034231aSEd Maste strm.Printf("\n %s", path);
111f034231aSEd Maste }
11214f1b3e8SDimitry Andric } else
113f034231aSEd Maste strm.PutCString("No value");
114f034231aSEd Maste
115f034231aSEd Maste return true;
116f034231aSEd Maste }
117