]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sgstream.hxx
aa680d01e60f34d808717289d1035d1ebae4322e
[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 #if defined( SG_HAVE_STD_INCLUDES )
37 #  include <istream>
38 #elif defined ( __BORLANDC__ )
39 #  include <iostream>
40 #else
41 #  include <istream.h>
42 #endif
43
44 #include STL_STRING
45
46 #include <simgear/misc/zfstream.hxx>
47
48 /**
49  * An envelope class for gzifstream.
50  */
51 class sg_gzifstream : private gzifstream_base, public std::istream
52 {
53 public:
54     /** Default constructor */
55     sg_gzifstream();
56
57     /**
58      * Constructor that attempt to open a file with and without
59      * ".gz" extension.
60      * @param name name of file
61      * @param io_mode file open mode(s) "or'd" together
62      */
63     sg_gzifstream( const std::string& name,
64                    ios_openmode io_mode = ios_in | ios_binary );
65
66     /**
67      * Constructor that attaches itself to an existing file descriptor.
68      * @param fd file descriptor
69      * @param io_mode file open mode(s) "or'd" together
70      */
71     sg_gzifstream( int fd, ios_openmode io_mode = ios_in|ios_binary );
72
73     /**
74      * Attempt to open a file with and without ".gz" extension.
75      * @param name name of file
76      * @param io_mode file open mode(s) "or'd" together
77      */
78     void open( const std::string& name,
79                ios_openmode io_mode = ios_in|ios_binary );
80
81     /**
82      * Attach to an existing file descriptor.
83      * @param fd file descriptor
84      * @param io_mode file open mode(s) "or'd" together
85      */
86     void attach( int fd, ios_openmode io_mode = ios_in|ios_binary );
87
88     /**
89      * Close the stream.
90      */
91     void close() { gzbuf.close(); }
92
93     /** @return true if the file is successfully opened, false otherwise. */
94     bool is_open() { return gzbuf.is_open(); }
95
96 private:
97     // Not defined!
98     sg_gzifstream( const sg_gzifstream& );    
99     void operator= ( const sg_gzifstream& );    
100 };
101
102 /**
103  * \relates sg_gzifstream
104  * An istream manipulator that skips to end of line.
105  * @param in input stream
106  */
107 std::istream& skipeol( std::istream& in );
108
109 /**
110  * \relates sg_gzifstream
111  * An istream manipulator that skips over white space.
112  * @param in input stream
113  */
114 std::istream& skipws( std::istream& in );
115
116 /**
117  * \relates sg_gzifstream
118  * An istream manipulator that skips comments and white space.
119  * Ignores comments that start with '#'.
120  * @param in input stream
121  */
122 std::istream& skipcomment( std::istream& in );
123
124
125 #endif /* _SGSTREAM_HXX */
126