blob: 129d2f4c11f003c585be1ff16b160748e115a056 [file] [log] [blame]
Chris Lattner24943d22010-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
12#include "lldb/Core/StringList.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
17SBStringList::SBStringList () :
Greg Clayton63094e02010-06-23 01:19:29 +000018 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000019{
20}
21
22SBStringList::SBStringList (const lldb_private::StringList *lldb_strings_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25 if (lldb_strings_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000026 m_opaque_ap.reset (new lldb_private::StringList (*lldb_strings_ptr));
Chris Lattner24943d22010-06-08 16:52:24 +000027}
28
29SBStringList::SBStringList (const SBStringList &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000030 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000031{
32 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000033 m_opaque_ap.reset (new lldb_private::StringList(*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000034}
35
36
Chris Lattner24943d22010-06-08 16:52:24 +000037const SBStringList &
38SBStringList::operator = (const SBStringList &rhs)
39{
Greg Clayton538eb822010-11-05 23:17:00 +000040 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 Lattner24943d22010-06-08 16:52:24 +000047 return *this;
48}
49
Greg Clayton538eb822010-11-05 23:17:00 +000050SBStringList::~SBStringList ()
51{
52}
53
Chris Lattner24943d22010-06-08 16:52:24 +000054const lldb_private::StringList *
55SBStringList::operator->() const
56{
Greg Clayton63094e02010-06-23 01:19:29 +000057 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
60const lldb_private::StringList &
61SBStringList::operator*() const
62{
Greg Clayton63094e02010-06-23 01:19:29 +000063 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +000064}
65
66bool
67SBStringList::IsValid() const
68{
Greg Clayton63094e02010-06-23 01:19:29 +000069 return (m_opaque_ap.get() != NULL);
Chris Lattner24943d22010-06-08 16:52:24 +000070}
71
72void
73SBStringList::AppendString (const char *str)
74{
75 if (str != NULL)
76 {
77 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000078 m_opaque_ap->AppendString (str);
Chris Lattner24943d22010-06-08 16:52:24 +000079 else
Greg Clayton63094e02010-06-23 01:19:29 +000080 m_opaque_ap.reset (new lldb_private::StringList (str));
Chris Lattner24943d22010-06-08 16:52:24 +000081 }
82
83}
84
85void
86SBStringList::AppendList (const char **strv, int strc)
87{
88 if ((strv != NULL)
89 && (strc > 0))
90 {
91 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000092 m_opaque_ap->AppendList (strv, strc);
Chris Lattner24943d22010-06-08 16:52:24 +000093 else
Greg Clayton63094e02010-06-23 01:19:29 +000094 m_opaque_ap.reset (new lldb_private::StringList (strv, strc));
Chris Lattner24943d22010-06-08 16:52:24 +000095 }
96}
97
98void
Johnny Chen86ba24d2010-09-17 18:39:57 +000099SBStringList::AppendList (const SBStringList &strings)
Chris Lattner24943d22010-06-08 16:52:24 +0000100{
101 if (strings.IsValid())
102 {
103 if (! IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +0000104 m_opaque_ap.reset (new lldb_private::StringList());
105 m_opaque_ap->AppendList (*(strings.m_opaque_ap));
Chris Lattner24943d22010-06-08 16:52:24 +0000106 }
107}
108
109uint32_t
110SBStringList::GetSize () const
111{
112 if (IsValid())
113 {
Greg Clayton63094e02010-06-23 01:19:29 +0000114 return m_opaque_ap->GetSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000115 }
116 return 0;
117}
118
119const char *
120SBStringList::GetStringAtIndex (size_t idx)
121{
122 if (IsValid())
123 {
Greg Clayton63094e02010-06-23 01:19:29 +0000124 return m_opaque_ap->GetStringAtIndex (idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000125 }
126 return NULL;
127}
128
129void
130SBStringList::Clear ()
131{
132 if (IsValid())
133 {
Greg Clayton63094e02010-06-23 01:19:29 +0000134 m_opaque_ap->Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000135 }
136}