1435933ddSDimitry Andric //===-- SBFileSpecList.cpp --------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include <limits.h>
11ac7ddfbfSEd Maste 
12ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h"
13ac7ddfbfSEd Maste #include "lldb/API/SBFileSpecList.h"
14ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
15ac7ddfbfSEd Maste #include "lldb/Core/FileSpecList.h"
16f678e45dSDimitry Andric #include "lldb/Host/PosixApi.h"
17f678e45dSDimitry Andric #include "lldb/Utility/FileSpec.h"
18f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
19f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
20ac7ddfbfSEd Maste 
21ac7ddfbfSEd Maste using namespace lldb;
22ac7ddfbfSEd Maste using namespace lldb_private;
23ac7ddfbfSEd Maste 
SBFileSpecList()24435933ddSDimitry Andric SBFileSpecList::SBFileSpecList() : m_opaque_ap(new FileSpecList()) {}
25ac7ddfbfSEd Maste 
SBFileSpecList(const SBFileSpecList & rhs)26435933ddSDimitry Andric SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_ap() {
27ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
28ac7ddfbfSEd Maste 
29*b5893f02SDimitry Andric   if (rhs.m_opaque_ap)
30ac7ddfbfSEd Maste     m_opaque_ap.reset(new FileSpecList(*(rhs.get())));
31ac7ddfbfSEd Maste 
32435933ddSDimitry Andric   if (log) {
33435933ddSDimitry Andric     log->Printf("SBFileSpecList::SBFileSpecList (const SBFileSpecList "
34435933ddSDimitry Andric                 "rhs.ap=%p) => SBFileSpecList(%p)",
350127ef0fSEd Maste                 static_cast<void *>(rhs.m_opaque_ap.get()),
360127ef0fSEd Maste                 static_cast<void *>(m_opaque_ap.get()));
37ac7ddfbfSEd Maste   }
38ac7ddfbfSEd Maste }
39ac7ddfbfSEd Maste 
~SBFileSpecList()40435933ddSDimitry Andric SBFileSpecList::~SBFileSpecList() {}
41ac7ddfbfSEd Maste 
operator =(const SBFileSpecList & rhs)42435933ddSDimitry Andric const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
43435933ddSDimitry Andric   if (this != &rhs) {
44ac7ddfbfSEd Maste     m_opaque_ap.reset(new lldb_private::FileSpecList(*(rhs.get())));
45ac7ddfbfSEd Maste   }
46ac7ddfbfSEd Maste   return *this;
47ac7ddfbfSEd Maste }
48ac7ddfbfSEd Maste 
GetSize() const49435933ddSDimitry Andric uint32_t SBFileSpecList::GetSize() const { return m_opaque_ap->GetSize(); }
50ac7ddfbfSEd Maste 
Append(const SBFileSpec & sb_file)51435933ddSDimitry Andric void SBFileSpecList::Append(const SBFileSpec &sb_file) {
52ac7ddfbfSEd Maste   m_opaque_ap->Append(sb_file.ref());
53ac7ddfbfSEd Maste }
54ac7ddfbfSEd Maste 
AppendIfUnique(const SBFileSpec & sb_file)55435933ddSDimitry Andric bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
56ac7ddfbfSEd Maste   return m_opaque_ap->AppendIfUnique(sb_file.ref());
57ac7ddfbfSEd Maste }
58ac7ddfbfSEd Maste 
Clear()59435933ddSDimitry Andric void SBFileSpecList::Clear() { m_opaque_ap->Clear(); }
60ac7ddfbfSEd Maste 
FindFileIndex(uint32_t idx,const SBFileSpec & sb_file,bool full)61435933ddSDimitry Andric uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
62435933ddSDimitry Andric                                        bool full) {
63ac7ddfbfSEd Maste   return m_opaque_ap->FindFileIndex(idx, sb_file.ref(), full);
64ac7ddfbfSEd Maste }
65ac7ddfbfSEd Maste 
GetFileSpecAtIndex(uint32_t idx) const66435933ddSDimitry Andric const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
67ac7ddfbfSEd Maste   SBFileSpec new_spec;
68ac7ddfbfSEd Maste   new_spec.SetFileSpec(m_opaque_ap->GetFileSpecAtIndex(idx));
69ac7ddfbfSEd Maste   return new_spec;
70ac7ddfbfSEd Maste }
71ac7ddfbfSEd Maste 
operator ->() const72435933ddSDimitry Andric const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
73ac7ddfbfSEd Maste   return m_opaque_ap.get();
74ac7ddfbfSEd Maste }
75ac7ddfbfSEd Maste 
get() const76435933ddSDimitry Andric const lldb_private::FileSpecList *SBFileSpecList::get() const {
77ac7ddfbfSEd Maste   return m_opaque_ap.get();
78ac7ddfbfSEd Maste }
79ac7ddfbfSEd Maste 
operator *() const80435933ddSDimitry Andric const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
81*b5893f02SDimitry Andric   return *m_opaque_ap;
82ac7ddfbfSEd Maste }
83ac7ddfbfSEd Maste 
ref() const84435933ddSDimitry Andric const lldb_private::FileSpecList &SBFileSpecList::ref() const {
85*b5893f02SDimitry Andric   return *m_opaque_ap;
86ac7ddfbfSEd Maste }
87ac7ddfbfSEd Maste 
GetDescription(SBStream & description) const88435933ddSDimitry Andric bool SBFileSpecList::GetDescription(SBStream &description) const {
89ac7ddfbfSEd Maste   Stream &strm = description.ref();
90ac7ddfbfSEd Maste 
91*b5893f02SDimitry Andric   if (m_opaque_ap) {
92ac7ddfbfSEd Maste     uint32_t num_files = m_opaque_ap->GetSize();
93ac7ddfbfSEd Maste     strm.Printf("%d files: ", num_files);
94435933ddSDimitry Andric     for (uint32_t i = 0; i < num_files; i++) {
95ac7ddfbfSEd Maste       char path[PATH_MAX];
96ac7ddfbfSEd Maste       if (m_opaque_ap->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
97ac7ddfbfSEd Maste         strm.Printf("\n    %s", path);
98ac7ddfbfSEd Maste     }
99435933ddSDimitry Andric   } else
100ac7ddfbfSEd Maste     strm.PutCString("No value");
101ac7ddfbfSEd Maste 
102ac7ddfbfSEd Maste   return true;
103ac7ddfbfSEd Maste }
104