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