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