1359575Sdim//===-- SWIG Interface for SBStream -----------------------------*- C++ -*-===//
2359575Sdim//
3359575Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4359575Sdim// See https://llvm.org/LICENSE.txt for license information.
5359575Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6359575Sdim//
7359575Sdim//===----------------------------------------------------------------------===//
8359575Sdim
9359575Sdim#include <stdio.h>
10359575Sdim
11359575Sdimnamespace lldb {
12359575Sdim
13359575Sdim%feature("docstring",
14359575Sdim"Represents a destination for streaming data output to. By default, a string
15359575Sdimstream is created.
16359575Sdim
17359575SdimFor example (from test/source-manager/TestSourceManager.py),
18359575Sdim
19359575Sdim        # Create the filespec for 'main.c'.
20359575Sdim        filespec = lldb.SBFileSpec('main.c', False)
21359575Sdim        source_mgr = self.dbg.GetSourceManager()
22359575Sdim        # Use a string stream as the destination.
23359575Sdim        stream = lldb.SBStream()
24359575Sdim        source_mgr.DisplaySourceLinesWithLineNumbers(filespec,
25359575Sdim                                                     self.line,
26359575Sdim                                                     2, # context before
27359575Sdim                                                     2, # context after
28359575Sdim                                                     '=>', # prefix for current line
29359575Sdim                                                     stream)
30359575Sdim
31359575Sdim        #    2
32359575Sdim        #    3    int main(int argc, char const *argv[]) {
33359575Sdim        # => 4        printf('Hello world.\\n'); // Set break point at this line.
34359575Sdim        #    5        return 0;
35359575Sdim        #    6    }
36359575Sdim        self.expect(stream.GetData(), 'Source code displayed correctly',
37359575Sdim                    exe=False,
38359575Sdim            patterns = ['=> %d.*Hello world' % self.line])") SBStream;
39359575Sdimclass SBStream
40359575Sdim{
41359575Sdimpublic:
42359575Sdim
43359575Sdim    SBStream ();
44359575Sdim
45359575Sdim    ~SBStream ();
46359575Sdim
47359575Sdim    bool
48359575Sdim    IsValid() const;
49359575Sdim
50359575Sdim    explicit operator bool() const;
51359575Sdim
52359575Sdim    %feature("docstring", "
53359575Sdim    If this stream is not redirected to a file, it will maintain a local
54359575Sdim    cache for the stream data which can be accessed using this accessor.") GetData;
55359575Sdim    const char *
56359575Sdim    GetData ();
57359575Sdim
58359575Sdim    %feature("docstring", "
59359575Sdim    If this stream is not redirected to a file, it will maintain a local
60359575Sdim    cache for the stream output whose length can be accessed using this
61359575Sdim    accessor.") GetSize;
62359575Sdim    size_t
63359575Sdim    GetSize();
64359575Sdim
65359575Sdim    // wrapping the variadic Printf() with a plain Print()
66359575Sdim    // because it is hard to support varargs in SWIG bridgings
67359575Sdim    %extend {
68359575Sdim        void Print (const char* str)
69359575Sdim        {
70359575Sdim            self->Printf("%s", str);
71359575Sdim        }
72359575Sdim    }
73359575Sdim
74359575Sdim    void
75359575Sdim    RedirectToFile (const char *path, bool append);
76359575Sdim
77359575Sdim    void
78359575Sdim    RedirectToFile (lldb::SBFile file);
79359575Sdim
80359575Sdim    void
81359575Sdim    RedirectToFile (lldb::FileSP file);
82359575Sdim
83359575Sdim    %extend {
84359575Sdim        %feature("autodoc", "DEPRECATED, use RedirectToFile");
85359575Sdim        void
86359575Sdim        RedirectToFileHandle (lldb::FileSP file, bool transfer_fh_ownership) {
87359575Sdim            self->RedirectToFile(file);
88359575Sdim        }
89359575Sdim    }
90359575Sdim
91359575Sdim    void
92359575Sdim    RedirectToFileDescriptor (int fd, bool transfer_fh_ownership);
93359575Sdim
94359575Sdim    %feature("docstring", "
95359575Sdim    If the stream is redirected to a file, forget about the file and if
96359575Sdim    ownership of the file was transferred to this object, close the file.
97359575Sdim    If the stream is backed by a local cache, clear this cache.") Clear;
98359575Sdim    void
99359575Sdim    Clear ();
100359575Sdim};
101359575Sdim
102359575Sdim} // namespace lldb
103