]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sgstream.cxx
cppbind: automatic conversion of SGReferenced derived pointers.
[simgear.git] / simgear / misc / sgstream.cxx
index 484dce73277d6fc34bf1425315f1ab976b186e04..c2ed93b5869e8bfe43708d9f0f07409220062f11 100644 (file)
 // $Id$
 
 #include <simgear/compiler.h>
-#include STL_STRING 
-
+#include <string>
 #include <ctype.h> // isspace()
-
-#ifdef SG_HAVE_STD_INCLUDES
-# include <cerrno>
-#else
-# include <errno.h>
-#endif
+#include <cerrno>
 
 #include "sgstream.hxx"
 
 using std::string;
 using std::istream;
+using std::ostream;
 
 sg_gzifstream::sg_gzifstream()
     : istream(&gzbuf)
@@ -107,35 +102,26 @@ istream&
 skipeol( istream& in )
 {
     char c = '\0';
-    // skip to end of line.
 
-#ifdef __MWERKS__
-    while ( in.get(c) && c != '\0' ) {
-#else
+    // make sure we detect LF, CR and CR/LF
     while ( in.get(c) ) {
-#endif
-       if ( (c == '\n') || (c == '\r') ) {
-           break;
-       }       
+        if (c == '\n')
+            break;
+        else if (c == '\r') {
+            if (in.peek() == '\n')
+                in.get(c);
+            break;
+        }
     }
-
     return in;
 }
 
 istream&
 skipws( istream& in ) {
     char c;
-#ifdef __MWERKS__
-    while ( in.get(c) && c != '\0' ) {
-#else
     while ( in.get(c) ) {
-#endif
 
-#ifdef __MWERKS__
-       if ( ! isspace( c ) && c != '\n' ) {
-#else
        if ( ! isspace( c ) ) {
-#endif
            // put pack the non-space character
            in.putback(c);
            break;
@@ -150,11 +136,7 @@ skipcomment( istream& in )
     while ( in )
     {
        // skip whitespace
-#ifdef __MWERKS__
-       in >> ::skipws;
-#else
        in >> skipws;
-#endif
 
        char c;
        if ( in.get( c ) && c != '#' )
@@ -168,3 +150,44 @@ skipcomment( istream& in )
     return in;
 }
 
+
+sg_gzofstream::sg_gzofstream()
+    : ostream(&gzbuf)
+{
+}
+
+//-----------------------------------------------------------------------------
+//
+// Open a file for gzipped writing.
+//
+sg_gzofstream::sg_gzofstream( const string& name, ios_openmode io_mode )
+    : ostream(&gzbuf)
+{
+    this->open( name, io_mode );
+}
+
+//-----------------------------------------------------------------------------
+//
+// Attach a stream to an already opened file descriptor.
+//
+sg_gzofstream::sg_gzofstream( int fd, ios_openmode io_mode )
+    : ostream(&gzbuf)
+{
+    gzbuf.attach( fd, io_mode );
+}
+
+//-----------------------------------------------------------------------------
+//
+// Open a file for gzipped writing.
+//
+void
+sg_gzofstream::open( const string& name, ios_openmode io_mode )
+{
+    gzbuf.open( name.c_str(), io_mode );
+}
+
+void
+sg_gzofstream::attach( int fd, ios_openmode io_mode )
+{
+    gzbuf.attach( fd, io_mode );
+}