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