]> git.mxchange.org Git - simgear.git/blobdiff - simgear/debug/logstream.hxx
Harald JOHNSEN:
[simgear.git] / simgear / debug / logstream.hxx
index ea35ee956c66d935ba575a23c8feab1feb35f060..4546a5e1d5cd6efbaa774eb475101a05584853af 100644 (file)
@@ -28,9 +28,8 @@
 
 #include <simgear/compiler.h>
 
-// At least Irix needs this
-#ifdef SG_HAVE_NATIVE_SGI_COMPILERS
-#include <char_traits.h>
+#ifdef _MSC_VER
+#  include <windows.h>
 #endif
 
 #ifdef SG_HAVE_STD_INCLUDES
 
 #include <simgear/debug/debug_types.h>
 
-#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
 SG_USING_STD(streambuf);
 SG_USING_STD(ostream);
+SG_USING_STD(cout);
 SG_USING_STD(cerr);
 SG_USING_STD(endl);
-#else
-SG_USING_STD(char_traits);
-#endif
 
 #ifdef __MWERKS__
 SG_USING_STD(iostream);
@@ -69,7 +65,11 @@ SG_USING_STD(iostream);
  * messages at runtime. Only messages with priority >= logbuf::logPriority
  * and debugClass == logbuf::logClass are output.
  */
+#ifdef SG_NEED_STREAMBUF_HACK
+class logbuf : public __streambuf
+#else
 class logbuf : public streambuf
+#endif
 {
 public:
 
@@ -184,7 +184,23 @@ logbuf::set_log_state( sgDebugClass c, sgDebugPriority p )
 inline logbuf::int_type
 logbuf::overflow( int c )
 {
+#ifdef _MSC_VER
+    static has_console = false;
+    if ( logging_enabled ) {
+        if ( !has_console ) {
+            AllocConsole();
+            freopen("conin$", "r", stdin);
+            freopen("conout$", "w", stdout);
+            freopen("conout$", "w", stderr);
+            has_console = true;
+        }
+        sbuf->sputc(c);
+    }
+    else
+        return EOF == 0 ? 1: 0;
+#else
     return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0);
+#endif
 }
 
 /**