blob: 5ec93f3b4fffc9e3c3df8b715877d5093d1334bc [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"
11#include "lldb/Core/FileSpec.h"
12
13using namespace lldb;
14using namespace lldb_private;
15
16
17
18SBFileSpec::SBFileSpec () :
Greg Clayton63094e02010-06-23 01:19:29 +000019 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000020{
21}
22
23SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000024 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000025{
Greg Clayton63094e02010-06-23 01:19:29 +000026 if (rhs.m_opaque_ap.get())
Johnny Chen4ead2e92010-08-27 22:35:26 +000027 m_opaque_ap.reset (new FileSpec (rhs.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000028}
29
30SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton63094e02010-06-23 01:19:29 +000031 m_opaque_ap(new FileSpec (path))
Chris Lattner24943d22010-06-08 16:52:24 +000032{
33}
34
35SBFileSpec::~SBFileSpec ()
36{
37}
38
39const SBFileSpec &
40SBFileSpec::operator = (const SBFileSpec &rhs)
41{
42 if (this != &rhs)
43 {
44 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000045 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000046 }
47 return *this;
48}
49
50bool
51SBFileSpec::IsValid() const
52{
Greg Clayton63094e02010-06-23 01:19:29 +000053 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000054}
55
56bool
57SBFileSpec::Exists () const
58{
Greg Clayton63094e02010-06-23 01:19:29 +000059 if (m_opaque_ap.get())
60 return m_opaque_ap->Exists();
Chris Lattner24943d22010-06-08 16:52:24 +000061 return false;
62}
63
Caroline Ticeeddffe92010-09-10 04:48:55 +000064bool
65SBFileSpec::ResolveExecutableLocation ()
66{
67 if (m_opaque_ap.get())
68 return m_opaque_ap->ResolveExecutableLocation ();
69 return false;
70}
Chris Lattner24943d22010-06-08 16:52:24 +000071
72int
73SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
74{
75 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
76}
77
78const char *
Johnny Chen4ead2e92010-08-27 22:35:26 +000079SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +000080{
Greg Clayton63094e02010-06-23 01:19:29 +000081 if (m_opaque_ap.get())
82 return m_opaque_ap->GetFilename().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000083 return NULL;
84}
85
86const char *
87SBFileSpec::GetDirectory() const
88{
Greg Clayton63094e02010-06-23 01:19:29 +000089 if (m_opaque_ap.get())
90 return m_opaque_ap->GetDirectory().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000091 return NULL;
92}
93
94uint32_t
95SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
96{
Greg Clayton63094e02010-06-23 01:19:29 +000097 if (m_opaque_ap.get())
98 return m_opaque_ap->GetPath (dst_path, dst_len);
Chris Lattner24943d22010-06-08 16:52:24 +000099
100 if (dst_path && dst_len)
101 *dst_path = '\0';
102 return 0;
103}
104
105
106const lldb_private::FileSpec *
107SBFileSpec::operator->() const
108{
Greg Clayton63094e02010-06-23 01:19:29 +0000109 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000110}
111
112const lldb_private::FileSpec *
113SBFileSpec::get() const
114{
Greg Clayton63094e02010-06-23 01:19:29 +0000115 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000116}
117
118
119const lldb_private::FileSpec &
120SBFileSpec::operator*() const
121{
Greg Clayton63094e02010-06-23 01:19:29 +0000122 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125const lldb_private::FileSpec &
126SBFileSpec::ref() const
127{
Greg Clayton63094e02010-06-23 01:19:29 +0000128 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000129}
130
131
132void
133SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
134{
Greg Clayton63094e02010-06-23 01:19:29 +0000135 if (m_opaque_ap.get())
136 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000137 else
Greg Clayton63094e02010-06-23 01:19:29 +0000138 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000139}
140