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
20using namespace lldb;
21using namespace lldb_private;
22
23
24
25SBFileSpecList::SBFileSpecList () :
26    m_opaque_ap(new FileSpecList())
27{
28}
29
30SBFileSpecList::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                     rhs.m_opaque_ap.get(), m_opaque_ap.get());
42    }
43}
44
45SBFileSpecList::~SBFileSpecList ()
46{
47}
48
49const SBFileSpecList &
50SBFileSpecList::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
59uint32_t
60SBFileSpecList::GetSize () const
61{
62    return m_opaque_ap->GetSize();
63}
64
65void
66SBFileSpecList::Append (const SBFileSpec &sb_file)
67{
68    m_opaque_ap->Append (sb_file.ref());
69}
70
71bool
72SBFileSpecList::AppendIfUnique (const SBFileSpec &sb_file)
73{
74    return m_opaque_ap->AppendIfUnique (sb_file.ref());
75}
76
77void
78SBFileSpecList::Clear()
79{
80    m_opaque_ap->Clear();
81}
82
83uint32_t
84SBFileSpecList::FindFileIndex (uint32_t idx, const SBFileSpec &sb_file, bool full)
85{
86    return m_opaque_ap->FindFileIndex (idx, sb_file.ref(), full);
87}
88
89const SBFileSpec
90SBFileSpecList::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
97const lldb_private::FileSpecList *
98SBFileSpecList::operator->() const
99{
100    return m_opaque_ap.get();
101}
102
103const lldb_private::FileSpecList *
104SBFileSpecList::get() const
105{
106    return m_opaque_ap.get();
107}
108
109
110const lldb_private::FileSpecList &
111SBFileSpecList::operator*() const
112{
113    return *m_opaque_ap.get();
114}
115
116const lldb_private::FileSpecList &
117SBFileSpecList::ref() const
118{
119    return *m_opaque_ap.get();
120}
121
122bool
123SBFileSpecList::GetDescription (SBStream &description) const
124{
125    Stream &strm = description.ref();
126
127    if (m_opaque_ap.get())
128    {
129        uint32_t num_files = m_opaque_ap->GetSize();
130        strm.Printf ("%d files: ", num_files);
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)))
135                strm.Printf ("\n    %s", path);
136        }
137    }
138    else
139        strm.PutCString ("No value");
140
141    return true;
142}
143