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