1 //===-- SBFileSpec.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Host/FileSpec.h"
15 #include "lldb/Core/Log.h"
16 #include "lldb/Core/Stream.h"
19 using namespace lldb_private;
23 SBFileSpec::SBFileSpec () :
24 m_opaque_ap(new lldb_private::FileSpec())
28 SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
29 m_opaque_ap(new lldb_private::FileSpec(*rhs.m_opaque_ap))
33 SBFileSpec::SBFileSpec (const lldb_private::FileSpec& fspec) :
34 m_opaque_ap(new lldb_private::FileSpec(fspec))
39 SBFileSpec::SBFileSpec (const char *path) :
40 m_opaque_ap(new FileSpec (path, true))
44 SBFileSpec::SBFileSpec (const char *path, bool resolve) :
45 m_opaque_ap(new FileSpec (path, resolve))
49 SBFileSpec::~SBFileSpec ()
54 SBFileSpec::operator = (const SBFileSpec &rhs)
57 *m_opaque_ap = *rhs.m_opaque_ap;
62 SBFileSpec::IsValid() const
64 return m_opaque_ap->operator bool();
68 SBFileSpec::Exists () const
70 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
72 bool result = m_opaque_ap->Exists();
75 log->Printf ("SBFileSpec(%p)::Exists () => %s", m_opaque_ap.get(), (result ? "true" : "false"));
81 SBFileSpec::ResolveExecutableLocation ()
83 return m_opaque_ap->ResolveExecutableLocation ();
87 SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
89 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
93 SBFileSpec::GetFilename() const
95 const char *s = m_opaque_ap->GetFilename().AsCString();
97 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
101 log->Printf ("SBFileSpec(%p)::GetFilename () => \"%s\"", m_opaque_ap.get(), s);
103 log->Printf ("SBFileSpec(%p)::GetFilename () => NULL", m_opaque_ap.get());
110 SBFileSpec::GetDirectory() const
112 const char *s = m_opaque_ap->GetDirectory().AsCString();
113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
117 log->Printf ("SBFileSpec(%p)::GetDirectory () => \"%s\"", m_opaque_ap.get(), s);
119 log->Printf ("SBFileSpec(%p)::GetDirectory () => NULL", m_opaque_ap.get());
125 SBFileSpec::SetFilename(const char *filename)
127 if (filename && filename[0])
128 m_opaque_ap->GetFilename().SetCString(filename);
130 m_opaque_ap->GetFilename().Clear();
134 SBFileSpec::SetDirectory(const char *directory)
136 if (directory && directory[0])
137 m_opaque_ap->GetDirectory().SetCString(directory);
139 m_opaque_ap->GetDirectory().Clear();
143 SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
145 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
147 uint32_t result = m_opaque_ap->GetPath (dst_path, dst_len);
150 log->Printf ("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64 ") => %u",
151 m_opaque_ap.get(), result, dst_path, (uint64_t)dst_len, result);
153 if (result == 0 && dst_path && dst_len > 0)
159 const lldb_private::FileSpec *
160 SBFileSpec::operator->() const
162 return m_opaque_ap.get();
165 const lldb_private::FileSpec *
166 SBFileSpec::get() const
168 return m_opaque_ap.get();
172 const lldb_private::FileSpec &
173 SBFileSpec::operator*() const
175 return *m_opaque_ap.get();
178 const lldb_private::FileSpec &
179 SBFileSpec::ref() const
181 return *m_opaque_ap.get();
186 SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
192 SBFileSpec::GetDescription (SBStream &description) const
194 Stream &strm = description.ref();
196 if (m_opaque_ap->GetPath(path, sizeof(path)))
197 strm.PutCString (path);