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" 17 #include "lldb/Core/Stream.h" 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 { 33 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 34 35 if (rhs.m_opaque_ap.get()) 36 m_opaque_ap.reset (new FileSpecList (*(rhs.get()))); 37 38 if (log) 39 { 40 log->Printf ("SBFileSpecList::SBFileSpecList (const SBFileSpecList rhs.ap=%p) => SBFileSpecList(%p)", 41 static_cast<void*>(rhs.m_opaque_ap.get()), 42 static_cast<void*>(m_opaque_ap.get())); 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 85 SBFileSpecList::FindFileIndex (uint32_t idx, const SBFileSpec &sb_file, bool full) 86 { 87 return m_opaque_ap->FindFileIndex (idx, sb_file.ref(), full); 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 { 126 Stream &strm = description.ref(); 127 128 if (m_opaque_ap.get()) 129 { 130 uint32_t num_files = m_opaque_ap->GetSize(); 131 strm.Printf ("%d files: ", num_files); 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))) 136 strm.Printf ("\n %s", path); 137 } 138 } 139 else 140 strm.PutCString ("No value"); 141 142 return true; 143 } 144