2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBFileSpec.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBFileSpec.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/FileSpec.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SBFileSpec::SBFileSpec () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (rhs.m_opaque_ap.get())
|
2010-08-28 06:35:26 +08:00
|
|
|
m_opaque_ap.reset (new FileSpec (rhs.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-21 04:54:39 +08:00
|
|
|
// Deprected!!!
|
2010-06-09 00:52:24 +08:00
|
|
|
SBFileSpec::SBFileSpec (const char *path) :
|
2010-10-21 04:54:39 +08:00
|
|
|
m_opaque_ap(new FileSpec (path, true))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec::SBFileSpec (const char *path, bool resolve) :
|
|
|
|
m_opaque_ap(new FileSpec (path, resolve))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec::~SBFileSpec ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBFileSpec &
|
|
|
|
SBFileSpec::operator = (const SBFileSpec &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBFileSpec::IsValid() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBFileSpec::Exists () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->Exists();
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-10 12:48:55 +08:00
|
|
|
bool
|
|
|
|
SBFileSpec::ResolveExecutableLocation ()
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->ResolveExecutableLocation ();
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
|
|
|
|
{
|
|
|
|
return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2010-08-28 06:35:26 +08:00
|
|
|
SBFileSpec::GetFilename() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->GetFilename().AsCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBFileSpec::GetDirectory() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->GetDirectory().AsCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->GetPath (dst_path, dst_len);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (dst_path && dst_len)
|
|
|
|
*dst_path = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const lldb_private::FileSpec *
|
|
|
|
SBFileSpec::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::FileSpec *
|
|
|
|
SBFileSpec::get() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const lldb_private::FileSpec &
|
|
|
|
SBFileSpec::operator*() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::FileSpec &
|
|
|
|
SBFileSpec::ref() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
*m_opaque_ap = fs;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new FileSpec (fs));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBFileSpec::GetDescription (SBStream &description)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
{
|
|
|
|
const char *filename = GetFilename();
|
|
|
|
const char *dir_name = GetDirectory();
|
|
|
|
if (!filename && !dir_name)
|
|
|
|
description.Printf ("No value");
|
|
|
|
else if (!dir_name)
|
|
|
|
description.Printf ("%s", filename);
|
|
|
|
else
|
|
|
|
description.Printf ("%s/%s", dir_name, filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
description.Printf ("No value");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|