Panda3D
|
00001 // Filename: multiplexStreamBuf.h 00002 // Created by: drose (27Nov00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef MULTIPLEXSTREAMBUF_H 00016 #define MULTIPLEXSTREAMBUF_H 00017 00018 #include "pandabase.h" 00019 00020 #include "pvector.h" 00021 #include <stdio.h> 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : MultiplexStreamBuf 00025 // Description : Used by MultiplexStream to implement an ostream that 00026 // sends what is written to it to any number of 00027 // additional sources, like other ostreams. 00028 //////////////////////////////////////////////////////////////////// 00029 class EXPCL_PANDAEXPRESS MultiplexStreamBuf : public streambuf { 00030 public: 00031 MultiplexStreamBuf(); 00032 virtual ~MultiplexStreamBuf(); 00033 00034 enum BufferType { 00035 BT_none, 00036 BT_line, 00037 }; 00038 00039 enum OutputType { 00040 OT_ostream, 00041 OT_stdio, 00042 OT_system_debug, 00043 }; 00044 00045 void add_output(BufferType buffer_type, OutputType output_type, 00046 ostream *out = (ostream *)NULL, 00047 FILE *fout = (FILE *)NULL, 00048 bool owns_obj = false); 00049 00050 void flush(); 00051 00052 protected: 00053 virtual int overflow(int c); 00054 virtual int sync(); 00055 00056 private: 00057 void write_chars(const char *start, int length, bool flush); 00058 00059 00060 class Output { 00061 public: 00062 void close(); 00063 void write_string(const string &str); 00064 00065 BufferType _buffer_type; 00066 OutputType _output_type; 00067 ostream *_out; 00068 FILE *_fout; 00069 bool _owns_obj; 00070 }; 00071 00072 typedef pvector<Output> Outputs; 00073 Outputs _outputs; 00074 00075 string _line_buffer; 00076 }; 00077 00078 #include "multiplexStreamBuf.I" 00079 00080 #endif