xref: /llvm-project/lldb/source/API/SBStringList.cpp (revision 7ee633a24b8ce87b3a9b2f0f4bd1aace634cd2a1)
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 ->()40 lldb_private::StringList *SBStringList::operator->() {
41   if (!IsValid())
42     m_opaque_up = std::make_unique<lldb_private::StringList>();
43 
44   return m_opaque_up.get();
45 }
46 
operator ->() const47 const lldb_private::StringList *SBStringList::operator->() const {
48   return m_opaque_up.get();
49 }
50 
operator *() const51 const lldb_private::StringList &SBStringList::operator*() const {
52   return *m_opaque_up;
53 }
54 
IsValid() const55 bool SBStringList::IsValid() const {
56   LLDB_INSTRUMENT_VA(this);
57   return this->operator bool();
58 }
operator bool() const59 SBStringList::operator bool() const {
60   LLDB_INSTRUMENT_VA(this);
61 
62   return (m_opaque_up != nullptr);
63 }
64 
AppendString(const char * str)65 void SBStringList::AppendString(const char *str) {
66   LLDB_INSTRUMENT_VA(this, str);
67 
68   if (str != nullptr) {
69     if (IsValid())
70       m_opaque_up->AppendString(str);
71     else
72       m_opaque_up = std::make_unique<lldb_private::StringList>(str);
73   }
74 }
75 
AppendList(const char ** strv,int strc)76 void SBStringList::AppendList(const char **strv, int strc) {
77   LLDB_INSTRUMENT_VA(this, strv, strc);
78 
79   if ((strv != nullptr) && (strc > 0)) {
80     if (IsValid())
81       m_opaque_up->AppendList(strv, strc);
82     else
83       m_opaque_up = std::make_unique<lldb_private::StringList>(strv, strc);
84   }
85 }
86 
AppendList(const SBStringList & strings)87 void SBStringList::AppendList(const SBStringList &strings) {
88   LLDB_INSTRUMENT_VA(this, strings);
89 
90   if (strings.IsValid()) {
91     if (!IsValid())
92       m_opaque_up = std::make_unique<lldb_private::StringList>();
93     m_opaque_up->AppendList(*(strings.m_opaque_up));
94   }
95 }
96 
AppendList(const StringList & strings)97 void SBStringList::AppendList(const StringList &strings) {
98   if (!IsValid())
99     m_opaque_up = std::make_unique<lldb_private::StringList>();
100   m_opaque_up->AppendList(strings);
101 }
102 
GetSize() const103 uint32_t SBStringList::GetSize() const {
104   LLDB_INSTRUMENT_VA(this);
105 
106   if (IsValid()) {
107     return m_opaque_up->GetSize();
108   }
109   return 0;
110 }
111 
GetStringAtIndex(size_t idx)112 const char *SBStringList::GetStringAtIndex(size_t idx) {
113   LLDB_INSTRUMENT_VA(this, idx);
114 
115   if (IsValid()) {
116     return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString();
117   }
118   return nullptr;
119 }
120 
GetStringAtIndex(size_t idx) const121 const char *SBStringList::GetStringAtIndex(size_t idx) const {
122   LLDB_INSTRUMENT_VA(this, idx);
123 
124   if (IsValid()) {
125     return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString();
126   }
127   return nullptr;
128 }
129 
Clear()130 void SBStringList::Clear() {
131   LLDB_INSTRUMENT_VA(this);
132 
133   if (IsValid()) {
134     m_opaque_up->Clear();
135   }
136 }
137