Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/Core/FileSpec.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
| 17 | |
| 18 | |
| 19 | SBFileSpec::SBFileSpec () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 20 | m_opaque_ap() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | { |
| 22 | } |
| 23 | |
| 24 | SBFileSpec::SBFileSpec (const SBFileSpec &rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 25 | m_opaque_ap() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 27 | if (rhs.m_opaque_ap.get()) |
Johnny Chen | 4ead2e9 | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 28 | m_opaque_ap.reset (new FileSpec (rhs.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame^] | 31 | // Deprected!!! |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | SBFileSpec::SBFileSpec (const char *path) : |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame^] | 33 | m_opaque_ap(new FileSpec (path, true)) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | SBFileSpec::SBFileSpec (const char *path, bool resolve) : |
| 38 | m_opaque_ap(new FileSpec (path, resolve)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | { |
| 40 | } |
| 41 | |
| 42 | SBFileSpec::~SBFileSpec () |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | const SBFileSpec & |
| 47 | SBFileSpec::operator = (const SBFileSpec &rhs) |
| 48 | { |
| 49 | if (this != &rhs) |
| 50 | { |
| 51 | if (rhs.IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 52 | m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | } |
| 54 | return *this; |
| 55 | } |
| 56 | |
| 57 | bool |
| 58 | SBFileSpec::IsValid() const |
| 59 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 60 | return m_opaque_ap.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bool |
| 64 | SBFileSpec::Exists () const |
| 65 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 66 | if (m_opaque_ap.get()) |
| 67 | return m_opaque_ap->Exists(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | return false; |
| 69 | } |
| 70 | |
Caroline Tice | eddffe9 | 2010-09-10 04:48:55 +0000 | [diff] [blame] | 71 | bool |
| 72 | SBFileSpec::ResolveExecutableLocation () |
| 73 | { |
| 74 | if (m_opaque_ap.get()) |
| 75 | return m_opaque_ap->ResolveExecutableLocation (); |
| 76 | return false; |
| 77 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | |
| 79 | int |
| 80 | SBFileSpec::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 | |
| 85 | const char * |
Johnny Chen | 4ead2e9 | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 86 | SBFileSpec::GetFilename() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 88 | if (m_opaque_ap.get()) |
| 89 | return m_opaque_ap->GetFilename().AsCString(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | const char * |
| 94 | SBFileSpec::GetDirectory() const |
| 95 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 96 | if (m_opaque_ap.get()) |
| 97 | return m_opaque_ap->GetDirectory().AsCString(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | uint32_t |
| 102 | SBFileSpec::GetPath (char *dst_path, size_t dst_len) const |
| 103 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 104 | if (m_opaque_ap.get()) |
| 105 | return m_opaque_ap->GetPath (dst_path, dst_len); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | |
| 107 | if (dst_path && dst_len) |
| 108 | *dst_path = '\0'; |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | const lldb_private::FileSpec * |
| 114 | SBFileSpec::operator->() const |
| 115 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 116 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | const lldb_private::FileSpec * |
| 120 | SBFileSpec::get() const |
| 121 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 122 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |
| 126 | const lldb_private::FileSpec & |
| 127 | SBFileSpec::operator*() const |
| 128 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 129 | return *m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | const lldb_private::FileSpec & |
| 133 | SBFileSpec::ref() const |
| 134 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 135 | return *m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | |
| 139 | void |
| 140 | SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs) |
| 141 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 142 | if (m_opaque_ap.get()) |
| 143 | *m_opaque_ap = fs; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 145 | m_opaque_ap.reset (new FileSpec (fs)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 148 | bool |
| 149 | SBFileSpec::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 | } |