blob: 9e157ea201d775123551f914e767384296b9b127 [file] [log] [blame]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001//===-- SBFileSpecListList.cpp ------------------------------------------*- C++
2//-*-===//
Jim Ingham969795f2011-09-21 01:17:13 +00003//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#include <limits.h>
12
13#include "lldb/API/SBFileSpec.h"
14#include "lldb/API/SBFileSpecList.h"
15#include "lldb/API/SBStream.h"
16#include "lldb/Core/FileSpecList.h"
17#include "lldb/Core/Log.h"
Greg Claytonda7bc7d2011-11-13 06:57:31 +000018#include "lldb/Core/Stream.h"
Jim Ingham969795f2011-09-21 01:17:13 +000019#include "lldb/Host/FileSpec.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024SBFileSpecList::SBFileSpecList() : m_opaque_ap(new FileSpecList()) {}
Jim Ingham969795f2011-09-21 01:17:13 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_ap() {
27 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 if (rhs.m_opaque_ap.get())
30 m_opaque_ap.reset(new FileSpecList(*(rhs.get())));
31
32 if (log) {
33 log->Printf("SBFileSpecList::SBFileSpecList (const SBFileSpecList "
34 "rhs.ap=%p) => SBFileSpecList(%p)",
35 static_cast<void *>(rhs.m_opaque_ap.get()),
36 static_cast<void *>(m_opaque_ap.get()));
37 }
Jim Ingham969795f2011-09-21 01:17:13 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040SBFileSpecList::~SBFileSpecList() {}
Jim Ingham969795f2011-09-21 01:17:13 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
43 if (this != &rhs) {
44 m_opaque_ap.reset(new lldb_private::FileSpecList(*(rhs.get())));
45 }
46 return *this;
47}
Jim Ingham969795f2011-09-21 01:17:13 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049uint32_t SBFileSpecList::GetSize() const { return m_opaque_ap->GetSize(); }
50
51void SBFileSpecList::Append(const SBFileSpec &sb_file) {
52 m_opaque_ap->Append(sb_file.ref());
53}
54
55bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
56 return m_opaque_ap->AppendIfUnique(sb_file.ref());
57}
58
59void SBFileSpecList::Clear() { m_opaque_ap->Clear(); }
60
61uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
62 bool full) {
63 return m_opaque_ap->FindFileIndex(idx, sb_file.ref(), full);
64}
65
66const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
67 SBFileSpec new_spec;
68 new_spec.SetFileSpec(m_opaque_ap->GetFileSpecAtIndex(idx));
69 return new_spec;
70}
71
72const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
73 return m_opaque_ap.get();
74}
75
76const lldb_private::FileSpecList *SBFileSpecList::get() const {
77 return m_opaque_ap.get();
78}
79
80const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
81 return *m_opaque_ap.get();
82}
83
84const lldb_private::FileSpecList &SBFileSpecList::ref() const {
85 return *m_opaque_ap.get();
86}
87
88bool SBFileSpecList::GetDescription(SBStream &description) const {
89 Stream &strm = description.ref();
90
91 if (m_opaque_ap.get()) {
92 uint32_t num_files = m_opaque_ap->GetSize();
93 strm.Printf("%d files: ", num_files);
94 for (uint32_t i = 0; i < num_files; i++) {
95 char path[PATH_MAX];
96 if (m_opaque_ap->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
97 strm.Printf("\n %s", path);
Jim Ingham969795f2011-09-21 01:17:13 +000098 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 } else
100 strm.PutCString("No value");
Jim Ingham969795f2011-09-21 01:17:13 +0000101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 return true;
Jim Ingham969795f2011-09-21 01:17:13 +0000103}