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

pfstreamBuf.h

Go to the documentation of this file.
00001 // Filename: pfstreamBuf.h
00002 // Created by:  cary (12Dec00)
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 __PFSTREAMBUF_H__
00020 #define __PFSTREAMBUF_H__
00021 
00022 #include <dtoolbase.h>
00023 #include <string>
00024 #include <stdio.h>
00025 
00026 // By default, we'll use the Windows flavor of pipe functions if we're
00027 // compiling under Windows.  Turn this off to use popen(), even on
00028 // Windows.  (popen() doesn't seem to work on Win9x, although it does
00029 // work on NT-based variants.)
00030 #ifdef WIN32_VC
00031 #define WIN_PIPE_CALLS 1
00032 #endif
00033 
00034 #ifdef WIN_PIPE_CALLS
00035 #include <windows.h>
00036 
00037 #else  // WIN_PIPE_CALLS
00038 
00039 #ifdef WIN32_VC
00040 #define popen _popen
00041 #define pclose _pclose
00042 #endif
00043 
00044 #endif // WIN_PIPE_CALLS
00045 
00046 class EXPCL_DTOOL PipeStreamBuf : public streambuf {
00047 public:
00048   enum Direction { Input, Output };
00049 
00050   PipeStreamBuf(Direction);
00051   virtual ~PipeStreamBuf(void);
00052 
00053   void flush();
00054   void command(const string);
00055 
00056 protected:
00057   virtual int overflow(int c);
00058   virtual int sync(void);
00059   virtual int underflow(void);
00060 private:
00061   void init_pipe();
00062   bool is_open() const;
00063   bool eof_pipe() const;
00064   bool open_pipe(const string &cmd);
00065   void close_pipe();
00066   size_t write_pipe(const char *data, size_t len);
00067   size_t read_pipe(char *data, size_t len);
00068 
00069   Direction _dir;
00070   string _line_buffer;
00071 
00072 #ifndef WIN_PIPE_CALLS
00073   FILE *_pipe;
00074 
00075 #else  // WIN_PIPE_CALLS
00076   HANDLE _child_out;
00077 #endif  // WIN_PIPE_CALLS
00078 
00079   void write_chars(const char*, int, bool);
00080 };
00081 
00082 #endif /* __PFSTREAMBUF_H__ */

Generated on Fri Apr 18 01:33:58 2003 for DTool by doxygen1.3