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 
14 using namespace lldb;
15 using namespace lldb_private;
16 
17 
18 
19 SBFileSpec::SBFileSpec () :
20     m_opaque_ap()
21 {
22 }
23 
24 SBFileSpec::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!!!
32 SBFileSpec::SBFileSpec (const char *path) :
33     m_opaque_ap(new FileSpec (path, true))
34 {
35 }
36 
37 SBFileSpec::SBFileSpec (const char *path, bool resolve) :
38     m_opaque_ap(new FileSpec (path, resolve))
39 {
40 }
41 
42 SBFileSpec::~SBFileSpec ()
43 {
44 }
45 
46 const SBFileSpec &
47 SBFileSpec::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 
57 bool
58 SBFileSpec::IsValid() const
59 {
60     return m_opaque_ap.get() != NULL;
61 }
62 
63 bool
64 SBFileSpec::Exists () const
65 {
66     if (m_opaque_ap.get())
67         return m_opaque_ap->Exists();
68     return false;
69 }
70 
71 bool
72 SBFileSpec::ResolveExecutableLocation ()
73 {
74     if (m_opaque_ap.get())
75         return m_opaque_ap->ResolveExecutableLocation ();
76     return false;
77 }
78 
79 int
80 SBFileSpec::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 
85 const char *
86 SBFileSpec::GetFilename() const
87 {
88     if (m_opaque_ap.get())
89         return m_opaque_ap->GetFilename().AsCString();
90     return NULL;
91 }
92 
93 const char *
94 SBFileSpec::GetDirectory() const
95 {
96     if (m_opaque_ap.get())
97         return m_opaque_ap->GetDirectory().AsCString();
98     return NULL;
99 }
100 
101 uint32_t
102 SBFileSpec::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 
113 const lldb_private::FileSpec *
114 SBFileSpec::operator->() const
115 {
116     return m_opaque_ap.get();
117 }
118 
119 const lldb_private::FileSpec *
120 SBFileSpec::get() const
121 {
122     return m_opaque_ap.get();
123 }
124 
125 
126 const lldb_private::FileSpec &
127 SBFileSpec::operator*() const
128 {
129     return *m_opaque_ap.get();
130 }
131 
132 const lldb_private::FileSpec &
133 SBFileSpec::ref() const
134 {
135     return *m_opaque_ap.get();
136 }
137 
138 
139 void
140 SBFileSpec::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 
148 bool
149 SBFileSpec::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