]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sgstream.hxx
Fix VS2010 lack of fminf
[simgear.git] / simgear / misc / sgstream.hxx
index 373ebc7914f9eb23a667c90fc0a5319db72910f5..35c644594650d24a620c5e3194b52923b34ee812 100644 (file)
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Library General Public License for more details.
 //
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the
-// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-// Boston, MA  02111-1307, USA.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #ifndef _SGSTREAM_HXX
 #define _SGSTREAM_HXX
 
-#ifndef __cplusplus                                                          
+#ifndef __cplusplus
 # error This library requires C++
-#endif                                   
+#endif
 
 #include <simgear/compiler.h>
 
-#if defined( SG_HAVE_STD_INCLUDES )
 #  include <istream>
-#elif defined ( SG_HAVE_NATIVE_SGI_COMPILERS )
-#  include <CC/stream.h>
-#elif defined ( __BORLANDC__ )
-#  include <iostream>
-#else
-#  include <istream.h>
-#endif
+#  include <ostream>
 
-#include STL_STRING
+#include <string>
 
 #include <simgear/misc/zfstream.hxx>
 
-SG_USING_STD(string);
-
-#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
-SG_USING_STD(istream);
-#endif
-
-
 /**
  * An envelope class for gzifstream.
  */
-class sg_gzifstream : private gzifstream_base, public istream
+class sg_gzifstream : private gzifstream_base, public std::istream
 {
 public:
     /** Default constructor */
@@ -70,7 +55,7 @@ public:
      * @param name name of file
      * @param io_mode file open mode(s) "or'd" together
      */
-    sg_gzifstream( const string& name,
+    sg_gzifstream( const std::string& name,
                   ios_openmode io_mode = ios_in | ios_binary );
 
     /**
@@ -85,7 +70,7 @@ public:
      * @param name name of file
      * @param io_mode file open mode(s) "or'd" together
      */
-    void open( const string& name,
+    void open( const std::string& name,
               ios_openmode io_mode = ios_in|ios_binary );
 
     /**
@@ -114,14 +99,14 @@ private:
  * An istream manipulator that skips to end of line.
  * @param in input stream
  */
-istream& skipeol( istream& in );
+std::istream& skipeol( std::istream& in );
 
 /**
  * \relates sg_gzifstream
  * An istream manipulator that skips over white space.
  * @param in input stream
  */
-istream& skipws( istream& in );
+std::istream& skipws( std::istream& in );
 
 /**
  * \relates sg_gzifstream
@@ -129,8 +114,60 @@ istream& skipws( istream& in );
  * Ignores comments that start with '#'.
  * @param in input stream
  */
-istream& skipcomment( istream& in );
+std::istream& skipcomment( std::istream& in );
+
+/**
+ * An envelope class for gzofstream.
+ */
+class sg_gzofstream : private gzofstream_base, public std::ostream
+{
+public:
+    /** Default constructor */
+    sg_gzofstream();
+
+    /**
+     * Constructor to open a file for writing.
+     * @param name name of file
+     * @param io_mode file open mode(s) "or'd" together
+     */
+    sg_gzofstream( const std::string& name,
+           ios_openmode io_mode = ios_out | ios_binary );
+
+    /**
+     * Constructor that attaches itself to an existing file descriptor.
+     * @param fd file descriptor
+     * @param io_mode file open mode(s) "or'd" together
+     */
+    sg_gzofstream( int fd, ios_openmode io_mode = ios_out|ios_binary );
 
+    /**
+     * Attempt to open a file for writing.
+     * @param name name of file
+     * @param io_mode file open mode(s) "or'd" together
+     */
+    void open( const std::string& name,
+           ios_openmode io_mode = ios_out|ios_binary );
+
+    /**
+     * Attach to an existing file descriptor.
+     * @param fd file descriptor
+     * @param io_mode file open mode(s) "or'd" together
+     */
+    void attach( int fd, ios_openmode io_mode = ios_out|ios_binary );
+
+    /**
+     * Close the stream.
+     */
+    void close() { gzbuf.close(); }
+
+    /** @return true if the file is successfully opened, false otherwise. */
+    bool is_open() { return gzbuf.is_open(); }
+
+private:
+    // Not defined!
+    sg_gzofstream( const sg_gzofstream& );
+    void operator= ( const sg_gzofstream& );
+};
 
 #endif /* _SGSTREAM_HXX */