Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1 | //===-- SBFileSpecListList.cpp ------------------------------------------*- C++ -*-===// |
| 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" |
| 16 | #include "lldb/Core/Log.h" |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Stream.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 18 | #include "lldb/Host/FileSpec.h" |
| 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | |
| 24 | |
| 25 | SBFileSpecList::SBFileSpecList () : |
| 26 | m_opaque_ap(new FileSpecList()) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | SBFileSpecList::SBFileSpecList (const SBFileSpecList &rhs) : |
| 31 | m_opaque_ap() |
| 32 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 33 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 34 | |
| 35 | if (rhs.m_opaque_ap.get()) |
| 36 | m_opaque_ap.reset (new FileSpecList (*(rhs.get()))); |
| 37 | |
| 38 | if (log) |
| 39 | { |
Greg Clayton | c1ef10f | 2011-09-21 06:45:51 +0000 | [diff] [blame] | 40 | log->Printf ("SBFileSpecList::SBFileSpecList (const SBFileSpecList rhs.ap=%p) => SBFileSpecList(%p)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame^] | 41 | static_cast<void*>(rhs.m_opaque_ap.get()), |
| 42 | static_cast<void*>(m_opaque_ap.get())); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | SBFileSpecList::~SBFileSpecList () |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | const SBFileSpecList & |
| 51 | SBFileSpecList::operator = (const SBFileSpecList &rhs) |
| 52 | { |
| 53 | if (this != &rhs) |
| 54 | { |
| 55 | m_opaque_ap.reset (new lldb_private::FileSpecList(*(rhs.get()))); |
| 56 | } |
| 57 | return *this; |
| 58 | } |
| 59 | |
| 60 | uint32_t |
| 61 | SBFileSpecList::GetSize () const |
| 62 | { |
| 63 | return m_opaque_ap->GetSize(); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | SBFileSpecList::Append (const SBFileSpec &sb_file) |
| 68 | { |
| 69 | m_opaque_ap->Append (sb_file.ref()); |
| 70 | } |
| 71 | |
| 72 | bool |
| 73 | SBFileSpecList::AppendIfUnique (const SBFileSpec &sb_file) |
| 74 | { |
| 75 | return m_opaque_ap->AppendIfUnique (sb_file.ref()); |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | SBFileSpecList::Clear() |
| 80 | { |
| 81 | m_opaque_ap->Clear(); |
| 82 | } |
| 83 | |
| 84 | uint32_t |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 85 | SBFileSpecList::FindFileIndex (uint32_t idx, const SBFileSpec &sb_file, bool full) |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 86 | { |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 87 | return m_opaque_ap->FindFileIndex (idx, sb_file.ref(), full); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | const SBFileSpec |
| 91 | SBFileSpecList::GetFileSpecAtIndex (uint32_t idx) const |
| 92 | { |
| 93 | SBFileSpec new_spec; |
| 94 | new_spec.SetFileSpec(m_opaque_ap->GetFileSpecAtIndex(idx)); |
| 95 | return new_spec; |
| 96 | } |
| 97 | |
| 98 | const lldb_private::FileSpecList * |
| 99 | SBFileSpecList::operator->() const |
| 100 | { |
| 101 | return m_opaque_ap.get(); |
| 102 | } |
| 103 | |
| 104 | const lldb_private::FileSpecList * |
| 105 | SBFileSpecList::get() const |
| 106 | { |
| 107 | return m_opaque_ap.get(); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | const lldb_private::FileSpecList & |
| 112 | SBFileSpecList::operator*() const |
| 113 | { |
| 114 | return *m_opaque_ap.get(); |
| 115 | } |
| 116 | |
| 117 | const lldb_private::FileSpecList & |
| 118 | SBFileSpecList::ref() const |
| 119 | { |
| 120 | return *m_opaque_ap.get(); |
| 121 | } |
| 122 | |
| 123 | bool |
| 124 | SBFileSpecList::GetDescription (SBStream &description) const |
| 125 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 126 | Stream &strm = description.ref(); |
| 127 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 128 | if (m_opaque_ap.get()) |
| 129 | { |
| 130 | uint32_t num_files = m_opaque_ap->GetSize(); |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 131 | strm.Printf ("%d files: ", num_files); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 132 | for (uint32_t i = 0; i < num_files; i++) |
| 133 | { |
| 134 | char path[PATH_MAX]; |
| 135 | if (m_opaque_ap->GetFileSpecAtIndex(i).GetPath(path, sizeof(path))) |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 136 | strm.Printf ("\n %s", path); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | else |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 140 | strm.PutCString ("No value"); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 141 | |
| 142 | return true; |
| 143 | } |