00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00025
00026
00027
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