Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Turner | 573ab90 | 2017-03-21 18:25:04 +0000 | [diff] [blame] | 12 | #include "lldb/Utility/StringList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 17 | SBStringList::SBStringList() : m_opaque_ap() {} |
| 18 | |
| 19 | SBStringList::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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_ap() { |
| 26 | if (rhs.IsValid()) |
| 27 | m_opaque_ap.reset(new lldb_private::StringList(*rhs)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | const SBStringList &SBStringList::operator=(const SBStringList &rhs) { |
| 31 | if (this != &rhs) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | if (rhs.IsValid()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | m_opaque_ap.reset(new lldb_private::StringList(*rhs)); |
| 34 | else |
| 35 | m_opaque_ap.reset(); |
| 36 | } |
| 37 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | SBStringList::~SBStringList() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | const lldb_private::StringList *SBStringList::operator->() const { |
| 43 | return m_opaque_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | const lldb_private::StringList &SBStringList::operator*() const { |
| 47 | return *m_opaque_ap; |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | bool SBStringList::IsValid() const { return (m_opaque_ap.get() != NULL); } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | void SBStringList::AppendString(const char *str) { |
| 53 | if (str != NULL) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | if (IsValid()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | m_opaque_ap->AppendString(str); |
| 56 | else |
| 57 | m_opaque_ap.reset(new lldb_private::StringList(str)); |
| 58 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | void SBStringList::AppendList(const char **strv, int strc) { |
| 62 | if ((strv != NULL) && (strc > 0)) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | if (IsValid()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | m_opaque_ap->AppendList(strv, strc); |
| 65 | else |
| 66 | m_opaque_ap.reset(new lldb_private::StringList(strv, strc)); |
| 67 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | void 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 Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 78 | void 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 Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | uint32_t SBStringList::GetSize() const { |
| 85 | if (IsValid()) { |
| 86 | return m_opaque_ap->GetSize(); |
| 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | const char *SBStringList::GetStringAtIndex(size_t idx) { |
| 92 | if (IsValid()) { |
| 93 | return m_opaque_ap->GetStringAtIndex(idx); |
| 94 | } |
| 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | const char *SBStringList::GetStringAtIndex(size_t idx) const { |
| 99 | if (IsValid()) { |
| 100 | return m_opaque_ap->GetStringAtIndex(idx); |
| 101 | } |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | void SBStringList::Clear() { |
| 106 | if (IsValid()) { |
| 107 | m_opaque_ap->Clear(); |
| 108 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | } |