blob: 508bfb4f17d06b310dafd990243482db474fe800 [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- SBFileSpecList.cpp --------------------------------------*- C++ -*-===//
Jim Ingham969795f2011-09-21 01:17:13 +00002//
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"
Jim Ingham969795f2011-09-21 01:17:13 +000016#include "lldb/Host/FileSpec.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000017#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000018#include "lldb/Utility/Stream.h"
Jim Ingham969795f2011-09-21 01:17:13 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023SBFileSpecList::SBFileSpecList() : m_opaque_ap(new FileSpecList()) {}
Jim Ingham969795f2011-09-21 01:17:13 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_ap() {
26 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 if (rhs.m_opaque_ap.get())
29 m_opaque_ap.reset(new FileSpecList(*(rhs.get())));
30
31 if (log) {
32 log->Printf("SBFileSpecList::SBFileSpecList (const SBFileSpecList "
33 "rhs.ap=%p) => SBFileSpecList(%p)",
34 static_cast<void *>(rhs.m_opaque_ap.get()),
35 static_cast<void *>(m_opaque_ap.get()));
36 }
Jim Ingham969795f2011-09-21 01:17:13 +000037}
38
Kate Stoneb9c1b512016-09-06 20:57:50 +000039SBFileSpecList::~SBFileSpecList() {}
Jim Ingham969795f2011-09-21 01:17:13 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
42 if (this != &rhs) {
43 m_opaque_ap.reset(new lldb_private::FileSpecList(*(rhs.get())));
44 }
45 return *this;
46}
Jim Ingham969795f2011-09-21 01:17:13 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048uint32_t SBFileSpecList::GetSize() const { return m_opaque_ap->GetSize(); }
49
50void SBFileSpecList::Append(const SBFileSpec &sb_file) {
51 m_opaque_ap->Append(sb_file.ref());
52}
53
54bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
55 return m_opaque_ap->AppendIfUnique(sb_file.ref());
56}
57
58void SBFileSpecList::Clear() { m_opaque_ap->Clear(); }
59
60uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
61 bool full) {
62 return m_opaque_ap->FindFileIndex(idx, sb_file.ref(), full);
63}
64
65const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
66 SBFileSpec new_spec;
67 new_spec.SetFileSpec(m_opaque_ap->GetFileSpecAtIndex(idx));
68 return new_spec;
69}
70
71const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
72 return m_opaque_ap.get();
73}
74
75const lldb_private::FileSpecList *SBFileSpecList::get() const {
76 return m_opaque_ap.get();
77}
78
79const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
80 return *m_opaque_ap.get();
81}
82
83const lldb_private::FileSpecList &SBFileSpecList::ref() const {
84 return *m_opaque_ap.get();
85}
86
87bool SBFileSpecList::GetDescription(SBStream &description) const {
88 Stream &strm = description.ref();
89
90 if (m_opaque_ap.get()) {
91 uint32_t num_files = m_opaque_ap->GetSize();
92 strm.Printf("%d files: ", num_files);
93 for (uint32_t i = 0; i < num_files; i++) {
94 char path[PATH_MAX];
95 if (m_opaque_ap->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
96 strm.Printf("\n %s", path);
Jim Ingham969795f2011-09-21 01:17:13 +000097 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 } else
99 strm.PutCString("No value");
Jim Ingham969795f2011-09-21 01:17:13 +0000100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 return true;
Jim Ingham969795f2011-09-21 01:17:13 +0000102}