00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stdafx.h"
00021
00022 #include <iostream>
00023 #include <string>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026
00027 #include "gul_types.h"
00028 #include "gul_std.h"
00029
00030 #ifdef __BORLANDC__
00031 #include "string.cc"
00032 #endif
00033
00034 template
00035 class std::basic_string<char,std::char_traits<char>,gul::poolalloc<char> >;
00036
00037
00038 namespace gul {
00039
00040
00041
00042
00043
00044
00045 static List<streambufrec> OldStreambufs;
00046
00047 GULAPI debug_streambuf::debug_streambuf( FILE *logfile )
00048 {
00049 m_bptr = 0;
00050 m_logfile = logfile;
00051
00052 m_oldsb = new streambufrec;
00053 OldStreambufs.Append(m_oldsb);
00054
00055 m_oldsb->cerr_buf = std::cerr.rdbuf();
00056 m_oldsb->cout_buf = std::cout.rdbuf();
00057 std::cerr.rdbuf( this );
00058 std::cout.rdbuf( this );
00059 if( !initialized )
00060 {
00061 atexit(debug_streambuf::atexit_func);
00062 initialized = true;
00063 }
00064 }
00065
00066 int debug_streambuf::overflow( int c )
00067 {
00068 m_buf[m_bptr++] = c;
00069
00070 if( (c == '\n') || (m_bptr == 1023) )
00071 {
00072 m_buf[m_bptr] = 0;
00073
00074 if( m_logfile )
00075 fprintf(m_logfile,m_buf);
00076 printf(m_buf);
00077 #ifdef _MSC_VER
00078 OutputDebugStringA(m_buf);
00079 #endif
00080 m_bptr = 0;
00081 }
00082 return(c);
00083 }
00084
00085 void debug_streambuf::atexit_func( void )
00086 {
00087 streambufrec *oldsb,*oldsb_next;
00088
00089 oldsb = OldStreambufs.First();
00090 OldStreambufs.ReleaseElems();
00091
00092 while( oldsb )
00093 {
00094 std::cerr.rdbuf( oldsb->cerr_buf );
00095 std::cout.rdbuf( oldsb->cout_buf );
00096 oldsb_next = oldsb->next;
00097 delete oldsb;
00098 oldsb = oldsb_next;
00099 }
00100 }
00101
00102 GULAPI debug_streambuf::~debug_streambuf()
00103 {
00104 if( OldStreambufs.nElems )
00105 {
00106 OldStreambufs.Remove(m_oldsb);
00107 std::cerr.rdbuf( m_oldsb->cerr_buf );
00108 std::cout.rdbuf( m_oldsb->cout_buf );
00109 delete m_oldsb;
00110 }
00111 }
00112
00113 bool debug_streambuf::initialized = false;
00114
00115 }
00116
00117
00118