Panda3D
 All Classes Functions Variables Enumerations
multiplexStreamBuf.h
1 // Filename: multiplexStreamBuf.h
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 #ifndef MULTIPLEXSTREAMBUF_H
16 #define MULTIPLEXSTREAMBUF_H
17 
18 #include "pandabase.h"
19 
20 #include "pvector.h"
21 #include <stdio.h>
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : MultiplexStreamBuf
25 // Description : Used by MultiplexStream to implement an ostream that
26 // sends what is written to it to any number of
27 // additional sources, like other ostreams.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDAEXPRESS MultiplexStreamBuf : public streambuf {
30 public:
32  virtual ~MultiplexStreamBuf();
33 
34  enum BufferType {
35  BT_none,
36  BT_line,
37  };
38 
39  enum OutputType {
40  OT_ostream,
41  OT_stdio,
42  OT_system_debug,
43  };
44 
45  void add_output(BufferType buffer_type, OutputType output_type,
46  ostream *out = (ostream *)NULL,
47  FILE *fout = (FILE *)NULL,
48  bool owns_obj = false);
49 
50  void flush();
51 
52 protected:
53  virtual int overflow(int c);
54  virtual int sync();
55 
56 private:
57  void write_chars(const char *start, int length, bool flush);
58 
59 
60  class Output {
61  public:
62  void close();
63  void write_string(const string &str);
64 
65  BufferType _buffer_type;
66  OutputType _output_type;
67  ostream *_out;
68  FILE *_fout;
69  bool _owns_obj;
70  };
71 
72  typedef pvector<Output> Outputs;
73  Outputs _outputs;
74 
75  string _line_buffer;
76 };
77 
78 #include "multiplexStreamBuf.I"
79 
80 #endif
Used by MultiplexStream to implement an ostream that sends what is written to it to any number of add...