1 //===-- SBCommandReturnObject.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/Interpreter/CommandReturnObject.h"
11 
12 #include "lldb/API/SBCommandReturnObject.h"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
17 SBCommandReturnObject::SBCommandReturnObject () :
18     m_opaque_ap (new CommandReturnObject ())
19 {
20 }
21 
22 SBCommandReturnObject::~SBCommandReturnObject ()
23 {
24     // m_opaque_ap will automatically delete any pointer it owns
25 }
26 
27 bool
28 SBCommandReturnObject::IsValid() const
29 {
30     return m_opaque_ap.get() != NULL;
31 }
32 
33 
34 const char *
35 SBCommandReturnObject::GetOutput ()
36 {
37     if (m_opaque_ap.get())
38         return m_opaque_ap->GetOutputStream().GetData();
39     return NULL;
40 }
41 
42 const char *
43 SBCommandReturnObject::GetError ()
44 {
45     if (m_opaque_ap.get())
46         return m_opaque_ap->GetErrorStream().GetData();
47     return NULL;
48 }
49 
50 size_t
51 SBCommandReturnObject::GetOutputSize ()
52 {
53     if (m_opaque_ap.get())
54         return m_opaque_ap->GetOutputStream().GetSize();
55     return 0;
56 }
57 
58 size_t
59 SBCommandReturnObject::GetErrorSize ()
60 {
61     if (m_opaque_ap.get())
62         return m_opaque_ap->GetErrorStream().GetSize();
63     return 0;
64 }
65 
66 size_t
67 SBCommandReturnObject::PutOutput (FILE *fh)
68 {
69     if (fh)
70     {
71         size_t num_bytes = GetOutputSize ();
72         if (num_bytes)
73             return ::fprintf (fh, "%s", GetOutput());
74     }
75     return 0;
76 }
77 
78 size_t
79 SBCommandReturnObject::PutError (FILE *fh)
80 {
81     if (fh)
82     {
83         size_t num_bytes = GetErrorSize ();
84         if (num_bytes)
85             return ::fprintf (fh, "%s", GetError());
86     }
87     return 0;
88 }
89 
90 void
91 SBCommandReturnObject::Clear()
92 {
93     if (m_opaque_ap.get())
94         m_opaque_ap->Clear();
95 }
96 
97 lldb::ReturnStatus
98 SBCommandReturnObject::GetStatus()
99 {
100     if (m_opaque_ap.get())
101         return m_opaque_ap->GetStatus();
102     return lldb::eReturnStatusInvalid;
103 }
104 
105 bool
106 SBCommandReturnObject::Succeeded ()
107 {
108     if (m_opaque_ap.get())
109         return m_opaque_ap->Succeeded();
110     return false;
111 }
112 
113 bool
114 SBCommandReturnObject::HasResult ()
115 {
116     if (m_opaque_ap.get())
117         return m_opaque_ap->HasResult();
118     return false;
119 }
120 
121 void
122 SBCommandReturnObject::AppendMessage (const char *message)
123 {
124     if (m_opaque_ap.get())
125         m_opaque_ap->AppendMessage (message);
126 }
127 
128 CommandReturnObject *
129 SBCommandReturnObject::operator ->() const
130 {
131     return m_opaque_ap.get();
132 }
133 
134 CommandReturnObject *
135 SBCommandReturnObject::get() const
136 {
137     return m_opaque_ap.get();
138 }
139 
140 CommandReturnObject &
141 SBCommandReturnObject::operator *() const
142 {
143     assert(m_opaque_ap.get());
144     return *(m_opaque_ap.get());
145 }
146 
147 
148 CommandReturnObject &
149 SBCommandReturnObject::ref() const
150 {
151     assert(m_opaque_ap.get());
152     return *(m_opaque_ap.get());
153 }
154 
155 
156 void
157 SBCommandReturnObject::SetLLDBObjectPtr (CommandReturnObject *ptr)
158 {
159     if (m_opaque_ap.get())
160         m_opaque_ap.reset (ptr);
161 }
162 
163