Panda3D
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  */
17 INLINE MultiplexStream::
18 MultiplexStream() : 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  */
26 INLINE void MultiplexStream::
27 add_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  */
37 INLINE bool MultiplexStream::
38 add_stdio_file(FILE *fout, bool close_when_done) {
39  _msb.add_output(MultiplexStreamBuf::BT_line,
40  MultiplexStreamBuf::OT_ostream,
41  nullptr, fout, close_when_done);
42  return true;
43 }
44 
45 /**
46  * Adds the standard output channel.
47  */
48 INLINE void MultiplexStream::
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  */
59 INLINE bool MultiplexStream::
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  */
82 INLINE void MultiplexStream::
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  */
91 INLINE void MultiplexStream::
92 flush() {
93  _msb.flush();
94 }
void add_ostream(std::ostream *out, bool delete_later=false)
Adds the indicated generic ostream to the multiplex output.
bool open_append(std::ofstream &stream) const
Opens the indicated ofstream for writing the file, if possible.
Definition: filename.cxx:1945
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.
void flush()
Forces out all output that hasn't yet been written.
void add_output(BufferType buffer_type, OutputType output_type, std::ostream *out=nullptr, FILE *fout=nullptr, bool owns_obj=false)
Adds the indicated output destinition to the set of things that will be written to when characters ar...
bool add_file(Filename file)
Adds the given file to the multiplex output.
void add_system_debug()
Adds the system debug output the the multiplex output.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
void add_standard_output()
Adds the standard output channel.
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.