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 13 using namespace lldb; 14 using namespace lldb_private; 15 16 17 18 SBFileSpec::SBFileSpec () : 19 m_opaque_ap() 20 { 21 } 22 23 SBFileSpec::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 30 SBFileSpec::SBFileSpec (const char *path) : 31 m_opaque_ap(new FileSpec (path)) 32 { 33 } 34 35 SBFileSpec::~SBFileSpec () 36 { 37 } 38 39 const SBFileSpec & 40 SBFileSpec::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 50 bool 51 SBFileSpec::IsValid() const 52 { 53 return m_opaque_ap.get() != NULL; 54 } 55 56 bool 57 SBFileSpec::Exists () const 58 { 59 if (m_opaque_ap.get()) 60 return m_opaque_ap->Exists(); 61 return false; 62 } 63 64 bool 65 SBFileSpec::ResolveExecutableLocation () 66 { 67 if (m_opaque_ap.get()) 68 return m_opaque_ap->ResolveExecutableLocation (); 69 return false; 70 } 71 72 int 73 SBFileSpec::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 78 const char * 79 SBFileSpec::GetFilename() const 80 { 81 if (m_opaque_ap.get()) 82 return m_opaque_ap->GetFilename().AsCString(); 83 return NULL; 84 } 85 86 const char * 87 SBFileSpec::GetDirectory() const 88 { 89 if (m_opaque_ap.get()) 90 return m_opaque_ap->GetDirectory().AsCString(); 91 return NULL; 92 } 93 94 uint32_t 95 SBFileSpec::GetPath (char *dst_path, size_t dst_len) const 96 { 97 if (m_opaque_ap.get()) 98 return m_opaque_ap->GetPath (dst_path, dst_len); 99 100 if (dst_path && dst_len) 101 *dst_path = '\0'; 102 return 0; 103 } 104 105 106 const lldb_private::FileSpec * 107 SBFileSpec::operator->() const 108 { 109 return m_opaque_ap.get(); 110 } 111 112 const lldb_private::FileSpec * 113 SBFileSpec::get() const 114 { 115 return m_opaque_ap.get(); 116 } 117 118 119 const lldb_private::FileSpec & 120 SBFileSpec::operator*() const 121 { 122 return *m_opaque_ap.get(); 123 } 124 125 const lldb_private::FileSpec & 126 SBFileSpec::ref() const 127 { 128 return *m_opaque_ap.get(); 129 } 130 131 132 void 133 SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs) 134 { 135 if (m_opaque_ap.get()) 136 *m_opaque_ap = fs; 137 else 138 m_opaque_ap.reset (new FileSpec (fs)); 139 } 140 141