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 
17 SBStringList::SBStringList() { LLDB_INSTRUMENT_VA(this); }
18 
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 
24 SBStringList::SBStringList(const SBStringList &rhs) {
25   LLDB_INSTRUMENT_VA(this, rhs);
26 
27   m_opaque_up = clone(rhs.m_opaque_up);
28 }
29 
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 
40 const lldb_private::StringList *SBStringList::operator->() const {
41   return m_opaque_up.get();
42 }
43 
44 const lldb_private::StringList &SBStringList::operator*() const {
45   return *m_opaque_up;
46 }
47 
48 bool SBStringList::IsValid() const {
49   LLDB_INSTRUMENT_VA(this);
50   return this->operator bool();
51 }
52 SBStringList::operator bool() const {
53   LLDB_INSTRUMENT_VA(this);
54 
55   return (m_opaque_up != nullptr);
56 }
57 
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 
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 
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 
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 
96 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 
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 
114 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 
123 void SBStringList::Clear() {
124   LLDB_INSTRUMENT_VA(this);
125 
126   if (IsValid()) {
127     m_opaque_up->Clear();
128   }
129 }
130