blob: 36fcf1bbf2e3206327d43f116e6e0ef91b116bf4 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Core/FileSpec.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
17
18
19SBFileSpec::SBFileSpec () :
Greg Clayton63094e02010-06-23 01:19:29 +000020 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000021{
22}
23
24SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000025 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000026{
Greg Clayton63094e02010-06-23 01:19:29 +000027 if (rhs.m_opaque_ap.get())
Johnny Chen4ead2e92010-08-27 22:35:26 +000028 m_opaque_ap.reset (new FileSpec (rhs.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000029}
30
31SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton63094e02010-06-23 01:19:29 +000032 m_opaque_ap(new FileSpec (path))
Chris Lattner24943d22010-06-08 16:52:24 +000033{
34}
35
36SBFileSpec::~SBFileSpec ()
37{
38}
39
40const SBFileSpec &
41SBFileSpec::operator = (const SBFileSpec &rhs)
42{
43 if (this != &rhs)
44 {
45 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000046 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000047 }
48 return *this;
49}
50
51bool
52SBFileSpec::IsValid() const
53{
Greg Clayton63094e02010-06-23 01:19:29 +000054 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000055}
56
57bool
58SBFileSpec::Exists () const
59{
Greg Clayton63094e02010-06-23 01:19:29 +000060 if (m_opaque_ap.get())
61 return m_opaque_ap->Exists();
Chris Lattner24943d22010-06-08 16:52:24 +000062 return false;
63}
64
Caroline Ticeeddffe92010-09-10 04:48:55 +000065bool
66SBFileSpec::ResolveExecutableLocation ()
67{
68 if (m_opaque_ap.get())
69 return m_opaque_ap->ResolveExecutableLocation ();
70 return false;
71}
Chris Lattner24943d22010-06-08 16:52:24 +000072
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 *
Johnny Chen4ead2e92010-08-27 22:35:26 +000080SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +000081{
Greg Clayton63094e02010-06-23 01:19:29 +000082 if (m_opaque_ap.get())
83 return m_opaque_ap->GetFilename().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000084 return NULL;
85}
86
87const char *
88SBFileSpec::GetDirectory() const
89{
Greg Clayton63094e02010-06-23 01:19:29 +000090 if (m_opaque_ap.get())
91 return m_opaque_ap->GetDirectory().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000092 return NULL;
93}
94
95uint32_t
96SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
97{
Greg Clayton63094e02010-06-23 01:19:29 +000098 if (m_opaque_ap.get())
99 return m_opaque_ap->GetPath (dst_path, dst_len);
Chris Lattner24943d22010-06-08 16:52:24 +0000100
101 if (dst_path && dst_len)
102 *dst_path = '\0';
103 return 0;
104}
105
106
107const lldb_private::FileSpec *
108SBFileSpec::operator->() const
109{
Greg Clayton63094e02010-06-23 01:19:29 +0000110 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000111}
112
113const lldb_private::FileSpec *
114SBFileSpec::get() const
115{
Greg Clayton63094e02010-06-23 01:19:29 +0000116 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000117}
118
119
120const lldb_private::FileSpec &
121SBFileSpec::operator*() const
122{
Greg Clayton63094e02010-06-23 01:19:29 +0000123 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000124}
125
126const lldb_private::FileSpec &
127SBFileSpec::ref() const
128{
Greg Clayton63094e02010-06-23 01:19:29 +0000129 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000130}
131
132
133void
134SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
135{
Greg Clayton63094e02010-06-23 01:19:29 +0000136 if (m_opaque_ap.get())
137 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000138 else
Greg Clayton63094e02010-06-23 01:19:29 +0000139 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000140}
141
Caroline Tice98f930f2010-09-20 05:20:02 +0000142bool
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}