SBFileSpec.cpp revision 98f930f429160f9777f626c3ac6aa609f4e965d2
1//===-- SBFileSpec.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 "lldb/API/SBFileSpec.h"
11#include "lldb/API/SBStream.h"
12#include "lldb/Core/FileSpec.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
17
18
19SBFileSpec::SBFileSpec () :
20    m_opaque_ap()
21{
22}
23
24SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
25    m_opaque_ap()
26{
27    if (rhs.m_opaque_ap.get())
28        m_opaque_ap.reset (new FileSpec (rhs.get()));
29}
30
31SBFileSpec::SBFileSpec (const char *path) :
32    m_opaque_ap(new FileSpec (path))
33{
34}
35
36SBFileSpec::~SBFileSpec ()
37{
38}
39
40const SBFileSpec &
41SBFileSpec::operator = (const SBFileSpec &rhs)
42{
43    if (this != &rhs)
44    {
45        if (rhs.IsValid())
46            m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
47    }
48    return *this;
49}
50
51bool
52SBFileSpec::IsValid() const
53{
54    return m_opaque_ap.get() != NULL;
55}
56
57bool
58SBFileSpec::Exists () const
59{
60    if (m_opaque_ap.get())
61        return m_opaque_ap->Exists();
62    return false;
63}
64
65bool
66SBFileSpec::ResolveExecutableLocation ()
67{
68    if (m_opaque_ap.get())
69        return m_opaque_ap->ResolveExecutableLocation ();
70    return false;
71}
72
73int
74SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
75{
76    return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
77}
78
79const char *
80SBFileSpec::GetFilename() const
81{
82    if (m_opaque_ap.get())
83        return m_opaque_ap->GetFilename().AsCString();
84    return NULL;
85}
86
87const char *
88SBFileSpec::GetDirectory() const
89{
90    if (m_opaque_ap.get())
91        return m_opaque_ap->GetDirectory().AsCString();
92    return NULL;
93}
94
95uint32_t
96SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
97{
98    if (m_opaque_ap.get())
99        return m_opaque_ap->GetPath (dst_path, dst_len);
100
101    if (dst_path && dst_len)
102        *dst_path = '\0';
103    return 0;
104}
105
106
107const lldb_private::FileSpec *
108SBFileSpec::operator->() const
109{
110    return m_opaque_ap.get();
111}
112
113const lldb_private::FileSpec *
114SBFileSpec::get() const
115{
116    return m_opaque_ap.get();
117}
118
119
120const lldb_private::FileSpec &
121SBFileSpec::operator*() const
122{
123    return *m_opaque_ap.get();
124}
125
126const lldb_private::FileSpec &
127SBFileSpec::ref() const
128{
129    return *m_opaque_ap.get();
130}
131
132
133void
134SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
135{
136    if (m_opaque_ap.get())
137        *m_opaque_ap = fs;
138    else
139        m_opaque_ap.reset (new FileSpec (fs));
140}
141
142bool
143SBFileSpec::GetDescription (SBStream &description)
144{
145    if (m_opaque_ap.get())
146    {
147        const char *filename = GetFilename();
148        const char *dir_name = GetDirectory();
149        if (!filename && !dir_name)
150            description.Printf ("No value");
151        else if (!dir_name)
152            description.Printf ("%s", filename);
153        else
154            description.Printf ("%s/%s", dir_name, filename);
155    }
156    else
157        description.Printf ("No value");
158
159    return true;
160}
161
162PyObject *
163SBFileSpec::__repr__ ()
164{
165    SBStream description;
166    GetDescription (description);
167    return PyString_FromString (description.GetData());
168}
169