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

WinGUIostream.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/gui/src/WinGUIostream.cxx,v 1.2 2001/01/29 06:12:44 burnett Exp $
00002 
00003 #ifdef WIN32  // stupid to prevent compilation on unix platforms 
00004 
00005 #include "WinGUI.h"
00006 #include "winGUIostream.h"
00007 #include "resource.h"
00008 #include <errno.h>
00009 #include <iostream>
00010 #include <strstream>
00011 #include <fstream>
00012 
00013 static std::streambuf* sbout=0;
00014 static std::streambuf* sberr=0;
00015 
00016 // special place to put output
00017 static ofstream* tempfile=0;
00018 
00020 //          private streambuf used by WinGUIostream
00021 class logbuf : public std::streambuf
00022 {
00023 public:
00024     logbuf (HWND owner);
00025     virtual ~logbuf ();
00026 
00027     virtual int overflow (int c);
00028     virtual int underflow ();
00029 
00030 private:
00031     HWND _win;
00032 
00033 };
00035 //         WINGUIostream implementations
00037 //                constructor
00038 WinGUIostream::WinGUIostream(const char* name, HWND owner, HINSTANCE hInstance)
00039 //: ostream(_buf = new logbuf(owner))
00040 : basic_ostream<char>(_buf = new logbuf(owner))
00041 {
00042     AllocConsole();
00043 
00044  // direct cout and cerr to the console window
00045     std::streambuf* sbout = std::cout.rdbuf(); 
00046     std::streambuf* sberr = std::cerr.rdbuf(); 
00047     std::cout.rdbuf(_buf);
00048     std::cerr.rdbuf(_buf);
00049 
00050     const char * stdout_filename;
00051     if( (stdout_filename=::getenv("stdout"))!=0 )
00052         tempfile = new ofstream(stdout_filename);
00053  }
00054 //------------------------------------------------------------------------
00055 WinGUIostream::~WinGUIostream()
00056 {
00057     std::cout.rdbuf(sbout);
00058     std::cerr.rdbuf(sberr);
00059     delete _buf;
00060     
00061     delete tempfile;
00062 }
00063 //------------------------------------------------------------------------
00064 //                           clear
00065 
00066 void WinGUIostream::clear()
00067 {
00068     //TODO: figure out how to clear console
00069    flush();
00070 
00071 }
00073 //            logbuf implementations
00075 
00076 const int LOGBUF_SIZE = 32;
00077 
00078 //#doc          Initializes the log buffer.
00079 logbuf::logbuf (HWND owner): _win(owner)
00080 {
00081         setp (0, 0);
00082         setg (0, 0, 0);
00083 }
00084 
00085 logbuf::~logbuf ()
00086 { }
00087 
00088 int logbuf::underflow () { return traits_type::eof (); }
00089 
00090 int logbuf::overflow (int c)
00091 {
00092     if (c != traits_type::eof ())
00093     {
00094         char string [3];
00095         int length = 1;
00096         string [0] = c;
00097         string [1] = '\0';
00098         string [2] = '\0';
00099         
00100         if (c == '\n') {
00101             string [0] = '\r';
00102             string [1] = '\n';
00103             ++length;
00104         }
00105         unsigned long numwritten;
00106         ::WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), string, length, &numwritten, NULL);
00107 
00108         // write the character(s) to the stdout temporary file
00109         if(tempfile)  (*tempfile) << string[0]; //string;;
00110     }
00111     return 0;
00112 }
00113 
00114 
00115 #endif // NT_MSVCPP

Generated at Wed Nov 21 12:20:55 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000