]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sgstream.hxx
Fix VS2010 lack of fminf
[simgear.git] / simgear / misc / sgstream.hxx
1 /**
2  * \file sgstream.hxx
3  * zlib input file stream wrapper.
4  */
5
6 // Written by Bernie Bright, 1998
7 //
8 // Copyright (C) 1998  Bernie Bright - bbright@c031.aone.net.au
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _SGSTREAM_HXX
28 #define _SGSTREAM_HXX
29
30 #ifndef __cplusplus
31 # error This library requires C++
32 #endif
33
34 #include <simgear/compiler.h>
35
36 #  include <istream>
37 #  include <ostream>
38
39 #include <string>
40
41 #include <simgear/misc/zfstream.hxx>
42
43 /**
44  * An envelope class for gzifstream.
45  */
46 class sg_gzifstream : private gzifstream_base, public std::istream
47 {
48 public:
49     /** Default constructor */
50     sg_gzifstream();
51
52     /**
53      * Constructor that attempt to open a file with and without
54      * ".gz" extension.
55      * @param name name of file
56      * @param io_mode file open mode(s) "or'd" together
57      */
58     sg_gzifstream( const std::string& name,
59                    ios_openmode io_mode = ios_in | ios_binary );
60
61     /**
62      * Constructor that attaches itself to an existing file descriptor.
63      * @param fd file descriptor
64      * @param io_mode file open mode(s) "or'd" together
65      */
66     sg_gzifstream( int fd, ios_openmode io_mode = ios_in|ios_binary );
67
68     /**
69      * Attempt to open a file with and without ".gz" extension.
70      * @param name name of file
71      * @param io_mode file open mode(s) "or'd" together
72      */
73     void open( const std::string& name,
74                ios_openmode io_mode = ios_in|ios_binary );
75
76     /**
77      * Attach to an existing file descriptor.
78      * @param fd file descriptor
79      * @param io_mode file open mode(s) "or'd" together
80      */
81     void attach( int fd, ios_openmode io_mode = ios_in|ios_binary );
82
83     /**
84      * Close the stream.
85      */
86     void close() { gzbuf.close(); }
87
88     /** @return true if the file is successfully opened, false otherwise. */
89     bool is_open() { return gzbuf.is_open(); }
90
91 private:
92     // Not defined!
93     sg_gzifstream( const sg_gzifstream& );    
94     void operator= ( const sg_gzifstream& );    
95 };
96
97 /**
98  * \relates sg_gzifstream
99  * An istream manipulator that skips to end of line.
100  * @param in input stream
101  */
102 std::istream& skipeol( std::istream& in );
103
104 /**
105  * \relates sg_gzifstream
106  * An istream manipulator that skips over white space.
107  * @param in input stream
108  */
109 std::istream& skipws( std::istream& in );
110
111 /**
112  * \relates sg_gzifstream
113  * An istream manipulator that skips comments and white space.
114  * Ignores comments that start with '#'.
115  * @param in input stream
116  */
117 std::istream& skipcomment( std::istream& in );
118
119 /**
120  * An envelope class for gzofstream.
121  */
122 class sg_gzofstream : private gzofstream_base, public std::ostream
123 {
124 public:
125     /** Default constructor */
126     sg_gzofstream();
127
128     /**
129      * Constructor to open a file for writing.
130      * @param name name of file
131      * @param io_mode file open mode(s) "or'd" together
132      */
133     sg_gzofstream( const std::string& name,
134            ios_openmode io_mode = ios_out | ios_binary );
135
136     /**
137      * Constructor that attaches itself to an existing file descriptor.
138      * @param fd file descriptor
139      * @param io_mode file open mode(s) "or'd" together
140      */
141     sg_gzofstream( int fd, ios_openmode io_mode = ios_out|ios_binary );
142
143     /**
144      * Attempt to open a file for writing.
145      * @param name name of file
146      * @param io_mode file open mode(s) "or'd" together
147      */
148     void open( const std::string& name,
149            ios_openmode io_mode = ios_out|ios_binary );
150
151     /**
152      * Attach to an existing file descriptor.
153      * @param fd file descriptor
154      * @param io_mode file open mode(s) "or'd" together
155      */
156     void attach( int fd, ios_openmode io_mode = ios_out|ios_binary );
157
158     /**
159      * Close the stream.
160      */
161     void close() { gzbuf.close(); }
162
163     /** @return true if the file is successfully opened, false otherwise. */
164     bool is_open() { return gzbuf.is_open(); }
165
166 private:
167     // Not defined!
168     sg_gzofstream( const sg_gzofstream& );
169     void operator= ( const sg_gzofstream& );
170 };
171
172 #endif /* _SGSTREAM_HXX */
173