1 //===-- SBStringList.cpp ----------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBStringList.h" 10 11 #include "lldb/Utility/StringList.h" 12 13 using namespace lldb; 14 using namespace lldb_private; 15 16 SBStringList::SBStringList() : m_opaque_up() {} 17 18 SBStringList::SBStringList(const lldb_private::StringList *lldb_strings_ptr) 19 : m_opaque_up() { 20 if (lldb_strings_ptr) 21 m_opaque_up.reset(new lldb_private::StringList(*lldb_strings_ptr)); 22 } 23 24 SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_up() { 25 if (rhs.IsValid()) 26 m_opaque_up.reset(new lldb_private::StringList(*rhs)); 27 } 28 29 const SBStringList &SBStringList::operator=(const SBStringList &rhs) { 30 if (this != &rhs) { 31 if (rhs.IsValid()) 32 m_opaque_up.reset(new lldb_private::StringList(*rhs)); 33 else 34 m_opaque_up.reset(); 35 } 36 return *this; 37 } 38 39 SBStringList::~SBStringList() {} 40 41 const lldb_private::StringList *SBStringList::operator->() const { 42 return m_opaque_up.get(); 43 } 44 45 const lldb_private::StringList &SBStringList::operator*() const { 46 return *m_opaque_up; 47 } 48 49 bool SBStringList::IsValid() const { return (m_opaque_up != NULL); } 50 51 void SBStringList::AppendString(const char *str) { 52 if (str != NULL) { 53 if (IsValid()) 54 m_opaque_up->AppendString(str); 55 else 56 m_opaque_up.reset(new lldb_private::StringList(str)); 57 } 58 } 59 60 void SBStringList::AppendList(const char **strv, int strc) { 61 if ((strv != NULL) && (strc > 0)) { 62 if (IsValid()) 63 m_opaque_up->AppendList(strv, strc); 64 else 65 m_opaque_up.reset(new lldb_private::StringList(strv, strc)); 66 } 67 } 68 69 void SBStringList::AppendList(const SBStringList &strings) { 70 if (strings.IsValid()) { 71 if (!IsValid()) 72 m_opaque_up.reset(new lldb_private::StringList()); 73 m_opaque_up->AppendList(*(strings.m_opaque_up)); 74 } 75 } 76 77 void SBStringList::AppendList(const StringList &strings) { 78 if (!IsValid()) 79 m_opaque_up.reset(new lldb_private::StringList()); 80 m_opaque_up->AppendList(strings); 81 } 82 83 uint32_t SBStringList::GetSize() const { 84 if (IsValid()) { 85 return m_opaque_up->GetSize(); 86 } 87 return 0; 88 } 89 90 const char *SBStringList::GetStringAtIndex(size_t idx) { 91 if (IsValid()) { 92 return m_opaque_up->GetStringAtIndex(idx); 93 } 94 return NULL; 95 } 96 97 const char *SBStringList::GetStringAtIndex(size_t idx) const { 98 if (IsValid()) { 99 return m_opaque_up->GetStringAtIndex(idx); 100 } 101 return NULL; 102 } 103 104 void SBStringList::Clear() { 105 if (IsValid()) { 106 m_opaque_up->Clear(); 107 } 108 } 109