Panda3D
Loading...
Searching...
No Matches
multiplexStream.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file multiplexStream.I
10 * @author drose
11 * @date 2000-11-27
12 */
13
14/**
15 *
16 */
17INLINE MultiplexStream::
18MultiplexStream() : std::ostream(&_msb) {
19 setf(std::ios::unitbuf);
20}
21
22/**
23 * Adds the indicated generic ostream to the multiplex output. The ostream
24 * will receive whatever data is sent to the pipe.
25 */
27add_ostream(std::ostream *out, bool delete_later) {
28 _msb.add_output(MultiplexStreamBuf::BT_none,
29 MultiplexStreamBuf::OT_ostream,
30 out, nullptr, delete_later);
31}
32
33/**
34 * Adds the given file, previously opened using the C stdio library, to the
35 * multiplex output.
36 */
38add_stdio_file(FILE *fout, bool close_when_done) {
39 _msb.add_output(MultiplexStreamBuf::BT_line,
40 MultiplexStreamBuf::OT_stdio,
41 nullptr, fout, close_when_done);
42 return true;
43}
44
45/**
46 * Adds the standard output channel.
47 */
50 _msb.add_output(MultiplexStreamBuf::BT_none,
51 MultiplexStreamBuf::OT_ostream,
52 &std::cout, nullptr, false);
53}
54
55/**
56 * Adds the given file to the multiplex output. The file is opened in append
57 * mode with line buffering. Returns false if the file cannot be opened.
58 */
60add_file(Filename file) {
61 file.set_text();
62 pofstream *out = new pofstream;
63 if (!file.open_append(*out)) {
64 delete out;
65 return false;
66 }
67 out->setf(std::ios::unitbuf);
68
69 _msb.add_output(MultiplexStreamBuf::BT_line,
70 MultiplexStreamBuf::OT_ostream,
71 out, nullptr, true);
72 return true;
73}
74
75/**
76 * Adds the system debug output the the multiplex output. This may map to a
77 * syslog or some such os-specific output system. It may do nothing on a
78 * particular system.
79 *
80 * Presently, this maps only to OutputDebugString() on Windows.
81 */
84 _msb.add_output(MultiplexStreamBuf::BT_line,
85 MultiplexStreamBuf::OT_system_debug);
86}
87
88/**
89 * Forces out all output that hasn't yet been written.
90 */
92flush() {
93 _msb.flush();
94}
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
bool open_append(std::ofstream &stream) const
Opens the indicated ofstream for writing the file, if possible.
void set_text()
Indicates that the filename represents a text file.
Definition filename.I:424
void flush()
Forces out all output that hasn't yet been written.
bool add_stdio_file(FILE *file, bool close_when_done)
Adds the given file, previously opened using the C stdio library, to the multiplex output.
void add_standard_output()
Adds the standard output channel.
void add_system_debug()
Adds the system debug output the the multiplex output.
void add_ostream(std::ostream *out, bool delete_later=false)
Adds the indicated generic ostream to the multiplex output.
bool add_file(Filename file)
Adds the given file to the multiplex output.
STL class.
STL namespace.