[RISCV] Reduce redundancy in vnsrl tests
[llvm-project.git] / lldb / source / API / SBStringList.cpp
blob350c58b61634c3be669a7e9c74433b359694505d
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 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBStringList.h"
10 #include "Utils.h"
11 #include "lldb/Utility/Instrumentation.h"
12 #include "lldb/Utility/StringList.h"
14 using namespace lldb;
15 using namespace lldb_private;
17 SBStringList::SBStringList() { LLDB_INSTRUMENT_VA(this); }
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);
24 SBStringList::SBStringList(const SBStringList &rhs) {
25 LLDB_INSTRUMENT_VA(this, rhs);
27 m_opaque_up = clone(rhs.m_opaque_up);
30 const SBStringList &SBStringList::operator=(const SBStringList &rhs) {
31 LLDB_INSTRUMENT_VA(this, rhs);
33 if (this != &rhs)
34 m_opaque_up = clone(rhs.m_opaque_up);
35 return *this;
38 SBStringList::~SBStringList() = default;
40 lldb_private::StringList *SBStringList::operator->() {
41 if (!IsValid())
42 m_opaque_up = std::make_unique<lldb_private::StringList>();
44 return m_opaque_up.get();
47 const lldb_private::StringList *SBStringList::operator->() const {
48 return m_opaque_up.get();
51 const lldb_private::StringList &SBStringList::operator*() const {
52 return *m_opaque_up;
55 bool SBStringList::IsValid() const {
56 LLDB_INSTRUMENT_VA(this);
57 return this->operator bool();
59 SBStringList::operator bool() const {
60 LLDB_INSTRUMENT_VA(this);
62 return (m_opaque_up != nullptr);
65 void SBStringList::AppendString(const char *str) {
66 LLDB_INSTRUMENT_VA(this, str);
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);
76 void SBStringList::AppendList(const char **strv, int strc) {
77 LLDB_INSTRUMENT_VA(this, strv, strc);
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);
87 void SBStringList::AppendList(const SBStringList &strings) {
88 LLDB_INSTRUMENT_VA(this, strings);
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));
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);
103 uint32_t SBStringList::GetSize() const {
104 LLDB_INSTRUMENT_VA(this);
106 if (IsValid()) {
107 return m_opaque_up->GetSize();
109 return 0;
112 const char *SBStringList::GetStringAtIndex(size_t idx) {
113 LLDB_INSTRUMENT_VA(this, idx);
115 if (IsValid()) {
116 return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString();
118 return nullptr;
121 const char *SBStringList::GetStringAtIndex(size_t idx) const {
122 LLDB_INSTRUMENT_VA(this, idx);
124 if (IsValid()) {
125 return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString();
127 return nullptr;
130 void SBStringList::Clear() {
131 LLDB_INSTRUMENT_VA(this);
133 if (IsValid()) {
134 m_opaque_up->Clear();