Chris Lattner | 24943d2 | 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 | |
| 12 | #include "lldb/Core/StringList.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
| 17 | SBStringList::SBStringList () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 18 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | { |
| 20 | } |
| 21 | |
| 22 | SBStringList::SBStringList (const lldb_private::StringList *lldb_strings_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 23 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | { |
| 25 | if (lldb_strings_ptr) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 26 | m_opaque_ap.reset (new lldb_private::StringList (*lldb_strings_ptr)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | SBStringList::SBStringList (const SBStringList &rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 30 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
| 32 | if (rhs.IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 33 | m_opaque_ap.reset (new lldb_private::StringList(*rhs)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | const SBStringList & |
| 38 | SBStringList::operator = (const SBStringList &rhs) |
| 39 | { |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 40 | if (this != &rhs) |
| 41 | { |
| 42 | if (rhs.IsValid()) |
| 43 | m_opaque_ap.reset(new lldb_private::StringList(*rhs)); |
| 44 | else |
| 45 | m_opaque_ap.reset(); |
| 46 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | return *this; |
| 48 | } |
| 49 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 50 | SBStringList::~SBStringList () |
| 51 | { |
| 52 | } |
| 53 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | const lldb_private::StringList * |
| 55 | SBStringList::operator->() const |
| 56 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 57 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | const lldb_private::StringList & |
| 61 | SBStringList::operator*() const |
| 62 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 63 | return *m_opaque_ap; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | bool |
| 67 | SBStringList::IsValid() const |
| 68 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 69 | return (m_opaque_ap.get() != NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void |
| 73 | SBStringList::AppendString (const char *str) |
| 74 | { |
| 75 | if (str != NULL) |
| 76 | { |
| 77 | if (IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 78 | m_opaque_ap->AppendString (str); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 80 | m_opaque_ap.reset (new lldb_private::StringList (str)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | SBStringList::AppendList (const char **strv, int strc) |
| 87 | { |
| 88 | if ((strv != NULL) |
| 89 | && (strc > 0)) |
| 90 | { |
| 91 | if (IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 92 | m_opaque_ap->AppendList (strv, strc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 94 | m_opaque_ap.reset (new lldb_private::StringList (strv, strc)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | void |
Johnny Chen | 86ba24d | 2010-09-17 18:39:57 +0000 | [diff] [blame] | 99 | SBStringList::AppendList (const SBStringList &strings) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | { |
| 101 | if (strings.IsValid()) |
| 102 | { |
| 103 | if (! IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 104 | m_opaque_ap.reset (new lldb_private::StringList()); |
| 105 | m_opaque_ap->AppendList (*(strings.m_opaque_ap)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | uint32_t |
| 110 | SBStringList::GetSize () const |
| 111 | { |
| 112 | if (IsValid()) |
| 113 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 114 | return m_opaque_ap->GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | } |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | const char * |
| 120 | SBStringList::GetStringAtIndex (size_t idx) |
| 121 | { |
| 122 | if (IsValid()) |
| 123 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 124 | return m_opaque_ap->GetStringAtIndex (idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | } |
| 126 | return NULL; |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | SBStringList::Clear () |
| 131 | { |
| 132 | if (IsValid()) |
| 133 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 134 | m_opaque_ap->Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | } |
| 136 | } |