CommandReturnObject.h revision 2e8cb8a7342a2ea672792067d712a794e215a3a7
1//===-- CommandReturnObject.h -----------------------------------*- 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#ifndef liblldb_CommandReturnObject_h_
11#define liblldb_CommandReturnObject_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/lldb-private.h"
18#include "lldb/Core/STLUtils.h"
19#include "lldb/Core/StreamFile.h"
20#include "lldb/Core/StreamString.h"
21#include "lldb/Core/StreamTee.h"
22
23namespace lldb_private {
24
25
26class CommandReturnObject
27{
28public:
29
30    CommandReturnObject ();
31
32    ~CommandReturnObject ();
33
34    const char *
35    GetOutputData ()
36    {
37        if (m_output_stream_string_sp)
38            return static_cast<StreamString *>(m_output_stream_string_sp.get())->GetData();
39        else
40            return "";
41    }
42
43    const char *
44    GetErrorData ()
45    {
46        if (m_error_stream_string_sp)
47            return static_cast<StreamString *>(m_error_stream_string_sp.get())->GetData();
48        else
49            return "";
50    }
51
52    Stream &
53    GetOutputStream ()
54    {
55        if (!m_output_stream_string_sp)
56        {
57            StreamString *new_stream = new StreamString();
58            m_output_stream_string_sp.reset (new_stream);
59            m_output_stream.SetStream1 (m_output_stream_string_sp);
60        }
61        return m_output_stream;
62    }
63
64    Stream &
65    GetErrorStream ()
66    {
67        if (!m_error_stream_string_sp)
68        {
69            StreamString *new_stream = new StreamString();
70            m_error_stream_string_sp.reset (new_stream);
71            m_error_stream.SetStream1 (m_error_stream_string_sp);
72        }
73        return m_error_stream;
74    }
75
76    void
77    SetImmediateOutputFile (FILE *fh)
78    {
79        lldb::StreamSP new_stream_sp (new StreamFile (fh, false));
80        m_output_stream.SetStream2 (new_stream_sp);
81    }
82
83    void
84    SetImmediateErrorFile (FILE *fh)
85    {
86        lldb::StreamSP new_stream_sp (new StreamFile (fh, false));
87        SetImmediateOutputStream (new_stream_sp);
88    }
89
90    void
91    SetImmediateOutputStream (lldb::StreamSP &new_stream_sp)
92    {
93        m_output_stream.SetStream2 (new_stream_sp);
94    }
95
96    void
97    SetImmediateErrorStream (lldb::StreamSP &new_stream_sp)
98    {
99        m_error_stream.SetStream2 (new_stream_sp);
100    }
101
102    lldb::StreamSP &
103    GetImmediateOutputStream ()
104    {
105        return m_output_stream.GetStream2 ();
106    }
107
108    lldb::StreamSP &
109    GetImmediateErrorStream ()
110    {
111        return m_error_stream.GetStream2 ();
112    }
113
114    void
115    Clear();
116
117    void
118    AppendMessage (const char *in_string, int len = -1);
119
120    void
121    AppendMessageWithFormat (const char *format, ...);
122
123    void
124    AppendRawWarning (const char *in_string, int len = -1);
125
126    void
127    AppendWarning (const char *in_string, int len = -1);
128
129    void
130    AppendWarningWithFormat (const char *format, ...);
131
132    void
133    AppendError (const char *in_string, int len = -1);
134
135    void
136    AppendRawError (const char *in_string, int len = -1);
137
138    void
139    AppendErrorWithFormat (const char *format, ...);
140
141    lldb::ReturnStatus
142    GetStatus();
143
144    void
145    SetStatus (lldb::ReturnStatus status);
146
147    bool
148    Succeeded ();
149
150    bool
151    HasResult ();
152
153    bool GetDidChangeProcessState ();
154
155    void SetDidChangeProcessState (bool b);
156
157private:
158    lldb::StreamSP m_output_stream_string_sp;
159    lldb::StreamSP m_error_stream_string_sp;
160    StreamTee    m_output_stream;
161    StreamTee    m_error_stream;
162
163    lldb::ReturnStatus m_status;
164    bool m_did_change_process_state;
165};
166
167} // namespace lldb_private
168
169#endif  // liblldb_CommandReturnObject_h_
170