1 //===-- SBStringList.cpp --------------------------------------------------===//
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 #include "Utils.h"
11 #include "lldb/Utility/Instrumentation.h"
12 #include "lldb/Utility/StringList.h"
13
14 using namespace lldb;
15 using namespace lldb_private;
16
SBStringList()17 SBStringList::SBStringList() { LLDB_INSTRUMENT_VA(this); }
18
SBStringList(const lldb_private::StringList * lldb_strings_ptr)19 SBStringList::SBStringList(const lldb_private::StringList *lldb_strings_ptr) {
20 if (lldb_strings_ptr)
21 m_opaque_up = std::make_unique<StringList>(*lldb_strings_ptr);
22 }
23
SBStringList(const SBStringList & rhs)24 SBStringList::SBStringList(const SBStringList &rhs) {
25 LLDB_INSTRUMENT_VA(this, rhs);
26
27 m_opaque_up = clone(rhs.m_opaque_up);
28 }
29
operator =(const SBStringList & rhs)30 const SBStringList &SBStringList::operator=(const SBStringList &rhs) {
31 LLDB_INSTRUMENT_VA(this, rhs);
32
33 if (this != &rhs)
34 m_opaque_up = clone(rhs.m_opaque_up);
35 return *this;
36 }
37
38 SBStringList::~SBStringList() = default;
39
operator ->() const40 const lldb_private::StringList *SBStringList::operator->() const {
41 return m_opaque_up.get();
42 }
43
operator *() const44 const lldb_private::StringList &SBStringList::operator*() const {
45 return *m_opaque_up;
46 }
47
IsValid() const48 bool SBStringList::IsValid() const {
49 LLDB_INSTRUMENT_VA(this);
50 return this->operator bool();
51 }
operator bool() const52 SBStringList::operator bool() const {
53 LLDB_INSTRUMENT_VA(this);
54
55 return (m_opaque_up != nullptr);
56 }
57
AppendString(const char * str)58 void SBStringList::AppendString(const char *str) {
59 LLDB_INSTRUMENT_VA(this, str);
60
61 if (str != nullptr) {
62 if (IsValid())
63 m_opaque_up->AppendString(str);
64 else
65 m_opaque_up = std::make_unique<lldb_private::StringList>(str);
66 }
67 }
68
AppendList(const char ** strv,int strc)69 void SBStringList::AppendList(const char **strv, int strc) {
70 LLDB_INSTRUMENT_VA(this, strv, strc);
71
72 if ((strv != nullptr) && (strc > 0)) {
73 if (IsValid())
74 m_opaque_up->AppendList(strv, strc);
75 else
76 m_opaque_up = std::make_unique<lldb_private::StringList>(strv, strc);
77 }
78 }
79
AppendList(const SBStringList & strings)80 void SBStringList::AppendList(const SBStringList &strings) {
81 LLDB_INSTRUMENT_VA(this, strings);
82
83 if (strings.IsValid()) {
84 if (!IsValid())
85 m_opaque_up = std::make_unique<lldb_private::StringList>();
86 m_opaque_up->AppendList(*(strings.m_opaque_up));
87 }
88 }
89
AppendList(const StringList & strings)90 void SBStringList::AppendList(const StringList &strings) {
91 if (!IsValid())
92 m_opaque_up = std::make_unique<lldb_private::StringList>();
93 m_opaque_up->AppendList(strings);
94 }
95
GetSize() const96 uint32_t SBStringList::GetSize() const {
97 LLDB_INSTRUMENT_VA(this);
98
99 if (IsValid()) {
100 return m_opaque_up->GetSize();
101 }
102 return 0;
103 }
104
GetStringAtIndex(size_t idx)105 const char *SBStringList::GetStringAtIndex(size_t idx) {
106 LLDB_INSTRUMENT_VA(this, idx);
107
108 if (IsValid()) {
109 return m_opaque_up->GetStringAtIndex(idx);
110 }
111 return nullptr;
112 }
113
GetStringAtIndex(size_t idx) const114 const char *SBStringList::GetStringAtIndex(size_t idx) const {
115 LLDB_INSTRUMENT_VA(this, idx);
116
117 if (IsValid()) {
118 return m_opaque_up->GetStringAtIndex(idx);
119 }
120 return nullptr;
121 }
122
Clear()123 void SBStringList::Clear() {
124 LLDB_INSTRUMENT_VA(this);
125
126 if (IsValid()) {
127 m_opaque_up->Clear();
128 }
129 }
130