blob: fb504f233f91df4dcbe6118e1366deea0a5433b1 [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
Greg Clayton537a7a82010-10-20 20:54:39 +000031// Deprected!!!
Chris Lattner24943d22010-06-08 16:52:24 +000032SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton537a7a82010-10-20 20:54:39 +000033 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))
Chris Lattner24943d22010-06-08 16:52:24 +000039{
40}
41
42SBFileSpec::~SBFileSpec ()
43{
44}
45
46const SBFileSpec &
47SBFileSpec::operator = (const SBFileSpec &rhs)
48{
49 if (this != &rhs)
50 {
51 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000052 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000053 }
54 return *this;
55}
56
57bool
58SBFileSpec::IsValid() const
59{
Greg Clayton63094e02010-06-23 01:19:29 +000060 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000061}
62
63bool
64SBFileSpec::Exists () const
65{
Greg Clayton63094e02010-06-23 01:19:29 +000066 if (m_opaque_ap.get())
67 return m_opaque_ap->Exists();
Chris Lattner24943d22010-06-08 16:52:24 +000068 return false;
69}
70
Caroline Ticeeddffe92010-09-10 04:48:55 +000071bool
72SBFileSpec::ResolveExecutableLocation ()
73{
74 if (m_opaque_ap.get())
75 return m_opaque_ap->ResolveExecutableLocation ();
76 return false;
77}
Chris Lattner24943d22010-06-08 16:52:24 +000078
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 *
Johnny Chen4ead2e92010-08-27 22:35:26 +000086SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +000087{
Greg Clayton63094e02010-06-23 01:19:29 +000088 if (m_opaque_ap.get())
89 return m_opaque_ap->GetFilename().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000090 return NULL;
91}
92
93const char *
94SBFileSpec::GetDirectory() const
95{
Greg Clayton63094e02010-06-23 01:19:29 +000096 if (m_opaque_ap.get())
97 return m_opaque_ap->GetDirectory().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000098 return NULL;
99}
100
101uint32_t
102SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
103{
Greg Clayton63094e02010-06-23 01:19:29 +0000104 if (m_opaque_ap.get())
105 return m_opaque_ap->GetPath (dst_path, dst_len);
Chris Lattner24943d22010-06-08 16:52:24 +0000106
107 if (dst_path && dst_len)
108 *dst_path = '\0';
109 return 0;
110}
111
112
113const lldb_private::FileSpec *
114SBFileSpec::operator->() const
115{
Greg Clayton63094e02010-06-23 01:19:29 +0000116 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000117}
118
119const lldb_private::FileSpec *
120SBFileSpec::get() const
121{
Greg Clayton63094e02010-06-23 01:19:29 +0000122 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125
126const lldb_private::FileSpec &
127SBFileSpec::operator*() const
128{
Greg Clayton63094e02010-06-23 01:19:29 +0000129 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000130}
131
132const lldb_private::FileSpec &
133SBFileSpec::ref() const
134{
Greg Clayton63094e02010-06-23 01:19:29 +0000135 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
138
139void
140SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
141{
Greg Clayton63094e02010-06-23 01:19:29 +0000142 if (m_opaque_ap.get())
143 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000144 else
Greg Clayton63094e02010-06-23 01:19:29 +0000145 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000146}
147
Caroline Tice98f930f2010-09-20 05:20:02 +0000148bool
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}