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 "Utils.h"
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 = llvm::make_unique<StringList>(*lldb_strings_ptr);
22 }
23 
24 SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_up() {
25   m_opaque_up = clone(rhs.m_opaque_up);
26 }
27 
28 const SBStringList &SBStringList::operator=(const SBStringList &rhs) {
29   if (this != &rhs)
30     m_opaque_up = clone(rhs.m_opaque_up);
31   return *this;
32 }
33 
34 SBStringList::~SBStringList() {}
35 
36 const lldb_private::StringList *SBStringList::operator->() const {
37   return m_opaque_up.get();
38 }
39 
40 const lldb_private::StringList &SBStringList::operator*() const {
41   return *m_opaque_up;
42 }
43 
44 bool SBStringList::IsValid() const { return (m_opaque_up != NULL); }
45 
46 void SBStringList::AppendString(const char *str) {
47   if (str != NULL) {
48     if (IsValid())
49       m_opaque_up->AppendString(str);
50     else
51       m_opaque_up.reset(new lldb_private::StringList(str));
52   }
53 }
54 
55 void SBStringList::AppendList(const char **strv, int strc) {
56   if ((strv != NULL) && (strc > 0)) {
57     if (IsValid())
58       m_opaque_up->AppendList(strv, strc);
59     else
60       m_opaque_up.reset(new lldb_private::StringList(strv, strc));
61   }
62 }
63 
64 void SBStringList::AppendList(const SBStringList &strings) {
65   if (strings.IsValid()) {
66     if (!IsValid())
67       m_opaque_up.reset(new lldb_private::StringList());
68     m_opaque_up->AppendList(*(strings.m_opaque_up));
69   }
70 }
71 
72 void SBStringList::AppendList(const StringList &strings) {
73   if (!IsValid())
74     m_opaque_up.reset(new lldb_private::StringList());
75   m_opaque_up->AppendList(strings);
76 }
77 
78 uint32_t SBStringList::GetSize() const {
79   if (IsValid()) {
80     return m_opaque_up->GetSize();
81   }
82   return 0;
83 }
84 
85 const char *SBStringList::GetStringAtIndex(size_t idx) {
86   if (IsValid()) {
87     return m_opaque_up->GetStringAtIndex(idx);
88   }
89   return NULL;
90 }
91 
92 const char *SBStringList::GetStringAtIndex(size_t idx) const {
93   if (IsValid()) {
94     return m_opaque_up->GetStringAtIndex(idx);
95   }
96   return NULL;
97 }
98 
99 void SBStringList::Clear() {
100   if (IsValid()) {
101     m_opaque_up->Clear();
102   }
103 }
104