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