SBStream.h revision 49306144bb37f0b3423d992f17cdcc24703374b4
1//===-- SBStream.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 LLDB_SBStream_h_
11#define LLDB_SBStream_h_
12
13#include <stdio.h>
14
15#include "lldb/API/SBDefines.h"
16
17namespace lldb {
18
19class SBStream
20{
21public:
22
23    SBStream ();
24
25    ~SBStream ();
26
27    bool
28    IsValid() const;
29
30    // If this stream is not redirected to a file, it will maintain a local
31    // cache for the stream data which can be accessed using this accessor.
32    const char *
33    GetData ();
34
35    // If this stream is not redirected to a file, it will maintain a local
36    // cache for the stream output whose length can be accessed using this
37    // accessor.
38    size_t
39    GetSize();
40
41    void
42    Printf (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
43
44    void
45    RedirectToFile (const char *path, bool append);
46
47    void
48    RedirectToFileHandle (FILE *fh, bool transfer_fh_ownership);
49
50    void
51    RedirectToFileDescriptor (int fd, bool transfer_fh_ownership);
52
53    // If the stream is redirected to a file, forget about the file and if
54    // ownership of the file was transfered to this object, close the file.
55    // If the stream is backed by a local cache, clear this cache.
56    void
57    Clear ();
58
59protected:
60    friend class SBAddress;
61    friend class SBBlock;
62    friend class SBBreakpoint;
63    friend class SBBreakpointLocation;
64    friend class SBCommandReturnObject;
65    friend class SBCompileUnit;
66    friend class SBData;
67    friend class SBDebugger;
68    friend class SBDeclaration;
69    friend class SBEvent;
70    friend class SBFileSpec;
71    friend class SBFileSpecList;
72    friend class SBFrame;
73    friend class SBFunction;
74    friend class SBInstruction;
75    friend class SBInstructionList;
76    friend class SBLineEntry;
77    friend class SBModule;
78    friend class SBProcess;
79    friend class SBSection;
80    friend class SBSourceManager;
81    friend class SBSymbol;
82    friend class SBSymbolContext;
83    friend class SBSymbolContextList;
84    friend class SBTarget;
85    friend class SBThread;
86    friend class SBType;
87    friend class SBTypeMember;
88    friend class SBValue;
89    friend class SBWatchpoint;
90
91    lldb_private::Stream *
92    operator->();
93
94    lldb_private::Stream *
95    get();
96
97    lldb_private::Stream &
98    ref();
99
100private:
101
102    DISALLOW_COPY_AND_ASSIGN (SBStream);
103    std::auto_ptr<lldb_private::Stream> m_opaque_ap;
104    bool m_is_file;
105};
106
107} // namespace lldb
108
109#endif // LLDB_SBStream_h_
110