00001 // Filename: multiplexStream.I 00002 // Created by: drose (27Nov00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: MultiplexStream::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE MultiplexStream:: 00025 MultiplexStream() : ostream(&_msb) { 00026 setf(ios::unitbuf); 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: MultiplexStream::add_ostream 00031 // Access: Public 00032 // Description: Adds the indicated generic ostream to the multiplex 00033 // output. The ostream will receive whatever data is 00034 // sent to the pipe. 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE void MultiplexStream:: 00037 add_ostream(ostream *out, bool delete_later) { 00038 _msb.add_output(MultiplexStreamBuf::BT_none, 00039 MultiplexStreamBuf::OT_ostream, 00040 out, NULL, delete_later); 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: MultiplexStream::add_stdio_file 00045 // Access: Public 00046 // Description: Adds the given file, previously opened using the C 00047 // stdio library, to the multiplex output. 00048 //////////////////////////////////////////////////////////////////// 00049 INLINE bool MultiplexStream:: 00050 add_stdio_file(FILE *fout, bool close_when_done) { 00051 _msb.add_output(MultiplexStreamBuf::BT_line, 00052 MultiplexStreamBuf::OT_ostream, 00053 NULL, fout, close_when_done); 00054 return true; 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: MultiplexStream::add_standard_output 00059 // Access: Public 00060 // Description: Adds the standard output channel. 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE void MultiplexStream:: 00063 add_standard_output() { 00064 _msb.add_output(MultiplexStreamBuf::BT_none, 00065 MultiplexStreamBuf::OT_ostream, 00066 &cout, NULL, false); 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: MultiplexStream::add_file 00071 // Access: Public 00072 // Description: Adds the given file to the multiplex output. The 00073 // file is opened in append mode with line buffering. 00074 // Returns false if the file cannot be opened. 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE bool MultiplexStream:: 00077 add_file(Filename file) { 00078 file.set_text(); 00079 ofstream *out = new ofstream; 00080 if (!file.open_append(*out)) { 00081 delete out; 00082 return false; 00083 } 00084 out->setf(ios::unitbuf); 00085 00086 _msb.add_output(MultiplexStreamBuf::BT_line, 00087 MultiplexStreamBuf::OT_ostream, 00088 out, NULL, true); 00089 return true; 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: MultiplexStream::add_system_debug 00094 // Access: Public 00095 // Description: Adds the system debug output the the multiplex 00096 // output. This may map to a syslog or some such 00097 // os-specific output system. It may do nothing on a 00098 // particular system. 00099 // 00100 // Presently, this maps only to OutputDebugString() on 00101 // Windows. 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE void MultiplexStream:: 00104 add_system_debug() { 00105 _msb.add_output(MultiplexStreamBuf::BT_line, 00106 MultiplexStreamBuf::OT_system_debug); 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: MultiplexStream::flush 00111 // Access: Public 00112 // Description: Forces out all output that hasn't yet been written. 00113 //////////////////////////////////////////////////////////////////// 00114 INLINE void MultiplexStream:: 00115 flush() { 00116 _msb.flush(); 00117 }