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