Panda3D
 All Classes Functions Variables Enumerations
multiplexStream.I
1 // Filename: multiplexStream.I
2 // Created by: drose (27Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: MultiplexStream::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE MultiplexStream::
21 MultiplexStream() : ostream(&_msb) {
22  setf(ios::unitbuf);
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: MultiplexStream::add_ostream
27 // Access: Public
28 // Description: Adds the indicated generic ostream to the multiplex
29 // output. The ostream will receive whatever data is
30 // sent to the pipe.
31 ////////////////////////////////////////////////////////////////////
32 INLINE void MultiplexStream::
33 add_ostream(ostream *out, bool delete_later) {
34  _msb.add_output(MultiplexStreamBuf::BT_none,
35  MultiplexStreamBuf::OT_ostream,
36  out, NULL, delete_later);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: MultiplexStream::add_stdio_file
41 // Access: Public
42 // Description: Adds the given file, previously opened using the C
43 // stdio library, to the multiplex output.
44 ////////////////////////////////////////////////////////////////////
45 INLINE bool MultiplexStream::
46 add_stdio_file(FILE *fout, bool close_when_done) {
47  _msb.add_output(MultiplexStreamBuf::BT_line,
48  MultiplexStreamBuf::OT_ostream,
49  NULL, fout, close_when_done);
50  return true;
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: MultiplexStream::add_standard_output
55 // Access: Public
56 // Description: Adds the standard output channel.
57 ////////////////////////////////////////////////////////////////////
58 INLINE void MultiplexStream::
60  _msb.add_output(MultiplexStreamBuf::BT_none,
61  MultiplexStreamBuf::OT_ostream,
62  &cout, NULL, false);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: MultiplexStream::add_file
67 // Access: Public
68 // Description: Adds the given file to the multiplex output. The
69 // file is opened in append mode with line buffering.
70 // Returns false if the file cannot be opened.
71 ////////////////////////////////////////////////////////////////////
72 INLINE bool MultiplexStream::
74  file.set_text();
75  pofstream *out = new pofstream;
76  if (!file.open_append(*out)) {
77  delete out;
78  return false;
79  }
80  out->setf(ios::unitbuf);
81 
82  _msb.add_output(MultiplexStreamBuf::BT_line,
83  MultiplexStreamBuf::OT_ostream,
84  out, NULL, true);
85  return true;
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: MultiplexStream::add_system_debug
90 // Access: Public
91 // Description: Adds the system debug output the the multiplex
92 // output. This may map to a syslog or some such
93 // os-specific output system. It may do nothing on a
94 // particular system.
95 //
96 // Presently, this maps only to OutputDebugString() on
97 // Windows.
98 ////////////////////////////////////////////////////////////////////
99 INLINE void MultiplexStream::
101  _msb.add_output(MultiplexStreamBuf::BT_line,
102  MultiplexStreamBuf::OT_system_debug);
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: MultiplexStream::flush
107 // Access: Public
108 // Description: Forces out all output that hasn't yet been written.
109 ////////////////////////////////////////////////////////////////////
110 INLINE void MultiplexStream::
111 flush() {
112  _msb.flush();
113 }
bool open_append(ofstream &stream) const
Opens the indicated ofstream for writing the file, if possible.
Definition: filename.cxx:2101
void set_text()
Indicates that the filename represents a text file.
Definition: filename.I:507
void flush()
Forces out all output that hasn't yet been written.
void flush()
Forces out all output that hasn't yet been written.
bool add_file(Filename file)
Adds the given file to the multiplex output.
void add_ostream(ostream *out, bool delete_later=false)
Adds the indicated generic ostream to the multiplex output.
void add_output(BufferType buffer_type, OutputType output_type, ostream *out=(ostream *) NULL, FILE *fout=(FILE *) NULL, bool owns_obj=false)
Adds the indicated output destinition to the set of things that will be written to when characters ar...
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:44
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...