Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/downloader/multiplexStreamBuf.h

Go to the documentation of this file.
00001 // Filename: multiplexStreamBuf.h
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 #ifndef MULTIPLEXSTREAMBUF_H
00020 #define MULTIPLEXSTREAMBUF_H
00021 
00022 #include <pandabase.h>
00023 
00024 #ifdef OLD_HAVE_IPC
00025 #include <ipc_mutex.h>
00026 #endif
00027 
00028 #include "pvector.h"
00029 #include <stdio.h>
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : MultiplexStreamBuf
00033 // Description : Used by MultiplexStream to implement an ostream that
00034 //               sends what is written to it to any number of
00035 //               additional sources, like other ostreams.
00036 ////////////////////////////////////////////////////////////////////
00037 class EXPCL_PANDAEXPRESS MultiplexStreamBuf : public streambuf {
00038 public:
00039   MultiplexStreamBuf();
00040   virtual ~MultiplexStreamBuf();
00041 
00042   enum BufferType {
00043     BT_none,
00044     BT_line,
00045   };
00046 
00047   enum OutputType {
00048     OT_ostream,
00049     OT_stdio,
00050     OT_system_debug,
00051   };
00052 
00053   void add_output(BufferType buffer_type, OutputType output_type,
00054                   ostream *out = (ostream *)NULL,
00055                   FILE *fout = (FILE *)NULL,
00056                   bool owns_obj = false);
00057 
00058   void flush();
00059 
00060 protected:
00061   virtual int overflow(int c);
00062   virtual int sync();
00063 
00064 private:
00065   void write_chars(const char *start, int length, bool flush);
00066 
00067 
00068   class Output {
00069   public:
00070     void close();
00071     void write_string(const string &str);
00072 
00073     BufferType _buffer_type;
00074     OutputType _output_type;
00075     ostream *_out;
00076     FILE *_fout;
00077     bool _owns_obj;
00078   };
00079 
00080   typedef pvector<Output> Outputs;
00081   Outputs _outputs;
00082 
00083   string _line_buffer;
00084 
00085 #ifdef OLD_HAVE_IPC
00086   mutex _lock;
00087 #endif
00088 };
00089 
00090 #include "multiplexStreamBuf.I"
00091 
00092 #endif

Generated on Fri May 2 00:36:51 2003 for Panda by doxygen1.3