1ac7ddfbfSEd Maste //===-- SBStringList.cpp ----------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/API/SBStringList.h"
11ac7ddfbfSEd Maste 
12f678e45dSDimitry Andric #include "lldb/Utility/StringList.h"
13ac7ddfbfSEd Maste 
14ac7ddfbfSEd Maste using namespace lldb;
15ac7ddfbfSEd Maste using namespace lldb_private;
16ac7ddfbfSEd Maste 
SBStringList()17435933ddSDimitry Andric SBStringList::SBStringList() : m_opaque_ap() {}
18ac7ddfbfSEd Maste 
SBStringList(const lldb_private::StringList * lldb_strings_ptr)19435933ddSDimitry Andric SBStringList::SBStringList(const lldb_private::StringList *lldb_strings_ptr)
20435933ddSDimitry Andric     : m_opaque_ap() {
21ac7ddfbfSEd Maste   if (lldb_strings_ptr)
22ac7ddfbfSEd Maste     m_opaque_ap.reset(new lldb_private::StringList(*lldb_strings_ptr));
23ac7ddfbfSEd Maste }
24ac7ddfbfSEd Maste 
SBStringList(const SBStringList & rhs)25435933ddSDimitry Andric SBStringList::SBStringList(const SBStringList &rhs) : m_opaque_ap() {
26ac7ddfbfSEd Maste   if (rhs.IsValid())
27ac7ddfbfSEd Maste     m_opaque_ap.reset(new lldb_private::StringList(*rhs));
28ac7ddfbfSEd Maste }
29ac7ddfbfSEd Maste 
operator =(const SBStringList & rhs)30435933ddSDimitry Andric const SBStringList &SBStringList::operator=(const SBStringList &rhs) {
31435933ddSDimitry Andric   if (this != &rhs) {
32ac7ddfbfSEd Maste     if (rhs.IsValid())
33ac7ddfbfSEd Maste       m_opaque_ap.reset(new lldb_private::StringList(*rhs));
34ac7ddfbfSEd Maste     else
35ac7ddfbfSEd Maste       m_opaque_ap.reset();
36ac7ddfbfSEd Maste   }
37ac7ddfbfSEd Maste   return *this;
38ac7ddfbfSEd Maste }
39ac7ddfbfSEd Maste 
~SBStringList()40435933ddSDimitry Andric SBStringList::~SBStringList() {}
41ac7ddfbfSEd Maste 
operator ->() const42435933ddSDimitry Andric const lldb_private::StringList *SBStringList::operator->() const {
43ac7ddfbfSEd Maste   return m_opaque_ap.get();
44ac7ddfbfSEd Maste }
45ac7ddfbfSEd Maste 
operator *() const46435933ddSDimitry Andric const lldb_private::StringList &SBStringList::operator*() const {
47ac7ddfbfSEd Maste   return *m_opaque_ap;
48ac7ddfbfSEd Maste }
49ac7ddfbfSEd Maste 
IsValid() const50*b5893f02SDimitry Andric bool SBStringList::IsValid() const { return (m_opaque_ap != NULL); }
51ac7ddfbfSEd Maste 
AppendString(const char * str)52435933ddSDimitry Andric void SBStringList::AppendString(const char *str) {
53435933ddSDimitry Andric   if (str != NULL) {
54ac7ddfbfSEd Maste     if (IsValid())
55ac7ddfbfSEd Maste       m_opaque_ap->AppendString(str);
56ac7ddfbfSEd Maste     else
57ac7ddfbfSEd Maste       m_opaque_ap.reset(new lldb_private::StringList(str));
58ac7ddfbfSEd Maste   }
59ac7ddfbfSEd Maste }
60ac7ddfbfSEd Maste 
AppendList(const char ** strv,int strc)61435933ddSDimitry Andric void SBStringList::AppendList(const char **strv, int strc) {
62435933ddSDimitry Andric   if ((strv != NULL) && (strc > 0)) {
63ac7ddfbfSEd Maste     if (IsValid())
64ac7ddfbfSEd Maste       m_opaque_ap->AppendList(strv, strc);
65ac7ddfbfSEd Maste     else
66ac7ddfbfSEd Maste       m_opaque_ap.reset(new lldb_private::StringList(strv, strc));
67ac7ddfbfSEd Maste   }
68ac7ddfbfSEd Maste }
69ac7ddfbfSEd Maste 
AppendList(const SBStringList & strings)70435933ddSDimitry Andric void SBStringList::AppendList(const SBStringList &strings) {
71435933ddSDimitry Andric   if (strings.IsValid()) {
72ac7ddfbfSEd Maste     if (!IsValid())
73ac7ddfbfSEd Maste       m_opaque_ap.reset(new lldb_private::StringList());
74ac7ddfbfSEd Maste     m_opaque_ap->AppendList(*(strings.m_opaque_ap));
75ac7ddfbfSEd Maste   }
76ac7ddfbfSEd Maste }
77ac7ddfbfSEd Maste 
AppendList(const StringList & strings)78435933ddSDimitry Andric void SBStringList::AppendList(const StringList &strings) {
79435933ddSDimitry Andric   if (!IsValid())
80435933ddSDimitry Andric     m_opaque_ap.reset(new lldb_private::StringList());
81435933ddSDimitry Andric   m_opaque_ap->AppendList(strings);
82435933ddSDimitry Andric }
83435933ddSDimitry Andric 
GetSize() const84435933ddSDimitry Andric uint32_t SBStringList::GetSize() const {
85435933ddSDimitry Andric   if (IsValid()) {
86ac7ddfbfSEd Maste     return m_opaque_ap->GetSize();
87ac7ddfbfSEd Maste   }
88ac7ddfbfSEd Maste   return 0;
89ac7ddfbfSEd Maste }
90ac7ddfbfSEd Maste 
GetStringAtIndex(size_t idx)91435933ddSDimitry Andric const char *SBStringList::GetStringAtIndex(size_t idx) {
92435933ddSDimitry Andric   if (IsValid()) {
93ac7ddfbfSEd Maste     return m_opaque_ap->GetStringAtIndex(idx);
94ac7ddfbfSEd Maste   }
95ac7ddfbfSEd Maste   return NULL;
96ac7ddfbfSEd Maste }
97ac7ddfbfSEd Maste 
GetStringAtIndex(size_t idx) const98435933ddSDimitry Andric const char *SBStringList::GetStringAtIndex(size_t idx) const {
99435933ddSDimitry Andric   if (IsValid()) {
1004bb0738eSEd Maste     return m_opaque_ap->GetStringAtIndex(idx);
1014bb0738eSEd Maste   }
1024bb0738eSEd Maste   return NULL;
1034bb0738eSEd Maste }
1044bb0738eSEd Maste 
Clear()105435933ddSDimitry Andric void SBStringList::Clear() {
106435933ddSDimitry Andric   if (IsValid()) {
107ac7ddfbfSEd Maste     m_opaque_ap->Clear();
108ac7ddfbfSEd Maste   }
109ac7ddfbfSEd Maste }
110