SBFileSpec.cpp revision 4ead2e9a5a74f465d00b0301c165fbebf4ee4ff3
1//===-- 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 () :
19    m_opaque_ap()
20{
21}
22
23SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
24    m_opaque_ap()
25{
26    if (rhs.m_opaque_ap.get())
27        m_opaque_ap.reset (new FileSpec (rhs.get()));
28}
29
30SBFileSpec::SBFileSpec (const char *path) :
31    m_opaque_ap(new FileSpec (path))
32{
33}
34
35SBFileSpec::~SBFileSpec ()
36{
37}
38
39const SBFileSpec &
40SBFileSpec::operator = (const SBFileSpec &rhs)
41{
42    if (this != &rhs)
43    {
44        if (rhs.IsValid())
45            m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
46    }
47    return *this;
48}
49
50bool
51SBFileSpec::IsValid() const
52{
53    return m_opaque_ap.get() != NULL;
54}
55
56bool
57SBFileSpec::Exists () const
58{
59    if (m_opaque_ap.get())
60        return m_opaque_ap->Exists();
61    return false;
62}
63
64
65int
66SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
67{
68    return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
69}
70
71const char *
72SBFileSpec::GetFilename() const
73{
74    if (m_opaque_ap.get())
75        return m_opaque_ap->GetFilename().AsCString();
76    return NULL;
77}
78
79const char *
80SBFileSpec::GetDirectory() const
81{
82    if (m_opaque_ap.get())
83        return m_opaque_ap->GetDirectory().AsCString();
84    return NULL;
85}
86
87uint32_t
88SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
89{
90    if (m_opaque_ap.get())
91        return m_opaque_ap->GetPath (dst_path, dst_len);
92
93    if (dst_path && dst_len)
94        *dst_path = '\0';
95    return 0;
96}
97
98
99const lldb_private::FileSpec *
100SBFileSpec::operator->() const
101{
102    return m_opaque_ap.get();
103}
104
105const lldb_private::FileSpec *
106SBFileSpec::get() const
107{
108    return m_opaque_ap.get();
109}
110
111
112const lldb_private::FileSpec &
113SBFileSpec::operator*() const
114{
115    return *m_opaque_ap.get();
116}
117
118const lldb_private::FileSpec &
119SBFileSpec::ref() const
120{
121    return *m_opaque_ap.get();
122}
123
124
125void
126SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
127{
128    if (m_opaque_ap.get())
129        *m_opaque_ap = fs;
130    else
131        m_opaque_ap.reset (new FileSpec (fs));
132}
133
134