/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/API/SBStringList.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 1.71k | SBStringList::SBStringList() { LLDB_INSTRUMENT_VA(this); } |
18 | | |
19 | 653 | SBStringList::SBStringList(const lldb_private::StringList *lldb_strings_ptr) { |
20 | 653 | if (lldb_strings_ptr) |
21 | 653 | m_opaque_up = std::make_unique<StringList>(*lldb_strings_ptr); |
22 | 653 | } |
23 | | |
24 | 11 | SBStringList::SBStringList(const SBStringList &rhs) { |
25 | 11 | LLDB_INSTRUMENT_VA(this, rhs); |
26 | | |
27 | 11 | m_opaque_up = clone(rhs.m_opaque_up); |
28 | 11 | } |
29 | | |
30 | 11 | const SBStringList &SBStringList::operator=(const SBStringList &rhs) { |
31 | 11 | LLDB_INSTRUMENT_VA(this, rhs); |
32 | | |
33 | 11 | if (this != &rhs) |
34 | 11 | m_opaque_up = clone(rhs.m_opaque_up); |
35 | 11 | return *this; |
36 | 11 | } |
37 | | |
38 | 2.37k | SBStringList::~SBStringList() = default; |
39 | | |
40 | 4 | lldb_private::StringList *SBStringList::operator->() { |
41 | 4 | if (!IsValid()) |
42 | 2 | m_opaque_up = std::make_unique<lldb_private::StringList>(); |
43 | | |
44 | 4 | return m_opaque_up.get(); |
45 | 4 | } |
46 | | |
47 | 0 | const lldb_private::StringList *SBStringList::operator->() const { |
48 | 0 | return m_opaque_up.get(); |
49 | 0 | } |
50 | | |
51 | 9 | const lldb_private::StringList &SBStringList::operator*() const { |
52 | 9 | return *m_opaque_up; |
53 | 9 | } |
54 | | |
55 | 12.0k | bool SBStringList::IsValid() const { |
56 | 12.0k | LLDB_INSTRUMENT_VA(this); |
57 | 12.0k | return this->operator bool(); |
58 | 12.0k | } |
59 | 12.0k | SBStringList::operator bool() const { |
60 | 12.0k | LLDB_INSTRUMENT_VA(this); |
61 | | |
62 | 12.0k | return (m_opaque_up != nullptr); |
63 | 12.0k | } |
64 | | |
65 | 59 | void SBStringList::AppendString(const char *str) { |
66 | 59 | LLDB_INSTRUMENT_VA(this, str); |
67 | | |
68 | 59 | if (str != nullptr) { |
69 | 58 | if (IsValid()) |
70 | 30 | m_opaque_up->AppendString(str); |
71 | 28 | else |
72 | 28 | m_opaque_up = std::make_unique<lldb_private::StringList>(str); |
73 | 58 | } |
74 | 59 | } |
75 | | |
76 | 7 | void SBStringList::AppendList(const char **strv, int strc) { |
77 | 7 | LLDB_INSTRUMENT_VA(this, strv, strc); |
78 | | |
79 | 7 | if ((strv != nullptr) && (strc > 0)6 ) { |
80 | 6 | if (IsValid()) |
81 | 1 | m_opaque_up->AppendList(strv, strc); |
82 | 5 | else |
83 | 5 | m_opaque_up = std::make_unique<lldb_private::StringList>(strv, strc); |
84 | 6 | } |
85 | 7 | } |
86 | | |
87 | 651 | void SBStringList::AppendList(const SBStringList &strings) { |
88 | 651 | LLDB_INSTRUMENT_VA(this, strings); |
89 | | |
90 | 651 | if (strings.IsValid()) { |
91 | 650 | if (!IsValid()) |
92 | 650 | m_opaque_up = std::make_unique<lldb_private::StringList>(); |
93 | 650 | m_opaque_up->AppendList(*(strings.m_opaque_up)); |
94 | 650 | } |
95 | 651 | } |
96 | | |
97 | 12 | void SBStringList::AppendList(const StringList &strings) { |
98 | 12 | if (!IsValid()) |
99 | 12 | m_opaque_up = std::make_unique<lldb_private::StringList>(); |
100 | 12 | m_opaque_up->AppendList(strings); |
101 | 12 | } |
102 | | |
103 | 1.65k | uint32_t SBStringList::GetSize() const { |
104 | 1.65k | LLDB_INSTRUMENT_VA(this); |
105 | | |
106 | 1.65k | if (IsValid()) { |
107 | 658 | return m_opaque_up->GetSize(); |
108 | 658 | } |
109 | 1.00k | return 0; |
110 | 1.65k | } |
111 | | |
112 | 8.94k | const char *SBStringList::GetStringAtIndex(size_t idx) { |
113 | 8.94k | LLDB_INSTRUMENT_VA(this, idx); |
114 | | |
115 | 8.94k | if (IsValid()) { |
116 | 8.94k | return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString(); |
117 | 8.94k | } |
118 | 0 | return nullptr; |
119 | 8.94k | } |
120 | | |
121 | 10 | const char *SBStringList::GetStringAtIndex(size_t idx) const { |
122 | 10 | LLDB_INSTRUMENT_VA(this, idx); |
123 | | |
124 | 10 | if (IsValid()) { |
125 | 10 | return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString(); |
126 | 10 | } |
127 | 0 | return nullptr; |
128 | 10 | } |
129 | | |
130 | 11 | void SBStringList::Clear() { |
131 | 11 | LLDB_INSTRUMENT_VA(this); |
132 | | |
133 | 11 | if (IsValid()) { |
134 | 8 | m_opaque_up->Clear(); |
135 | 8 | } |
136 | 11 | } |