Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- SBFileSpecList.cpp --------------------------------------*- C++ -*-===// |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 2 | // |
| 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 Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 16 | #include "lldb/Host/FileSpec.h" |
Zachary Turner | 8d48cd6 | 2017-03-22 17:33:23 +0000 | [diff] [blame^] | 17 | #include "lldb/Host/PosixApi.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/Stream.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | SBFileSpecList::SBFileSpecList() : m_opaque_ap(new FileSpecList()) {} |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 25 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_ap() { |
| 27 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | 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 Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | SBFileSpecList::~SBFileSpecList() {} |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | const 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 Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | uint32_t SBFileSpecList::GetSize() const { return m_opaque_ap->GetSize(); } |
| 50 | |
| 51 | void SBFileSpecList::Append(const SBFileSpec &sb_file) { |
| 52 | m_opaque_ap->Append(sb_file.ref()); |
| 53 | } |
| 54 | |
| 55 | bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) { |
| 56 | return m_opaque_ap->AppendIfUnique(sb_file.ref()); |
| 57 | } |
| 58 | |
| 59 | void SBFileSpecList::Clear() { m_opaque_ap->Clear(); } |
| 60 | |
| 61 | uint32_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 | |
| 66 | const 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 | |
| 72 | const lldb_private::FileSpecList *SBFileSpecList::operator->() const { |
| 73 | return m_opaque_ap.get(); |
| 74 | } |
| 75 | |
| 76 | const lldb_private::FileSpecList *SBFileSpecList::get() const { |
| 77 | return m_opaque_ap.get(); |
| 78 | } |
| 79 | |
| 80 | const lldb_private::FileSpecList &SBFileSpecList::operator*() const { |
| 81 | return *m_opaque_ap.get(); |
| 82 | } |
| 83 | |
| 84 | const lldb_private::FileSpecList &SBFileSpecList::ref() const { |
| 85 | return *m_opaque_ap.get(); |
| 86 | } |
| 87 | |
| 88 | bool 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 Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 98 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | } else |
| 100 | strm.PutCString("No value"); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | return true; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 103 | } |