blob: 9ac69b15ebb7912a9d1f2b9234401035b0dcadd2 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBStringList.cpp ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBStringList.h"
11
Zachary Turner573ab902017-03-21 18:25:04 +000012#include "lldb/Utility/StringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
14using namespace lldb;
15using namespace lldb_private;
16
Kate Stoneb9c1b512016-09-06 20:57:50 +000017SBStringList::SBStringList() : m_opaque_ap() {}
18
19SBStringList::SBStringList(const lldb_private::StringList *lldb_strings_ptr)
20 : m_opaque_ap() {
21 if (lldb_strings_ptr)
22 m_opaque_ap.reset(new lldb_private::StringList(*lldb_strings_ptr));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023}
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_ap() {
26 if (rhs.IsValid())
27 m_opaque_ap.reset(new lldb_private::StringList(*rhs));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028}
29
Kate Stoneb9c1b512016-09-06 20:57:50 +000030const SBStringList &SBStringList::operator=(const SBStringList &rhs) {
31 if (this != &rhs) {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032 if (rhs.IsValid())
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 m_opaque_ap.reset(new lldb_private::StringList(*rhs));
34 else
35 m_opaque_ap.reset();
36 }
37 return *this;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040SBStringList::~SBStringList() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042const lldb_private::StringList *SBStringList::operator->() const {
43 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046const lldb_private::StringList &SBStringList::operator*() const {
47 return *m_opaque_ap;
Greg Claytonefabb122010-11-05 23:17:00 +000048}
49
Kate Stoneb9c1b512016-09-06 20:57:50 +000050bool SBStringList::IsValid() const { return (m_opaque_ap.get() != NULL); }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052void SBStringList::AppendString(const char *str) {
53 if (str != NULL) {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054 if (IsValid())
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 m_opaque_ap->AppendString(str);
56 else
57 m_opaque_ap.reset(new lldb_private::StringList(str));
58 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059}
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061void SBStringList::AppendList(const char **strv, int strc) {
62 if ((strv != NULL) && (strc > 0)) {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 if (IsValid())
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 m_opaque_ap->AppendList(strv, strc);
65 else
66 m_opaque_ap.reset(new lldb_private::StringList(strv, strc));
67 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068}
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070void SBStringList::AppendList(const SBStringList &strings) {
71 if (strings.IsValid()) {
72 if (!IsValid())
73 m_opaque_ap.reset(new lldb_private::StringList());
74 m_opaque_ap->AppendList(*(strings.m_opaque_ap));
75 }
Jim Ingham76bb8d62016-04-28 01:40:57 +000076}
77
Jim Ingham92d19602016-09-20 22:54:49 +000078void SBStringList::AppendList(const StringList &strings) {
79 if (!IsValid())
80 m_opaque_ap.reset(new lldb_private::StringList());
81 m_opaque_ap->AppendList(strings);
82}
83
Kate Stoneb9c1b512016-09-06 20:57:50 +000084uint32_t SBStringList::GetSize() const {
85 if (IsValid()) {
86 return m_opaque_ap->GetSize();
87 }
88 return 0;
89}
90
91const char *SBStringList::GetStringAtIndex(size_t idx) {
92 if (IsValid()) {
93 return m_opaque_ap->GetStringAtIndex(idx);
94 }
95 return NULL;
96}
97
98const char *SBStringList::GetStringAtIndex(size_t idx) const {
99 if (IsValid()) {
100 return m_opaque_ap->GetStringAtIndex(idx);
101 }
102 return NULL;
103}
104
105void SBStringList::Clear() {
106 if (IsValid()) {
107 m_opaque_ap->Clear();
108 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109}